ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonHeavyIon/RateMonitorShifter.py
Revision: 1.3
Committed: Thu Nov 3 18:58:00 2011 UTC (13 years, 5 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +9 -5 lines
Log Message:
New triggers for heavy ion mode and found bug that could not parse HLT names correctly without versions

File Contents

# User Rev Content
1 grchrist 1.1 #!/usr/bin/env python
2    
3     from Page1Parser import Page1Parser
4     from GetRun import GetRun
5     import sys
6     import os
7     import cPickle as pickle
8     import getopt
9     import time
10     from ReadConfig import RateMonConfig
11     from colors import *
12    
13     WBMPageTemplate = "http://cmswbm/cmsdb/servlet/RunSummary?RUN=%s&DB=cms_omds_lb"
14     WBMRunInfoPage = "https://cmswbm/cmsdb/runSummary/RunSummary_1.html"
15    
16     RefRunNameTemplate = "RefRuns/Run_%s.pk"
17    
18     # define a function that clears the terminal screen
19     def clear():
20     print("\x1B[2J")
21    
22     def usage():
23     print sys.argv[0]+" [Options]"
24     print "This script monitors some HLT paths for bizarre rates"
25     print "Options: "
26     print "--CompareRun=<Run #> Compare run <Run #> to the reference run (Default = Current Run)"
27     print "--AllowedDiff=<diff> Report only if difference in trigger rate is greater than <diff>%"
28     print "--ZerosOnly Only report if trigger rate is 0"
29     print "--FindL1Zeros Look for physics paths with 0 L1 rate"
30     print "--ListIgnoredPaths Prints the paths that are not compared by this script and their rate in the CompareRun"
31     print "--ConfigFile=<file> Specify a configuration file (Default = defaults.cfg)"
32     print "--FirstLS=<ls> Specify the first lumisection to consider. This will set LSSlidingWindow to -1"
33     print "--LastLS=<ls> Specify the last lumisection to consider. Make sure LastLS > LSSlidingWindow"
34     print " or set LSSlidingWindow = -1"
35     print "--help Print this help"
36    
37     def main():
38     try:
39     opt, args = getopt.getopt(sys.argv[1:],"",["IgnoreVersion","ZerosOnly","CompareRun=","AllowedDiff=",\
40     "IgnoreLowRate=","FindL1Zeros","ListIgnoredPaths","ConfigFile=",\
41     "FirstLS=","LastLS=","help"])
42     except getopt.GetoptError, err:
43     print str(err)
44     usage()
45     sys.exit(2)
46    
47     Config = RateMonConfig(os.path.abspath(os.path.dirname(sys.argv[0])))
48     for o,a in opt:
49     if o=="--ConfigFile":
50     Config.CFGfile=a
51     Config.ReadCFG()
52    
53     IgnoreVersion = False
54     ZerosOnly = False
55     ListIgnoredPaths = False
56     AllowedRateDiff = Config.DefAllowRateDiff
57     IgnoreThreshold = Config.DefAllowIgnoreThresh
58     CompareRunNum = ""
59     FindL1Zeros = Config.FindL1Zeros
60     FirstLS = 999999
61     EndEndLS = 111111
62     LastLS = FirstLS+10
63     RefRunNum = int(Config.ReferenceRun)
64     NWarnPSZero = 1
65 grchrist 1.2
66    
67    
68 grchrist 1.1
69     if Config.LSWindow > 0:
70     FirstLS = -1*Config.LSWindow
71    
72    
73    
74     for o,a in opt: # get options passed on the command line
75     if o=="--IgnoreVersion":
76     IgnoreVersion=True
77     elif o=="--ZerosOnly":
78     ZerosOnly=True
79     elif o=="--CompareRun":
80     CompareRunNum=a
81     elif o=="--AllowedDiff":
82     AllowedRateDiff = float(a)
83     elif o=="--IgnoreLowRate":
84     IgnoreThreshold = float(a)
85     elif o=="--FindL1Zeros":
86     FindL1Zeros=True
87     elif o=="--ListIgnoredPaths":
88     ListIgnoredPaths=True
89     elif o=="--FirstLS":
90     FirstLS = int(a)
91     elif o=="--LastLS":
92     EndEndLS = int(a)
93     elif o=="--ConfigFile":
94     print "Using your custom config file ... %s" % (a)
95     elif o=="--help":
96     usage()
97     sys.exit(0)
98     else:
99     print "Invalid Option "+a
100     sys.exit(1)
101     # end else
102     #end for
103    
104     try:
105     NPSZeros = 0
106     while True:
107     ### Get the most recent run
108     SaveRun=False
109     if CompareRunNum=="": # if no run # specified on the CL, get the most recent run
110     RunListParser = Page1Parser()
111    
112     RunListParser._Parse(WBMRunInfoPage) # this is the page that lists all the runs in the last 24 hours with at least 1 trigger
113     RunListPage = RunListParser.ParsePage1()
114    
115     if RunListPage == '': # this will be '' if the mode of the most recent run is not l1_hlt_collisions/v*
116     print "WBM info page is "+WBMRunInfoPage
117     print "Most Recent run"+" is NOT collisions"
118     sys.exit(0) # maybe we should walk back and try to find a collisions run, but for now just exit
119     CompareRunNum = RunListParser.RunNumber
120     print "Most Recent run is "+CompareRunNum
121     else:
122     SaveRun=False
123     HeadRunFile = RefRunNameTemplate % CompareRunNum
124     RefRunFile = RefRunNameTemplate % str(RefRunNum)
125 grchrist 1.2 print RefRunFile
126 grchrist 1.1
127    
128     if not os.path.exists(RefRunFile[:RefRunFile.rfind('/')]): # folder for ref run file must exist
129     print "Reference run folder does not exist, please create" # should probably create programmatically, but for now force user to create
130     print RefRunFile[:RefRunFile.rfind('/')]
131     sys.exit(0)
132    
133 grchrist 1.2
134    
135     ###if not os.path.exists(RefRunFile) and RefRunNum != 0: # if the reference run is not saved, get it from wbm
136     print "Updated reference run file"
137     RefParser = GetRun(RefRunNum, RefRunFile, True)
138     #else: # otherwise load it from the file
139     # if RefRunNum != 0:
140     # RefParser = pickle.load( open( RefRunFile ) )
141     # print "going to ref run file"
142 grchrist 1.1
143     if os.path.exists(HeadRunFile): # check if a run file for the run we want to compare already exists, it probably won't but just in case we don't have to interrogate WBM
144    
145     HeadParser = pickle.load( open( HeadRunFile ) )
146     else:
147 grchrist 1.3 print "loading for HeadParser WBM"
148 grchrist 1.1 HeadParser = GetRun(CompareRunNum,HeadRunFile,SaveRun,FirstLS,EndEndLS)
149    
150     if HeadParser.FirstLS==-1:
151     print bcolors.OKBLUE+">> Stable Beams NOT yet declared, be patient..."+bcolors.ENDC
152     sys.exit(0)
153    
154     HeadRates = HeadParser.TriggerRates
155    
156     write=sys.stdout.write
157    
158     write('#'*50+'\n')
159     write('Please include all info below in any elog posts\nPost to elog HLT on call\nIt may be helpful to experts\n')
160     write('#'*50+'\n')
161    
162     write('Script called with following command line:\n\n')
163    
164     for thing in sys.argv:
165     write (thing)
166     write ("\n")
167    
168     write('\nUsing the following parameters:\n')
169     write('IgnoreVersion = %s\n' % (IgnoreVersion) )
170     write('ZerosOnly = %s\n' % (ZerosOnly) )
171     write('CompareRun = %s\n' % (CompareRunNum) )
172     write('AllowedDiff = %s\n' % (AllowedRateDiff) )
173     write('IgnoreLowRate = %s\n' % (IgnoreThreshold) )
174     write('FindL1Zeros = %s\n' % (FindL1Zeros) )
175     write('ListIgnoredPaths = %s\n' %(ListIgnoredPaths))
176     write('FirstLS = %s\n' % (FirstLS))
177     write('LastLS = %s\n' % (EndEndLS))
178     write('ConfigFile = %s\n\n' % (Config.CFGfile))
179     ##write('RefRunFile = %s\n' % (RefRunFile))
180    
181    
182     nameBufLen=60
183     RateBuffLen=10
184     write('*'*(nameBufLen+3*RateBuffLen+10))
185     write ('\nCalculation using FirstLS = %s to LastLS = %s of run %s \n' % (HeadParser.FirstLS, HeadParser.LastLS, CompareRunNum))
186    
187     write("The average delivered lumi of these lumi sections is: ")
188     write(str(round(HeadParser.AvDeliveredLumi,1))+"e30"+"\n")
189     write("The average live (recorded) lumi of these lumi sections is: ")
190     if HeadParser.AvLiveLumi==0:
191     write(bcolors.FAIL)
192     elif HeadParser.AvLiveLumi<100:
193     write(bcolors.WARNING)
194    
195     write(str(round(HeadParser.AvLiveLumi,1))+"e30")
196     write(bcolors.ENDC+"\n")
197     write("The average deadtime of these lumi sections is: ")
198     if HeadParser.AvDeadtime > 5:
199     write(bcolors.FAIL)
200     elif HeadParser.AvDeadtime > 10:
201     write(bcolors.WARNING)
202     else:
203     write(bcolors.OKBLUE)
204     write(str(round(HeadParser.AvDeadtime,1))+"%")
205     write(bcolors.ENDC+"\n")
206    
207     print "Using prescale column "+str(HeadParser.PrescaleColumnString)
208    
209     if HeadParser.PrescaleColumnString=="0":
210     if NPSZeros >= NWarnPSZero:
211     write(bcolors.FAIL)
212     write("WARNING: You are using prescale column 0 in Lumi Section %s! This is the emergency column and should only be used if there is no other way to take data\n" % (HeadParser.LastLS) )
213     write("If this is a mistake FIX IT NOW \nif not, the TFM and HLT DOC must be informed\n\n")
214     write(bcolors.ENDC)
215     raw_input("Press ENTER to continue...")
216     write("\n\n")
217     else:
218     NPSZeros+=1
219     else:
220     NPSZeros=0
221    
222     IgnoredRates=[]
223     LargeRateDifference=False
224 grchrist 1.2 if not Config.CompareReference:
225     write('Using quadratic fit comparisions\n')
226     write('*'*(nameBufLen+3*RateBuffLen+10)+'\n')
227     write('* Trigger Name'+' '*(nameBufLen-17)+'* HLT PS * Actual * Expected * % Diff *\n')
228     write('*'*(nameBufLen+3*RateBuffLen+10)+'\n')
229    
230    
231 grchrist 1.3
232 grchrist 1.2 for headTrigN,headTrigRate,headTrigPS,headL1 in HeadRates:
233 grchrist 1.3 ##headTrigNNoVersion = headTrigN[:headTrigN.rfind('_')]
234     headTrigNNoVersion=headTrigN
235 grchrist 1.2 if not Config.AnalyzeTrigger(headTrigNNoVersion): ## SKIP triggers in the skip list
236     continue
237     ExpectedRate = Config.GetExpectedRate(headTrigNNoVersion,HeadParser.AvLiveLumi)
238     ExpectedRate = round((ExpectedRate / headTrigPS),2)
239     Prescale = round(headTrigPS,1)
240     PerDiff=0
241     if ExpectedRate>0:
242     PerDiff = int(round( (headTrigRate-ExpectedRate)/ExpectedRate,2 )*100)
243 grchrist 1.1 ##Write Line ##
244 grchrist 1.2 if headTrigRate==0:
245     write(bcolors.FAIL)
246     elif abs(PerDiff) > AllowedRateDiff:
247     write(bcolors.FAIL)
248     else:
249     write(bcolors.OKGREEN)
250     write('* '+headTrigN+' '*(nameBufLen-len(headTrigN)-5)+'*')
251     write(' '*(RateBuffLen-4-len(str(Prescale))-1)+str(Prescale)+' *')
252     write(' '*(RateBuffLen-len(str(headTrigRate))-1)+str(headTrigRate)+' *')
253     write(' '*(RateBuffLen-len(str(ExpectedRate))-1)+str(ExpectedRate)+' *')
254     if ExpectedRate>0:
255     if abs(PerDiff) > AllowedRateDiff/2:
256 grchrist 1.1 ###write(' '+' '*(RateBuffLen-len(str(PerDiff))-2)+str(PerDiff)+'%')
257 grchrist 1.2 write(' '+' '*(RateBuffLen-len(str(PerDiff))-4)+str(PerDiff)+'%')
258     else:
259     ###write(' good ')
260     write(' good'+' '*(RateBuffLen-len(str(PerDiff))-6)+str(PerDiff)+'%')
261 grchrist 1.1 else:
262 grchrist 1.2 write(' ')
263     write(' *')
264     if headTrigRate==0:
265     write(" << TRIGGER RATE IS ZERO! INFORM SHIFT LEADER & CALL HLT DOC")
266     elif abs(PerDiff) > AllowedRateDiff:
267     write(" << LARGE RATE DIFFERENCE: POST IN HLT on call ELOG")
268     LargeRateDifference=True # this means we automatically check the reference run
269     write(bcolors.ENDC+'\n')
270 grchrist 1.1
271     CallDOC=False
272 grchrist 1.2
273     LargeRateDifference=False
274    
275     if Config.CompareReference and RefRunNum != 0:
276 grchrist 1.1 if LargeRateDifference:
277     write(bcolors.WARNING)
278     print """
279     \n\n
280     ********************************************************************
281     A trigger in this run has a substantial difference from expectations.\n
282     Comparing the current run to a reference run
283     ********************************************************************
284     """
285     write(bcolors.ENDC)
286     else:
287 grchrist 1.2 write('Comparing to ref run: '+str(RefRunNum)+'\n')
288    
289    
290     write('*'*(nameBufLen+3*RateBuffLen+9)+'\n')
291     write('* Trigger Name'+' '*(nameBufLen-17)+'* HLT PS * Actual * Expected * % Diff *\n')
292     write('*'*(nameBufLen+3*RateBuffLen+9)+'\n')
293 grchrist 1.1
294     NotFound=[]
295     for headTrigN,headTrigRate,headTrigPS,headL1 in HeadRates:
296 grchrist 1.2
297 grchrist 1.3 ##headTrigNNoVersion = headTrigN[:headTrigN.rfind('_')]
298     headTrigNNoVersion = headTrigN###no versions in heavy ions
299 grchrist 1.2
300 grchrist 1.1 if not Config.AnalyzeTrigger(headTrigNNoVersion): ## SKIP triggers in the skip list
301     continue
302     ExpectedRate=-1
303 grchrist 1.2 Prescale = round(headTrigPS,1)
304 grchrist 1.1 for refTrigN,refTrigRate,refTrigPS,refLa in RefParser.TriggerRates:
305     refTrigNNoVersion = refTrigN[:refTrigN.rfind('_')]
306 grchrist 1.2
307 grchrist 1.1 if refTrigNNoVersion == headTrigNNoVersion:
308 grchrist 1.2 ExpectedRate = round(refTrigRate * HeadParser.AvLiveLumi/RefParser.AvLiveLumi/headTrigPS,2)
309 grchrist 1.3
310 grchrist 1.1 break
311     if ExpectedRate==-1:
312     NotFound.append(headTrigNNoVersion)
313     continue
314     PerDiff=0
315     if ExpectedRate>0:
316     PerDiff = int(round( (headTrigRate-ExpectedRate)/ExpectedRate,2 )*100)
317     ##Write Line ##
318     if headTrigRate==0:
319     write(bcolors.FAIL)
320     elif abs(PerDiff) >AllowedRateDiff:
321     write(bcolors.FAIL)
322     else:
323     write(bcolors.OKGREEN)
324     write('* '+headTrigN+' '*(nameBufLen-len(headTrigN)-5)+'*')
325 grchrist 1.2 write(' '*(RateBuffLen-4-len(str(Prescale))-1)+str(Prescale)+' *')
326 grchrist 1.1 write(' '*(RateBuffLen-len(str(headTrigRate))-1)+str(headTrigRate)+' *')
327     write(' '*(RateBuffLen-len(str(ExpectedRate))-1)+str(ExpectedRate)+' *')
328     if ExpectedRate>0:
329     if abs(PerDiff) > AllowedRateDiff/2:
330     write(' '+' '*(RateBuffLen-len(str(PerDiff))-2)+str(PerDiff)+'%')
331     else:
332 grchrist 1.2 write(' good '+' '*(RateBuffLen-len(str(PerDiff))-7)+str(PerDiff)+'%')
333 grchrist 1.1 else:
334     write(' ')
335     write(' *')
336 grchrist 1.3
337 grchrist 1.1 if headTrigRate==0:
338     write(" << TRIGGER RATE IS ZERO! CALL HLT DOC")
339     CallDOC=True
340     elif abs(PerDiff) > AllowedRateDiff:
341     write(" << LARGE RATE DIFFERENCE WITH REFERENCE RUN")
342     CallDOC=True
343     write(bcolors.ENDC+'\n')
344 grchrist 1.3
345 grchrist 1.1 if CallDOC:
346     write(bcolors.FAIL)
347     print "\nSomething looks very wrong in this run"
348     print "If there is no obvious reason for this (subdetector out, etc.): **inform the SHIFT LEADER and call the HLT DOC!**"
349     raw_input("Press Enter to continue ... ")
350     write(bcolors.ENDC)
351    
352     if FindL1Zeros:
353     L1Zeros=[]
354     IgnoreBits = ["L1_PreCollisions","L1_InterBunch_Bsc","L1_BeamHalo","L1_BeamGas_Hf"]
355     for trigN,L1Pass,PSPass,PAccept,SeedName in HeadParser.Nevts:
356     ## Skip events in the skip list
357     trigNNoVersion = trigN[:trigN.rfind('_')]
358     if Config.AnalyzeTrigger(trigNNoVersion):
359     continue
360     ## if no events pass the L1, add it to the L1Zeros list if not already there
361     if SeedName in IgnoreBits:
362     continue
363     if L1Pass==0 and not SeedName in L1Zeros and SeedName.find("BeamGas")==-1 and SeedName.find('L1_SingleMuOpen')==-1 and SeedName.find('L1_BeamHalo')==-1 and SeedName.find('L1_InterBunch_Bsc')==-1 and SeedName.find('L1_PreCollisions')==-1:
364     L1Zeros.append(SeedName)
365     if len(L1Zeros) == 0:
366     pass
367     #print bcolors.OKGREEN+">>> L1 Seeds are fine"+bcolors.ENDC
368     else:
369     print "\n\n\n"
370     print ">>> The following seeds are used to seed HLT bits but accept 0 events:"
371     if len(L1Zeros)<10:
372     print bcolors.WARNING
373     for Seed in L1Zeros:
374     print Seed
375     print bcolors.ENDC
376     else:
377     print bcolors.FAIL
378     print "\n************************"
379     print "**MANY L1 seeds are 0!**"
380     print "** If in doubt **"
381     print "** Call the TFM/HLT! **"
382     print "************************"
383     print bcolors.ENDC
384     print '\n\n'
385     # end if find l1 zeros
386     print "Sleeping for 1 minute before repeating "
387     for iSleep in range(6):
388     for iDot in range(iSleep+1):
389     print ".",
390     print "."
391     time.sleep(10)
392     clear()
393     # End of while True
394     #end of try
395     except KeyboardInterrupt:
396     print "Quitting the program"
397    
398    
399     if __name__=='__main__':
400     main()