#!/usr/bin/tclsh global dBaseLoc set dBaseLoc "dbbak.starp.bnl.gov" ;#works for last and all privious year, do not works for current running year #In this script I will look in Jan's cdev data base to find the spin bits #for blue and yellow for each fill and define the valid time window for #that fill. # ------------------------------------------------------------------------------------------ proc repChar { myString Idx char } { #replace a character at position Idx in myString with char. return new string set stLength [string length $myString ] set subSt1 [string range $myString 0 [expr $Idx-1] ] set subSt2 [string range $myString [expr $Idx+1] [expr $stLength-1] ] set newString "$subSt1$char$subSt2" puts "start string $myString charPos $Idx length $stLength substring1 $subSt1 substring2 $subSt2 new string $newString" return $newString } # ----------------------------------------------------------------------------------------- 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] } } } # ------------------------------------------------------------------------------------ #Jan's jan_source/cdev2spinDbV124.tcl with my mods # # 1) check the first line (type: which tclsh ) # 2) modify MAIN (at the end) and procedures User1 # 3) execute the script (or type wish -f xml2ascii.tcl ) # #------------------------------------------------------ proc itemSort {cstack cdata saved_data cattr saved_attr args} { global eve upvar $saved_data sdata upvar $saved_attr sattr set item [string trim $cstack] regsub -all ":" $item "-" item regsub "cdev-" $item "" item regsub "yellow-" $item "yell-" item set atr [string trim $cattr] set val [string trim $cdata] #ignore entries without atributes if { [ string length $atr] <=0 } { return 0 } set eve($item) $val return 0 } #----------------------------------------- proc decodeFile {inFile} { set id [sxml::init $inFile] if { $id == -1 } { puts "Error: Unable to parse test file= $inFile" ; exit 1 } sxml::register_routine $id "_default_" itemSort puts -nonewline "processing file $inFile ..." # do the job set x [sxml::parse $id] sxml::end $id puts "sorter result=$x" if {$x != 0 } {exit 1} } #----------------------------- M A I N routine of Jan's reader------------------------------------- proc findSpin { begORend currFill } { #reads a file generated from querying Jan's data base and puts spin info to file #I need to modify to retun some other variables to calling routine global dbInfo eve global dbInfomodft eve ;#for modulo 14 global badRecord set badRecord 0 source ./jan_source/sxml.tcl set mySetup(inpName) "outCdev.eve" ;# pick up data from this file #--> Wed Jan 01 00:00:00 EST 2003 stareted from this version set mySetup(day4) 1357315070 #set mySetup(day0) [expr $mySetup(day0)+2*365*24*3600] ;#2005 set mySetup(day4) [expr $mySetup(day4)/24/3600 ] ;#2013 decodeFile $mySetup(inpName) set testFill $eve(yell-ring-fillnumberm) puts "check for filled record testFill=$testFill.." if { [string first "noData" $testFill] >=0 } { set badRecord 1 puts "record unixtime=$eve(unixtime) contains noData try another" return } puts "Your input file='$mySetup(inpName)' conforms with .xml syntax " set timeString [clock format $eve(unixtime) ] puts " DB entry unixTime =$eve(unixtime) --> string: $timeString" set day [format %.2f [expr 4+ (( $eve(unixtime)/24/3600 ) - $mySetup(day4)) ]] puts " or day=$day in starting from January 1 2013" set fill $eve(yell-ring-fillnumberm) set ringL {blue yell} puts "" puts "RHIC fill=$fill day=$day " #below forces file name to match current fill number and marks it if fill in record #does not match current fill set errMark "" if {$currFill != "F$fill" } { set errMark "x" } set mySetup(outName) $begORend/$errMark$currFill.v124 set fd [open "$mySetup(outName)" "w"] puts $fd "#rhic/spinV124" #set rotation patterns for where Ybunch0 crosses Bbunch0 # returned values of pattern rotation = 0 for both beams means 4 and 10 o'clock write 240 0 in this case # returned values of pattern rotation = 60 for both beams means 2 and 8 o'clock wite 120 0 in this case # all others should not have been used also if don't agree then set error of "* *" #see pg 70 my analysis log book set xrot 0 foreach ring $ringL { set rotPat $eve($ring-buckets-patternrotationm) #puts "patterns $ring -$rotPat-" if { $rotPat==0 } continue if { $rotPat==60} {incr xrot; continue } incr xrot 9 } #puts "xrot=$xrot" if {$xrot==0} { set rot "120 0" } elseif {$xrot==2} { set rot "240 0" ;# the other } else { set rot "* *" ;# unknown } #puts $fd $rot ;# rotatorPattern set xrot 0 #In run 11 collision point was at 8 and 2 O'clock. Value of patternrotationm was -60 in begining of run #due to error. Was changed to +60 around day 72 but collision point remained same foreach ring $ringL { set rotPat $eve($ring-buckets-patternrotationm) puts "patterns $ring -$rotPat-" if { $rotPat == -60} {incr xrot; continue } if { $rotPat == 60} {incr xrot; continue } incr xrot 9 } puts "xrot=$xrot" if {$xrot==2} { set rot "0 240" } else { set rot "* *" } puts $fd $rot ;# rotator Pattern set use " " ;#default use file set longTrans "1 1" ;#default long both beams #set longTrans "0 0" ;#manual set to transverse (7/23/08 brian) #if { $fill >= 7718 && $fill <= 7833 } { set longTrans "0 0" } ;# trans period 2006 , Took out for 2008 run (7/23/08 brian) #special cases for 2005, insert similar cases for 2006 following #if { $fill < 6932 } { set longTrans "* *"; set use "N" } ;# - my log pg 68 #if { $fill == 7023 } {set use "x" } ; #no good runs this fill #if { $fill == 7024 } {set use "x" } ; #no good runs this fill #N means invesitigate before use x means never use #not sure before day 104. up to day 109 (fill 6932) there were fills that had both #long and trans setups in rotators. #if { $fill >= 7219 && $fill <= 7224 } { set longTrans "0 0" } ;#400 GeV period all trans #if { $fill >= 7288 && $fill <= 7296 } { set longTrans "0 0" } ;#second trans period #note there are gaps in the above ranges. There are fills with no runs in our lists where it is #not obvious which camp they belong to. I have verified that the fills that have runs that were #produced (my run list) will be correct. Adding new fills requires understanding the boundaries better. set dbInfo(use) $use puts $fd $longTrans set nbx(blue) 0 set nbx(yell) 0 set sPatt(blue) "" set sPatt(yell) "" set spPatt(blue) "xxxxxxxx" set spPatt(yell) "xxxxxxxx" set spPattmodft(blue) "xxxxxxxxxxxxxx" ;#for modulo 14 set spPattmodft(yell) "xxxxxxxxxxxxxx" ;#for modulo 14 for { set i 0 } { $i<360 } { incr i} { foreach ring $ringL { set xF $ring-buckets-intendedfillpatterns set xP $ring-buckets-polarizationfillpatterns set dF $eve($xF) set dP $eve($xP) #puts "$ring" set ip [lindex $dP $i ] ;#pol bit for each bucket set fB [lindex $dF $i ] ;#intended fill bit for each bucket set pB 333 if { $fB==0 } { set pB 000 } elseif { $ip==1 } { set pB 001 ;#4 bits for each ring #if {$nbx($ring) < 4} {set sPatt($ring) "$sPatt($ring)+"} } elseif { $ip==0 } { set pB 100 ;# first 3 give spin } elseif { $ip==-1 } { set pB 010 #if {$nbx($ring) < 4} {set sPatt($ring) "$sPatt($ring)-"} } ;#last 1 if filled if { $i < 22 && $i%3==0 } { ;#only do every 3rd bunch # (out of 320) and only 1st 8 if { $ip==1 } { set sPatt($ring) "$sPatt($ring)+" } elseif { $ip==0 } { set sPatt($ring) "$sPatt($ring)e" } elseif { $ip==-1 } { set sPatt($ring) "$sPatt($ring)-" } else {sPatt($ring) "$sPatt($ring)x" } } puts "spnb=$pB$fB tb=[expr $i+1] " puts -nonewline $fd "$pB$fB" incr nbx($ring) $fB ;#count filled bunches #New loop to try to ID pattern from all bunches filled set newSp "" if { $i%3 == 0} { ;#every 3rd bucket is real bunch set pattIdx [expr [expr $i/3]%8 ] set pattIdxmodft [expr [expr $i/3]%14 ] ;#for modulo 14 puts "bunch=$i pattern index=$pattIdx should count 0->7 repeatedly ring $ring" if { $ip==1 } { set newSp "+" } elseif { $ip==0 } { set newSp "e" } elseif { $ip==-1 } { set newSp "-" } set bunchSp [string index $spPatt($ring) $pattIdx]; #get charcter in pattern if {$bunchSp == "c" } {continue} ; # past checks have found conflicts if {$bunchSp == $newSp} { continue } ;# no new info continue if {$bunchSp == "x" || $bunchSp == "e" } { ;#still unknown fill with newSp set spPatt($ring) [repChar $spPatt($ring) $pattIdx $newSp] continue } #for modulo 14 spin pattern########### set bunchSpmodft [string index $spPattmodft($ring) $pattIdxmodft]; if {$bunchSpmodft == "c" } {continue} ; # past checks have found conflicts if {$bunchSpmodft == $newSp} { continue } ;# no new info continue if {$bunchSpmodft == "x" || $bunchSpmodft == "e" } { ;#still unknown fill with newSp set spPattmodft($ring) [repChar $spPattmodft($ring) $pattIdxmodft $newSp] continue } ########################### if {$newSp == "e" } {continue} set spPatt($ring) [repChar $spPatt($ring) $pattIdx "c"] set spPattmodft($ring) [repChar $spPattmodft($ring) $pattIdxmodft "c"] ;#for modulo 14 puts "spin pattern error stored previously $bunchSp this bunch $newSp bunch index $pattIdx" } } puts $fd " [format %3d [expr $i+1]] " } puts "No. of filled bXings blue=$nbx(blue) yellow=$nbx(yell) blue patt=$sPatt(blue) yell patt=$sPatt(yell)" puts "No. of filled bXings blue=$nbx(blue) yellow=$nbx(yell) blue patt=$spPatt(blue) yell patt=$spPatt(yell)" puts "******** end of a fill pattern***********" set dbInfo(nYbx) $nbx(yell) set dbInfo(nBbx) $nbx(blue) set dbInfo(Bpatt) $spPatt(blue) set dbInfo(Ypatt) $spPatt(yell) set dbInfomodft(Bpatt) $spPattmodft(blue) ;#for modulo 14 set dbInfomodft(Ypatt) $spPattmodft(yell) ;#for modulo 14 set dbInfo(unixtime) $eve(unixtime) set dbInfo(fill) $fill ;#use to cross check all is ok return foreach item [array names eve ] { if { [string first "patternrot" $item ] <0 } { continue } puts "$eve($item) <-- $item " } close $fd } # MAIN Routine --------------------------------------------------------------------------------------------------- global myRun global badRecord set outFile "spinTime.txt" set output [open $outFile "w"] #set some starting values so doesn't crash 1st time through set fillNum "Fill" set fUse "Use" set Run1Num "1st run" set Run2Num "2nd run" set nRuns "runs" set fillStart "Start" set fillStop "Stop" set ScottStart "Scott" set ScottDif "Scott Diff" set startDiff "beg dif" set stopDiff "stopdif" set hum1Time "Time 1st run start " set bBunch "BFill" set yBunch "YFill" set polPat "Pol Patt" set pattName "Patt" set error "Fill err" set startOffset 1200 set endOffset 600 set badRecord 0 set firstTime 1 #set runList [open ./mylist/test.csv "r"] set runList [open ./mylist/FP1.csv "r"] #set runList [open ./mylist/FP4.csv "r"] while { [gets $runList line] >= 1 } { ;#loop over lines in file puts " " puts "line from file = $line" set parseLine [ split $line "," ] set newFill [ lindex $parseLine 2 ] #puts "new fill?$newFill-" if { $newFill == " newFill"} { #completed this fill write out puts "new fill detected ****" if {$nRuns == 1} { ;#need special handling set Run2Num $Run1Num } #####################now extract the information from the RUNS ################################################# if {$firstTime == 0 } { ;#i.e. not the first time but all subsequent #get start time puts "*********************************************run info*************************************************" puts "" puts " ******run details of the 1st run of the fill*****" puts "" puts "run number = $Run1Num " catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where runNumber=$Run1Num " } ret puts "111 ret=$ret -111" set findList { dataID startRunTime endRunTime } unpackDbDump $ret $findList puts "run=$Run1Num ID=$myRun(dataID) start=$myRun(startRunTime) end=$myRun(endRunTime)" set fillStart [expr $myRun(startRunTime)-$startOffset] #puts "run start=$myRun(startRunTime) fill start=$fillStart" #get end time puts "" puts "*******************************************run info ***************************************************" puts "*********** run info of the last run of the fill********" puts "" puts "run number = $Run2Num " catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where runNumber=$Run2Num " } ret puts "ret=$ret-" set findList { dataID startRunTime endRunTime } unpackDbDump $ret $findList puts "run=$Run2Num ID=$myRun(dataID) start=$myRun(startRunTime) end=$myRun(endRunTime)" if {$myRun(endRunTime) != 0 } { set fillStop [expr $myRun(endRunTime)+$endOffset] } else { set fillStop "unknown" #special case for 2005 #if { $fillNum == "F6973" } { #set fillStop "1114581900" ;#special case guessed by hand #puts "fill F6973 end time set by hand" #} } puts "run stop=$myRun(endRunTime) fill stop=$fillStop" #special case for 2013 # if { $fillNum == 17538 } { set fillStart "1369289964" } # if { $fillNum == 17538 } { set fillStop "1369291826" } # if { $fillNum == "F17538" } { continue } #get Scott's start time for cross check - 2005 set ScottFile [open "./scott_fills/fullList.txt" "r"] set notFound 1 set ScottStart "unavail" set ScottDif "unavail." while { [gets $ScottFile sline] >= 1 } { ;#search for fill if { [string first $fillNum $sline] > 0 } { set ScottStart [lindex [split $sline " "] 2 ] set ScottDif [expr $fillStart-$ScottStart] } } ###################################now get SPIN info##################################################### #first at beginning of fill set begFillTime [clock format $fillStart -format "%Y-%m-%d %H:%M:%S" -gmt "true"] puts "" puts "*********************************************spin info**************************************************" puts "" puts "******* spin info at beginning of fill*****" puts "" puts "beg of fill convert=$begFillTime bnl=$hum1Time" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin begin $fillNum #####################check for BAD records. if find one back up to find a good one########################### puts "bad record = $badRecord" if { $badRecord != "0" } { catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataID FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E } ret set findList { dataID } unpackDbDump $ret $findList set dbID $myRun(dataID) set countRecords 0 while { $badRecord != "0"} { puts "\n found a bad record back up dbID=$dbID dbUnixtime=$eve(unixtime)" set dbID [expr $dbID-1 ] puts "backing up to dbID=$dbID" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND dataId=$dbID ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum set fillStop $dbInfo(unixtime) incr countRecords if { $countRecords > 200 } { puts "Can't find a good dB record after 200 steps dbID=$dbID" exit } } } ################define spin PATTERN#################################################################### set bBunch B$dbInfo(nBbx) set yBunch Y$dbInfo(nYbx) set polPat "B$dbInfo(Bpatt) Y$dbInfo(Ypatt)" if { $begFillTime < "2013-03-21 03:27:58" } { set polPat "B$dbInfomodft(Bpatt) Y$dbInfomodft(Ypatt)" } ;#for modulo 14 set fNbeg $dbInfo(fill) set fUnix $dbInfo(unixtime) #correct fill patterns before March 21st*************************** if { $begFillTime < "2013-03-21 03:27:58" } { if { $dbInfo(Bpatt) == "++--++--++--++" } { if { $dbInfomodft(Ypatt) == "++++----++++--" } { set pattName "P1" } elseif { $dbInfomodft(Ypatt) == "----++++----++" } { set pattName "P2" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++--++--++--" } { if { $dbInfomodft(Ypatt) == "++++----++++--" } { set pattName "P3" } elseif { $dbInfomodft(Ypatt) == "----++++----++" } { set pattName "P4" } else { set pattName "Y?" } } elseif { $dbInfomodft(Bpatt) == "++++----++++--" } { if { $dbInfo(Ypatt) == "++--++--++--++" } { set pattName "P5" } elseif { $dbInfo(Ypatt) == "--++--++--++--" } { set pattName "P6" } else { set pattName "Y?" } } elseif { $dbInfomodft(Bpatt) == "----++++----++" } { if { $dbInfo(Ypatt) == "++--++--++--++" } { set pattName "P7" } elseif { $dbInfo(Ypatt) == "--++--++--++--" } { set pattName "P8" } else { set pattName "Y?" } } else { set pattName "B?" } } #**************************************************** # spin patterns has been changed since March 21st.correct fill patterns after 2013:03:21 if { $dbInfo(Bpatt) == "++--++--" } { if { $dbInfo(Ypatt) == "--++++--" } { set pattName "P21" } elseif { $dbInfo(Ypatt) == "++----++" } { set pattName "P22" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++--++" } { if { $dbInfo(Ypatt) == "--++++--" } { set pattName "P23" } elseif { $dbInfo(Ypatt) == "++----++" } { set pattName "P24" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++++--" } { if { $dbInfo(Ypatt) == "++--++--" } { set pattName "P25" } elseif { $dbInfo(Ypatt) == "--++--++" } { set pattName "P26" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "++----++" } { if { $dbInfo(Ypatt) == "++--++--" } { set pattName "P27" } elseif { $dbInfo(Ypatt) == "--++--++" } { set pattName "P28" } else { set pattName "Y?" } } else { set pattName "B?" } #now at end of fill set begFillTime [clock format $fillStop -format "%Y-%m-%d %H:%M:%S" -gmt "true"] #****************************************************** puts "" puts "**********************************************spin info**************************************************" puts "" puts "***** spin info at end of fill******" puts "" puts "end of fill convert=$begFillTime " if { $begFillTime == "2013-05-23 09:00:57" } { continue } ;#special case run13 ############################ exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum ###############check for BAD records. if find one step to later record to find a good one puts "bad record = $badRecord" if { $badRecord != "0" } { catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataID FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E } ret set findList { dataID } unpackDbDump $ret $findList set dbID $myRun(dataID) set countRecords 0 while { $badRecord != "0"} { puts "\n found a bad record try next one dbID=$dbID dbUnixtime=$dbInfo(unixtime)" set dbID [expr $dbID+1 ] puts "advancing to dbID=$dbID" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND dataId=$dbID ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum set fillStop $dbInfo(unixtime) incr countRecords if { $countRecords > 200 } { puts "Can't find a good dB record after 200 steps dbID=$dbID" exit } } } ##################Double checks###########################3 #need to check if fill number agrees. If not search back toward end of run but no further. #if still can't agree have problem NOTE writes multiple v124 files. x indicates bad fill number #It will write a file with xFnum when searching backwards but will write one w/o x when it finds the correct fill number set stLast [string length $fillNum ] set fNum [ string range $fillNum 1 $stLast ] if { $fNum != $dbInfo(fill) } { catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataID FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E } ret set findList { dataID } unpackDbDump $ret $findList set dbID $myRun(dataID) while { $dbInfo(unixtime) > $myRun(endRunTime) } { puts "\n fill $fillNum does not agree at end of fill. back up dbID=$dbID dbUnixtime=$dbInfo(unixtime)" set dbID [expr $dbID-1 ] puts "backing up to dbID=$dbID" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND dataId=$dbID ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum set fillStop $dbInfo(unixtime) ;#will give a 0 for time diff between end of fill and record used to define end of fill if { $fNum == $dbInfo(fill) } {break} ; #backed up enough and we are done if { $badRecord != "0"} { #backup and let it go I think the rest of the code will flag it set dbID [expr $dbID+1 ] ;#should put me back at a good record puts "line 406 backing up to dbID=$dbID" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND dataId=$dbID ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum set fillStop $dbInfo(unixtime) break } } puts "unix times $fillStart $fillStop $fUnix $dbInfo(unixtime)" } #double check fill numbers with begin and end time stamps set fUse " " set startDiff [expr $fUnix-$fillStart] if { $startDiff > 310 } {set error "$error*s"; set fUse "N" } set stopDiff [expr $dbInfo(unixtime)-$fillStop] # if { $fillNum == 17538 } {set stopDiff [ expr $dbInfo(unixtime)-( $fillStop + 4000)] } if { $stopDiff > 310 } {set error "$error*e"; set fUse "N" } puts "desired fill=$fNum dbfill=$fNbeg endfill=$dbInfo(fill)" if { $fNum != $fNbeg } { set error "$error*fb" ; set fUse "N" } if { $fNum != $dbInfo(fill) } { set error "$error*fe" ; set fUse "N" } if { $dbInfo(use) != " " } { set fUse $dbInfo(use) } } ###################end of not first time################################################ #####################OUTPUT########################################################### #puts [ format {%5s %4s %9s %9s %7s %12s %12s %11s %11s %11s %20s %9s %9s %9s %5s %10s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $ScottDif $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] puts [ format {%5s %4s %8s %8s %5s %12s %12s %8s %8s %20s %6s %6s %20s %5s %9s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] #puts $output [ format {%5s %4s %9s %9s %7s %12s %12s %11s %11s %11s %20s %9s %9s %9s %5s %10s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $ScottDif $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] puts $output [ format {%5s %4s %8s %8s %5s %12s %12s %8s %8s %20s %6s %6s %20s %5s %9s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] puts "" puts "end of the fill" puts "*********************************************************************************************************" puts "*********************************************************************************************************" puts "" puts "*******now begin the new fill********" puts "" ###################################now get new fill info ######################################### set error " " set firstTime 0 set fillNum [lindex $parseLine 0 ] set fillNum [ string trim $fillNum " " ] gets $runList run ;#next line should be labels gets $runList run ;#next line should be first run in fill set nRuns "1" puts "first run in fill= $run" set parseRun [ split $run "," ] set runFill [lindex $parseRun 0 ] set runFill [ string trim $runFill " " ] if {$runFill != $fillNum } { puts "fill numbers don't match newFill=$fillNum- runFill=$runFill-" } set run1Num [lindex $parseRun 1 ] set hum1Time [lindex $parseRun 6 ] set strLast [string length $run1Num ] set Run1Num [string range $run1Num 2 $strLast ] puts "1st run in fill $runFill $run1Num $Run1Num $hum1Time" } else { #end if new fill == "new fill" puts "looking for last run ***" set runFill [lindex $parseLine 0 ] set runFill [ string trim $runFill " " ] if {$runFill != $fillNum } { puts "fill numbers don't match newFill=$fillNum- runFill=$runFill-" } set run2Num [lindex $parseLine 1 ] set hum2Time [lindex $parseLine 6 ] set strLast [string length $run2Num ] set Run2Num [string range $run2Num 2 $strLast ] puts "run in fill $runFill $run2Num $Run2Num $hum2Time" incr nRuns } } #################################### end of while loop #################################################### ###############now extract the information from the runs############################ if {$firstTime == 0 } { #get start time puts "" puts "***************************************************run info from 2nd part*************************************************" puts "" puts "******* run details of the 1st run of the fill***********" puts "run number = $Run1Num " catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where runNumber=$Run1Num " } ret puts "ret=$ret-" set findList { dataID startRunTime endRunTime } unpackDbDump $ret $findList puts "run=$Run1Num ID=$myRun(dataID) start=$myRun(startRunTime) end=$myRun(endRunTime)" set fillStart [expr $myRun(startRunTime)-$startOffset] puts "run start=$myRun(startRunTime) fill start=$fillStart" #get end time puts "" puts "***************************************************run info from 2nd part*************************************************" puts "" puts "******* run details of the 1st run of the fill***********" puts "run number = $Run1Num " catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where runNumber=$Run1Num " } ret puts "ret=$ret-" set findList { dataID startRunTime endRunTime } unpackDbDump $ret $findList puts "run=$Run1Num ID=$myRun(dataID) start=$myRun(startRunTime) end=$myRun(endRunTime)" set fillStart [expr $myRun(startRunTime)-$startOffset] puts "run start=$myRun(startRunTime) fill start=$fillStart" #get end time puts "" puts "*****************************************************run info from 2nd part*************************************************" puts "" puts "*****run details of the last run of the fill*******" puts "run number = $Run2Num " catch { exec mysql -h $dBaseLoc --port 3412 RunLog -s -E -e " select * from runDescriptor where runNumber=$Run2Num " } ret puts "ret=$ret-" set findList { dataID startRunTime endRunTime } unpackDbDump $ret $findList puts "run=$Run2Num ID=$myRun(dataID) start=$myRun(startRunTime) end=$myRun(endRunTime)" if {$myRun(endRunTime) != 0 } { set fillStop [expr $myRun(endRunTime)+$endOffset] } else { set fillStop "unknown" } #special case for run 13 # if { $fillNum == 17538 } { set fillStart " 1369289964" } # if { $fillNum == 17538 } { set fillStop "1369291826" } puts "run stop=$myRun(endRunTime) fill stop=$fillStop" #get Scott's start time for cross check set ScottFile [open "./scott_fills/fullList.txt" "r"] set notFound 1 set ScottStart "unavail" set ScottDif "unavail." while { [gets $ScottFile sline] >= 1 } { ;#search for fill if { [string first $fillNum $sline] > 0 } { set ScottStart [lindex [split $sline " "] 2 ] set ScottDif [expr $fillStart-$ScottStart] } } ########################now get SPIN info######################################################3 set begFillTime [clock format $fillStart -format "%Y-%m-%d %H:%M:%S" -gmt "true"] puts "" puts "***************************************************spin info from 2nd part**************************************************" puts "" puts "****** spin info at beginning of the fill*******" puts "" puts "convert=$begFillTime bnl=$hum1Time" exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin begin $fillNum set bBunch B$dbInfo(nBbx) set yBunch Y$dbInfo(nYbx) set polPat "B$dbInfo(Bpatt) Y$dbInfo(Ypatt)" if { $begFillTime < "2013-03-21 03:27:58" } { set polPat "B$dbInfomodft(Bpatt) Y$dbInfomodft(Ypatt)" } ;#for modulo 14 set fNbeg $dbInfo(fill) set fUnix $dbInfo(unixtime) ##########################define spin PATTERNS############################################# #correct fill patterns before March 21st*************************** if { $begFillTime < "2013-03-19 13:15:36" } { if { $dbInfo(Bpatt) == "++--++--++--++" } { if { $dbInfomodft(Ypatt) == "++++----++++--" } { set pattName "P1" } elseif { $dbInfomodft(Ypatt) == "----++++----++" } { set pattName "P2" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++--++--++--" } { if { $dbInfomodft(Ypatt) == "++++----++++--" } { set pattName "P3" } elseif { $dbInfomodft(Ypatt) == "----++++----++" } { set pattName "P4" } else { set pattName "Y?" } } elseif { $dbInfomodft(Bpatt) == "++++----++++--" } { if { $dbInfo(Ypatt) == "++--++--++--++" } { set pattName "P5" } elseif { $dbInfo(Ypatt) == "--++--++--++--" } { set pattName "P6" } else { set pattName "Y?" } } elseif { $dbInfomodft(Bpatt) == "----++++----++" } { if { $dbInfo(Ypatt) == "++--++--++--++" } { set pattName "P7" } elseif { $dbInfo(Ypatt) == "--++--++--++--" } { set pattName "P8" } else { set pattName "Y?" } } else { set pattName "B?" } } #**************************************************** #determine fill pattern name # spin patterns has been changed since March 21st.correct fill patterns after 2013:03:21 puts "fill patterns from 2nd part" puts "" if { $dbInfo(Bpatt) == "++--++--" } { if { $dbInfo(Ypatt) == "--++++--" } { set pattName "P21" } elseif { $dbInfo(Ypatt) == "++----++" } { set pattName "P22" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++--++" } { if { $dbInfo(Ypatt) == "--++++--" } { set pattName "P23" } elseif { $dbInfo(Ypatt) == "++----++" } { set pattName "P24" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "--++++--" } { if { $dbInfo(Ypatt) == "++--++--" } { set pattName "P25" } elseif { $dbInfo(Ypatt) == "--++--++" } { set pattName "P26" } else { set pattName "Y?" } } elseif { $dbInfo(Bpatt) == "++----++" } { if { $dbInfo(Ypatt) == "++--++--" } { set pattName "P27" } elseif { $dbInfo(Ypatt) == "--++--++" } { set pattName "P28" } else { set pattName "Y?" } } else { set pattName "B?" } #######################now at END of fill####################################3 set begFillTime [clock format $fillStop -format "%Y-%m-%d %H:%M:%S" -gmt "true"] puts "" puts "**************************************************spin info from 2nd part**************************************************" puts "" puts "********* spin info at end of the fill*******" puts "" puts "convert=$begFillTime bnl=$hum1Time" # if { $begFillTime == "2013-05-23 09:00:57" } { continue } ;# special case run13 exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum #############################DOUBLE CHECKS################################################################ #need to check if fill number agrees. If not search back toward end of run but no further. #if still can't agree have problem set stLast [string length $fillNum ] set fNum [ string range $fillNum 1 $stLast ] if { $fNum != $dbInfo(fill) } { catch { exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataID FROM kretDbBlobS WHERE nodeID=9 AND beginTime>'$begFillTime' ORDER By beginTime LIMIT 1 " -s -E } ret set findList { dataID } unpackDbDump $ret $findList set dbID $myRun(dataID) while { $dbInfo(unixtime) > $myRun(endRunTime) } { puts "line 545 fill $fillNum does not agree at end of fill. back up dbID=$dbID dbUnixtime=$dbInfo(unixtime)" set dbID [expr $dbID-1 ] exec mysql -h $dBaseLoc --port 3412 Conditions_rhic -e "SELECT dataS FROM kretDbBlobS WHERE nodeID=9 AND dataId=$dbID ORDER By beginTime LIMIT 1 " -s -E > outCdev.eve findSpin end $fillNum set fillStop $dbInfo(unixtime) if { $fNum == $dbInfo(fill) } {break} ; #backed up enough and we are done } puts "unix times $fillStart $fillStop $fUnix $dbInfo(unixtime)" } #double check fill numbers with begin and end time stamps set startDiff [expr $fUnix-$fillStart] if { $startDiff > 310 } {set error "$error*s"; set fUse "N" } set stopDiff [expr $dbInfo(unixtime)-$fillStop ] if { $stopDiff > 310 } {set error "$error*e"; set fUse "N" } set stLast [string length $fillNum ] set fNum [ string range $fillNum 1 $stLast ] puts "desired fill=$fNum dbfill=$fNbeg endfill=$dbInfo(fill)" if { $fNum != $fNbeg } { set error "$error*fb"; set fUse "N" } if { $fNum != $dbInfo(fill) } { set error "$error*fe"; set fUse "N" } if { $dbInfo(use) != " " } { set fUse $dbInfo(use) } } ###############################OUTPUT#################################################### puts "" puts "output from 2nd part" # puts [ format {%5s %4s %9s %9s %7s %12s %12s %11s %11s %11s %20s %9s %9s %9s %5s %10s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $ScottDif $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] puts [ format {%5s %4s %8s %8s %5s %12s %12s %8s %8s %20s %6s %6s %20s %5s %9s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] # puts $output [ format {%5s %4s %9s %9s %7s %12s %12s %11s %11s %11s %20s %9s %9s %9s %5s %10s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $ScottDif $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error] puts $output [ format {%5s %4s %8s %8s %5s %12s %12s %8s %8s %20s %6s %6s %20s %5s %9s} $fillNum $fUse $Run1Num $Run2Num $nRuns $fillStart $fillStop $startDiff $stopDiff $hum1Time $bBunch $yBunch $polPat $pattName $error]