#!/usr/bin/tclsh set my(sleepTime) 0 puts "my sleepTime = $my(sleepTime) " set my(upTime) 0 set my(sleep) $my(sleepTime) set my(trgData) /trgdata/ set my(trgDataHist) /star/u/starcrew/spin/wrk/hist/ ;#original location set my(TrgL) {JP0 JP1 JP2};# can use any available triggers in here set my(lastDbId) 75605; #start with R14074055 day run 13 500GeV set my(lastFill) -10 ;#Catch any new fill set my(stopDbId) 75655; #stop with R13109054 Day 109 for 500GeV run global dBaseLoc set dBaseLoc "dbbak.starp.bnl.gov" ;#this is the archive location for run 13 and all old runs; port num for run 13 is 3412. #----------------------------------------- proc tickTack {} { global my myRun after 1000 tickTack incr my(upTime) incr my(sleep) puts "auto upTime= $my(upTime) sec, restart in [ expr $my(sleepTime) - $my(sleep) ] " if { $my(sleep) < $my(sleepTime) } return set my(sleep) 0 if { [info exist myRun ] } { unset myRun } doTask [expr $my(lastDbId)+1] # if { $my(lastDbId) > 26310 } { exit } ;# Sunday, May 8 if { $my(lastDbId) == $my(stopDbId) } { exit } return } #---------------------------------------------- proc doTask { recId } { global my myRun global dBaseLoc puts "time to wake up !!!!" puts "help !!!!" puts "This is the new Version!" puts recordId=$recId puts $dBaseLoc catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select dataID from runDescriptor where dataID=$recId " } ret ;#for run 13 puts "--=$ret=-- \n [string first dataID $ret]" if { [string first dataID $ret] <0 } return # puts [split $ret ":"] set newDbId [lindex [split $ret ":"] 1] puts newDbId=$newDbId if { $my(lastDbId)==$newDbId } return set my(lastDbId) $newDbId #....................... Acquire run info ...................... catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where dataID=$my(lastDbId) ORDER By beginTime desc LIMIT 1 " } ret ;#for run 13 puts "runinfo=$ret= " puts "New run has started !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n" set itemL {runNumber beginTime startRunTime endRunTime daqSetupName trgSetupName } unpackDbDump $ret $itemL catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select rtsStatus,shiftLeaderStatus from runStatus where runNumber=$myRun(runNumber)" } ret ;#for current run puts "RunStat =$ret= " # puts [string first Junk $ret] set statList { rtsStatus shiftLeaderStatus } unpackDbDump $ret $statList ;#should put them in myRun puts "run status = $myRun(rtsStatus) shift leader status = $myRun(shiftLeaderStatus)" set shiftStat Successful if { $myRun(rtsStatus) == 2 } { puts "run $myRun(runNumber) is RTS Marked as Junk" set shiftStat Junk return ;#rts marked as junk don't bother } if { $myRun(shiftLeaderStatus) == 2 } {set shiftStat Bad} ; if { $myRun(shiftLeaderStatus) == 1 } {set shiftStat Questionable} ; if { $myRun(shiftLeaderStatus) == 1} { puts "not a first priority run" return ; } if { $myRun(shiftLeaderStatus) == 2} { puts "not a first priority run" return ; } if { $myRun(trgSetupName) != "pp500_production_2013"} { puts "not a first priority run" return ; } set myRun(shiftStat) $shiftStat puts "past Junk shiftStatus = $myRun(shiftStat)" if { [string first physics $myRun(daqSetupName) ] <0 } return # set excludeL { ped puls test bbcSc random fpdTest} ;#add random 7/17/06 should eliminate some runs day 70-71 #set excludeL { ped puls bbcSc random } ;#for run 8 remove test There were a lot at beginning of run #set excludeL { ped puls } ;#for run 10 testing set excludeL { ped puls tune Tune commission test Test Cosmic } ; #for run 10 200GeV foreach x $excludeL { if { [string first $x $myRun(trgSetupName) ] >=0 } return } set myRun(totSec) [expr $myRun(endRunTime)- $myRun(startRunTime)] if { $myRun(totSec) <180 && $myRun(totSec) > 0 && $myRun(trgSetupName) != "emc-check"} { #keep all emcCheck runs and runs of length 0 which probably means begin and end times corrupted puts "Run less than 180 sec. Don't process" return ;# too short run } # get detector information - first list of detectors in run catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select detectorID from detectorSet where runNumber=$myRun(runNumber) ORDER By detectorID " } ret ;#for current run #puts "detinfo =$ret=" set detectors " " set detL [split $ret "\n"] puts "detList =$detL=" foreach x $detL { if { [string first "detectorID" $x] <0 } continue #puts "detList $x " set i [expr [string first ":" $x]+2] set detId [string range $x $i end] #puts "find detId = $detId" #stored above as number - translate from db to give text name catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select name from detectorTypes where detectorID=$detId"} ret ;#for current run #puts "detName =$ret" set i [expr [string first ":" $ret]+2] set detName [string range $ret $i end] lappend detectors $detName } puts "detectors in run = $detectors" set myRun(detectors) $detectors #pick time dependent trigger list puts "myrun=$myRun(runNumber)" #set my(TrgL) $my(TrgL1) ; #start of run #if {$myRun(runNumber) >= 6119000 } {set my(TrgL) $my(TrgL2)} #if {$myRun(runNumber) >= 6119032 } {set my(TrgL) $my(TrgL3)} #if {$myRun(runNumber) >= 6136119 } {set my(TrgL) $my(TrgL4)} #if {$myRun(runNumber) >= 6165003 } {set my(TrgL) $my(TrgTr)} #if {$myRun(runNumber) >= 6167088 } {set my(TrgL) $my(TrgL4)} #puts "myrun=$myRun(runNumber) mytrglist=$my(TrgL)" regsub Production $myRun(trgSetupName) Prod myRun(trgSetupName) #foreach x $my(TrgL) { #getTrigRate $x #} #....................... Acquire beam info ...................... catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from beamInfo where runNumber=$myRun(runNumber) ORDER By beginTime desc LIMIT 1 " } ret ;#for current run puts "beamInfo=$ret= " set itemL { blueEnergy blueFillNumber blueIntensity yellowIntensity blueSpecies} unpackDbDump $ret $itemL set myRun(WMC-BY) [format %.0f [expr $myRun(blueIntensity) * $myRun(yellowIntensity)]] set myRun(fillNumber) [format %.0f $myRun(blueFillNumber)] set myRun(startRunTimeGmt) [ clock format $myRun(startRunTime) -gmt 1 -format "%Y-%m-%d %T"] set myRun(startRunTimeBnl) [ clock format $myRun(startRunTime) -format "%Y-%m-%d %T"] set myRun(endRunTimeGmt) [ clock format $myRun(endRunTime) -gmt 1 -format "%Y-%m-%d %T"] set myRun(endRunTimeBnl) [ clock format $myRun(endRunTime) -format "%Y-%m-%d %T"] catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rich -e " select beginTime,rs3,rs4,rs5 from richScalar where beginTime>'$myRun(startRunTimeGmt)' and beginTime<'$myRun(endRunTimeGmt)'" } ret ;#for run 13 puts "richscal=$ret= " unpackScaler $ret puts "out of scaler routine" #....................... Acquire trigger info ......................added by JS #catch { exec mysql -h db01.star.bnl.gov --port 3316 trigger -s -E -e " select * from triggerRate where run=$myRun(runNumber)"} ret puts "trig=$ret= " #above gets the full trigger record, 28 groups, 1 for each trigger definition #Do it now to get only what I want foreach x $my(TrgL) { getEvents $x } #findDsmHisto; #skip for now addWebRecord addRunlistRecord # exit puts "\n\n-------this run------" foreach y [lsort [array names myRun]] { puts "exit $y=$myRun($y) " } return } #-------------------- #-------------------- #-------------------- proc unpackDbDump { text keyL } { #mysql often returns the "variableName : value". This routine makes each line in the #returned string an indexed string in txtL and then looks in txtL for the line with the #varible names in keyL and extracts their value off the second part of the line after the # : character. global myRun set txtL [split $text "\n"] foreach x $txtL { puts x=$x foreach y $keyL { if { [string first $y $x] <0 } continue puts "y2=$y OK $x " set i [expr [string first ":" $x]+2] set myRun($y) [string range $x $i end] } } } #-------------------- #-------------------- #-------------------- proc unpackScaler { text } { global myRun #puts "in scaler routine" set txtL [split $text "\n"] set nr -1 set s3 0 set s4 0 set s5 0 set bg 0 #puts "scaler routine - do lines" foreach line $txtL { incr nr if { $nr <=0 } continue set count [scan $line "%s %s %f %f %f " d0 d0 x3 x4 x5 ] if {$count != 5} { puts "Error reading Scaler - terminating script,count=$count" exit } set s3 [expr $s3+$x3] set s4 [expr $s4+$x4] set s5 [expr $s5+$x5] } puts "BBC Scaler nr=$nr sr3=[format %.1f $s3] sr4=[format %.1f $s4] sr5=[format %.1f $s5]" set myRun(bbcRate-rs3) -1 set myRun(bbcBckg) -1 set myRun(bbc-rs4) -1 set myRun(bbc-rs5) -1 if { $nr !=0 } { set myRun(bbcRate-rs3) [format %.0f [expr $s3/$nr]] if {$s3 !=0 } { set myRun(bbcBckg) [format %.3f [expr ($s4+$s5)/$s3]]; #some runs have this 0 } set myRun(bbc-rs4) [format %.0f [expr $s4/$nr]]; #didn't find any with nr=0 but check anyway set myRun(bbc-rs5) [format %.0f [expr $s5/$nr]] } # set myRun(bbcBckgInst) [format %.2f [expr $bg/$nr]] ;# instantanous ratio } #-------------------- #-------------------- #-------------------- proc findDsmHisto { } { global myRun my set run $myRun(runNumber) puts "process DSM info for run=$run" catch { exec ls $my(trgDataHist) } ret #puts "trigger data ls =$ret" set retL [split $ret "\n"] foreach x $retL { #puts " x=$x run=$run" if { [string first $run $x] <0 } continue set fName $x set myRun(dsmHist) $x break } if { ![info exist fName] } return puts " file = $fName " catch { exec root -b -q plPanitkin.C\(\"$my(trgDataHist)$myRun(dsmHist)\",1\) | grep "\#JP" } ret #hist files and C program are on onllinux8 use starcrew/balewski plPanitkin and files in /star/u/starcrew/spin/wrk/hist/ puts "root =$ret= " if { [string first "\#JP" $ret] <0 } return set count [scan $ret "%s %f %f %d %d" d0 r er min max ] if {$count != 5} { puts "Error reading Scaler - terminating script,count=$count" exit } puts " r er min max $r $er $min $max " set myRun(EJP-r) $r set myRun(EJP-er) $er set myRun(EJP-min) $min set myRun(EJP-max) $max } #-------------------- #-------------------- #-------------------- proc getTrigRate { oflTrgName } { global myRun my dBaseLoc set run $myRun(runNumber) set trg $oflTrgName #....................... Acquire trigger bits ........... puts "scaler run = $run trg = $trg" catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rts -s -E -e "select idx_rn,name,idx_trigger,offlineBit,l0ps from triggers where name='$trg' and idx_rn=$run " } ret puts "scaler=$ret= " set myRun(idx_trigger) -1 unpackDbDump $ret idx_trigger puts " myRun(idx_trigger)=$myRun(idx_trigger)" if { $myRun(idx_trigger)<0 } { return } set idx_trigger $myRun(idx_trigger) #....................... Acquire ........... catch { exec mysql -h $dBaseLoc --port 3412 Scalers_rts -s -e "select numSeen from scaDaqScaler where idx_rn=$run and id=$idx_trigger " } ret #returns list of scaler partial sums, begin of run should be 0 + any number of incremental reads. Sum to get total using outL below. puts "Scaler=$ret= " set outL [split $ret "\n"] puts "outL=$outL [llength $outL] " set sum 0 foreach x $outL { incr sum $x } puts "sum=$sum" set myRun(sn-$trg) $sum } #-------------------- #-------------------- #-------------------- proc getEvents { oflTrgName } { global myRun my set run $myRun(runNumber) set trg $oflTrgName set evts 0 #....................... Acquire prescale and events ........... catch { exec mysql -h onldb.starp.bnl.gov --port 3412 RunLog -s -E -e " select prescale,numberOfEvents from l0TriggerSet where runNumber=$myRun(runNumber) and name='$trg'"} ret ;#for current run set textL [ split $ret "\n" ] set prescl 0 foreach x $textL { puts "+++++++++ getEvents x= $x" if { [string first prescale $x] < 0 } continue set i [ expr [string first ":" $x]+2 ] set prescl [string range $x $i end] # puts "prescl= $prescl" } set nevts 0 foreach x $textL { # puts "x= $x" if { [string first numberOfEvents $x] < 0} continue set i [expr [string first ":" $x]+2] set nevts [string range $x $i end] # puts "nevts=$nevts" } # puts "got events" #set totevts [expr $nevts*$prescl] ; #save total triggers set totevts $nevts ; #save events puts "trg=$trg nevts=$nevts prescl=$prescl totevts=$totevts" set myRun(ev-$trg) $totevts ; #was myRun(psev-$trg) for prescaled totals } #-------------------- #-------------------- #-------------------- proc addWebRecord { } { global myRun my # set uTime [clock seconds] # set myDate [clock format $uTime ] #set myList { fillNumber runNumber status trgSetupName shiftStat detectors startRunTimeBnl totSec bbcRate-rs3 bbc-rs4 bbc-rs5 bbcBckg EJP-r EJP-er EJP-min EJP-max }; #2005 list set myList { fillNumber runNumber status trgSetupName shiftStat detectors startRunTimeBnl totSec bbcRate-rs3 bbc-rs4 bbc-rs5 bbcBckg } #foreach x $my(TrgL) { #lappend myList sn-$x # } foreach x $my(TrgL) { lappend myList ev-$x ; # was lappend myList psev-$x for prescaled totals } set fd [open "./data/test.csv" "a"] if { $myRun(fillNumber)!=$my(lastFill) } { set my(lastFill) $myRun(fillNumber) puts $fd "F$my(lastFill) ,----, newFill,---------------------------- " foreach x $myList { puts -nonewline $fd " $x," } puts $fd "" };# repeat header set myRun(runNumber) R$myRun(runNumber) set saveFill $myRun(fillNumber) set myRun(fillNumber) F$myRun(fillNumber) set myRun(status) " ?? " foreach x $myList { #puts "$x [ info exist myRun($x) ] " if { [ info exist myRun($x) ] >0 } { puts -nonewline $fd " $myRun($x)," } else { puts -nonewline $fd " ," } } puts $fd " " close $fd set myRun(fillNumber) $saveFill } #-------------------- #-------------------- #-------------------- proc addRunlistRecord { } { global myRun my # set uTime [clock seconds] # set myDate [clock format $uTime ] puts "in run list proc" set myList { runNumber status comment trgSetupName shiftStat detectors } set fd [open "./data/testlist.csv" "a"] puts "fill n $myRun(fillNumber) lastfill $my(lastFill) " if { $myRun(fillNumber)!=$my(lastFill) } { set my(lastFill) $myRun(fillNumber) puts $fd "F$my(lastFill) ,----, newFill,---------------------------- " foreach x $myList { puts -nonewline $fd " $x," } puts $fd "" };# repeat header set myRun(runNumber) $myRun(runNumber) set saveFill $myRun(fillNumber) set myRun(fillNumber) "F$myRun(fillNumber)" set myRun(status) " ?? " set myRun(comment) " " foreach x $myList { puts "testlis word $x [ info exist myRun($x) ] " if { [ info exist myRun($x) ] >0 } { puts -nonewline $fd " $myRun($x)," } else { puts -nonewline $fd " ," } } puts $fd " " close $fd set myRun(fillNumber) $saveFill # puts "fill numbers, $saveFill, $myRun(fillNumber), $my(lastFill)" } #----------------------------- M A I N ----------------- #----------------------------- M A I N ----------------- #----------------------------- M A I N ----------------- set xNever 0 tickTack puts "done" vwait xNever