ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRateMonitor.py
Revision: 1.38
Committed: Mon Jul 2 12:48:31 2012 UTC (12 years, 10 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.37: +0 -2 lines
Log Message:
fixes to printouts and min express

File Contents

# User Rev Content
1 amott 1.1 #!/usr/bin/env python
2    
3 amott 1.15 #from AndrewGetRun import GetRun
4 amott 1.1 from DatabaseParser import *
5     from ReadConfig import RateMonConfig
6     import sys
7     import os
8     import cPickle as pickle
9     import getopt
10     import time
11     from colors import *
12     from TablePrint import *
13     from AddTableInfo_db import MoreTableInfo
14     from math import *
15    
16     WBMPageTemplate = "http://cmswbm/cmsdb/servlet/RunSummary?RUN=%s&DB=cms_omds_lb"
17     WBMRunInfoPage = "https://cmswbm/cmsdb/runSummary/RunSummary_1.html"
18    
19 grchrist 1.34 RefRunNameTemplate = "RefRuns/%s/Run_%s.pk"
20 amott 1.1
21     # define a function that clears the terminal screen
22     def clear():
23     print("\x1B[2J")
24    
25    
26     def usage():
27     print sys.argv[0]+" [Options]"
28     print "This script gets the current HLT trigger rates and compares them to a reference run"
29     print "Options: "
30     print "--AllowedDiff=<diff> Report only if difference in trigger rate is greater than <diff>%"
31     print "--CompareRun=<Run #> Compare run <Run #> to the reference run (Default = Current Run)"
32     print "--FindL1Zeros Look for physics paths with 0 L1 rate"
33     print "--FirstLS=<ls> Specify the first lumisection to consider. This will set LSSlidingWindow to -1"
34     print "--NumberLS=<#> Specify the last lumisection to consider. Make sure LastLS > LSSlidingWindow"
35     print " or set LSSlidingWindow = -1"
36     print "--IgnoreLowRate=<rate> Ignore triggers with an actual and expected rate below <rate>"
37     print "--ListIgnoredPaths Prints the paths that are not compared by this script and their rate in the CompareRun"
38     print "--PrintLumi Prints Instantaneous, Delivered, and Live lumi by LS for the run"
39     print "--RefRun=<Run #> Specifies <Run #> as the reference run to use (Default in defaults.cfg)"
40     print "--ShowPSTriggers Show prescaled triggers in rate comparison"
41 amott 1.33 print "--sortBy=<field> Sort the triggers by field. Valid fields are: name, rate, rateDiff"
42 amott 1.2 print "--force Override the check for collisions run"
43 amott 1.1 print "--help Print this help"
44 grchrist 1.20
45     def pickYear():
46     global thisyear
47 grchrist 1.23 thisyear="2012"
48     ##print "Year set to ",thisyear
49 grchrist 1.20
50 amott 1.1 def main():
51 grchrist 1.21 pickYear()
52 amott 1.1 try:
53     opt, args = getopt.getopt(sys.argv[1:],"",["AllowedDiff=","CompareRun=","FindL1Zeros",\
54     "FirstLS=","NumberLS=","IgnoreLowRate=","ListIgnoredPaths",\
55 amott 1.33 "PrintLumi","RefRun=","ShowPSTriggers","force","sortBy=","help"])
56 amott 1.1 except getopt.GetoptError, err:
57     print str(err)
58     usage()
59     sys.exit(2)
60    
61     Config = RateMonConfig(os.path.abspath(os.path.dirname(sys.argv[0])))
62     for o,a in opt:
63     if o=="--ConfigFile":
64     Config.CFGfile=a
65     Config.ReadCFG()
66 grchrist 1.35
67    
68     if "NoV" in Config.FitFileName:
69     Config.NoVersion=True
70 grchrist 1.30 print "NoVersion=",Config.NoVersion
71 grchrist 1.23
72 amott 1.1 AllowedRateDiff = Config.DefAllowRateDiff
73     CompareRunNum = ""
74     FindL1Zeros = False
75     FirstLS = 9999
76 amott 1.2 NumLS = -10
77 amott 1.1 IgnoreThreshold = Config.DefAllowIgnoreThresh
78     ListIgnoredPaths = False
79     PrintLumi = False
80     RefRunNum = int(Config.ReferenceRun)
81     ShowPSTriggers = True
82 amott 1.2 Force = False
83 amott 1.33 SortBy = ""
84 amott 1.1
85 amott 1.33 ShifterMode = int(Config.ShifterMode) # get this from the config, but can be overridden by other options
86 grchrist 1.23
87     ## if int(Config.ShifterMode):
88     ## print "ShifterMode!!"
89     ## else:
90     ## print "ExpertMode"
91 amott 1.1
92     if Config.LSWindow > 0:
93     NumLS = -1*Config.LSWindow
94    
95     for o,a in opt: # get options passed on the command line
96     if o=="--AllowedDiff":
97 amott 1.33 AllowedRateDiff = float(a)
98 amott 1.1 elif o=="--CompareRun":
99     CompareRunNum=int(a)
100 amott 1.33 ShifterMode = False
101 amott 1.1 elif o=="--FindL1Zeros":
102     FindL1Zeros = True
103     elif o=="--FirstLS":
104     FirstLS = int(a)
105 amott 1.33 ShifterMode = False
106 amott 1.1 elif o=="--NumberLS":
107     NumLS = int(a)
108     elif o=="--IgnoreLowRate":
109     IgnoreThreshold = float(a)
110     elif o=="--ListIgnoredPaths":
111     ListIgnoredPaths=True
112 amott 1.33 ShifterMode = False
113 amott 1.1 elif o=="--PrintLumi":
114     PrintLumi = True
115     elif o=="--RefRun":
116     RefRunNum=int(a)
117     elif o=="--ShowPSTriggers":
118     ShowPSTriggers=True
119 amott 1.33 elif o=="--sortBy":
120     SortBy = a
121 amott 1.2 elif o=="--force":
122     Force = True
123 amott 1.1 elif o=="--help":
124     usage()
125     sys.exit(0)
126     else:
127     print "Invalid Option "+a
128     sys.exit(1)
129    
130 grchrist 1.23
131 amott 1.1 RefLumisExists = False
132     """
133 grchrist 1.34 RefRunFile=RefRunNameTemplate % str(RefRunNum)
134 amott 1.1 if RefRunNum > 0:
135     RefRates = {}
136     for Iterator in range(1,100):
137     if RefLumisExists: ## Quits at the end of a run
138     if max(RefLumis[0]) <= (Iterator+1)*10:
139     break
140    
141     RefRunFile = RefRunNameTemplate % str( RefRunNum*100 + Iterator ) # place to save the reference run info
142     print "RefRunFile=",RefRunFile
143     if not os.path.exists(RefRunFile[:RefRunFile.rfind('/')]): # folder for ref run file must exist
144     print "Reference run folder does not exist, please create" # should probably create programmatically, but for now force user to create
145     print RefRunFile[:RefRunFile.rfind('/')]
146     sys.exit(0)
147    
148     if not os.path.exists(RefRunFile): # if the reference run is not saved, get it from wbm
149     print "Reference Run File for run "+str(RefRunNum)+" iterator "+str(Iterator)+" does not exist"
150     print "Creating ..."
151     try:
152     RefParser = GetRun(RefRunNum, RefRunFile, True, Iterator*10, (Iterator+1)*10)
153     print "parsing"
154     except:
155     print "GetRun failed from LS "+str(Iterator*10)+" to "+str((Iterator+1)*10)
156     continue
157    
158     else: # otherwise load it from the file
159     RefParser = pickle.load( open( RefRunFile ) )
160     print "loading"
161     if not RefLumisExists:
162     RefLumis = RefParser.LumiInfo
163     RefLumisExists = True
164    
165     try:
166     RefRates[Iterator] = RefParser.TriggerRates # get the trigger rates from the reference run
167     LastSuccessfulIterator = Iterator
168     except:
169     print "Failed to get rates from LS "+str(Iterator*10)+" to "+str((Iterator+1)*10)
170 grchrist 1.34
171 amott 1.1 """
172 grchrist 1.34 RefRunFile = RefRunNameTemplate % (thisyear,RefRunNum)
173 amott 1.1 RefParser = DatabaseParser()
174 grchrist 1.23 ##print "Reference Run: "+str(RefRunNum)
175 amott 1.1 if RefRunNum > 0:
176 grchrist 1.34 print "Geting RefRunFile",RefRunFile
177 amott 1.1 if not os.path.exists(RefRunFile[:RefRunFile.rfind('/')]): # folder for ref run file must exist
178     print "Reference run folder does not exist, please create" # should probably create programmatically, but for now force user to create
179     print RefRunFile[:RefRunFile.rfind('/')]
180 grchrist 1.27 sys.exit(0)
181 grchrist 1.34 s
182 amott 1.1 return
183     if not os.path.exists(RefRunFile):
184 grchrist 1.34 print "RefRunFile does not exist"
185 amott 1.1 # create the reference run file
186     try:
187     RefParser.RunNumber = RefRunNum
188     RefParser.ParseRunSetup()
189 grchrist 1.34 print "RefParser is setup"
190 amott 1.1 #RefParser.GetAllTriggerRatesByLS()
191     #RefParser.Save( RefRunFile )
192     except e:
193     print "PROBLEM GETTING REFERNCE RUN"
194     raise
195     else:
196     RefParser = pickle.load( open( RefRunFile ) )
197    
198     # OK, Got the Reference Run
199     # Now get the most recent run
200    
201     SaveRun = False
202     if CompareRunNum=="": # if no run # specified on the CL, get the most recent run
203 grchrist 1.22 CompareRunNum,isCol,isGood = GetLatestRunNumber()
204 grchrist 1.26
205    
206 grchrist 1.22 if not isGood:
207 grchrist 1.23 print "NO TRIGGER KEY FOUND for run ",CompareRunNum
208 grchrist 1.22
209 grchrist 1.23 ##sys.exit(0)
210 amott 1.1
211     if not isCol:
212     print "Most Recent run, "+str(CompareRunNum)+", is NOT collisions"
213 amott 1.16 print "Monitoring only stream A and Express"
214     #if not Force:
215     # sys.exit(0) # maybe we should walk back and try to find a collisions run, but for now just exit
216 grchrist 1.23
217     else:
218     print "Most Recent run is "+str(CompareRunNum)
219 amott 1.16 else:
220 grchrist 1.22 CompareRunNum,isCol,isGood = GetLatestRunNumber(CompareRunNum)
221     if not isGood:
222 grchrist 1.23 print "NO TRIGGER KEY FOUND for run ", CompareRunNum
223     ##sys.exit(0)
224 amott 1.17
225 grchrist 1.23
226 amott 1.17 HeadParser = DatabaseParser()
227     HeadParser.RunNumber = CompareRunNum
228 grchrist 1.23
229     try:
230     HeadParser.ParseRunSetup()
231     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,isCol)
232     LastGoodLS=HeadParser.GetLastLS(isCol)
233     CurrRun=CompareRunNum
234 grchrist 1.36 print "done good"
235 grchrist 1.23 except:
236 grchrist 1.36 print "exception"
237 grchrist 1.23 HeadLumiRange=[]
238     LastGoodLS=-1
239     CurrRun=CompareRunNum
240     isGood=0
241    
242     if len(HeadLumiRange) is 0:
243 grchrist 1.36 print "No lumisections that are taking physics data 0"
244 grchrist 1.23 HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
245     if len(HeadLumiRange)>0:
246     isGood=1
247     isCol=0
248     ##sys.exit(0)
249    
250    
251 amott 1.1 if PrintLumi:
252     for LS in HeadParser.LumiInfo[0]:
253     try:
254     if (LS < FirstLS or LS > LastLS) and not FirstLS==999999:
255     continue
256     print str(LS)+' '+str(round(HeadParser.LumiInfo[2][LS],1))+' '+str(round((HeadParser.LumiInfo[3][LS] - HeadParser.LumiInfo[3][LS-1])*1000/23.3,0))+' '+str(round((HeadParser.LumiInfo[4][LS] - HeadParser.LumiInfo[4][LS-1])*1000/23.3,0))
257     except:
258     print "Lumisection "+str(LS-1)+" was not parsed from the LumiSections page"
259    
260 grchrist 1.23 sys.exit(0)
261 amott 1.1
262     if RefRunNum == 0:
263     RefRates = 0
264     RefLumis = 0
265     LastSuccessfulIterator = 0
266    
267     ### Now actually compare the rates, make tables and look at L1. Loops for ShifterMode
268     #CheckTriggerList(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config)
269 grchrist 1.23
270     ###isGood=1##if there is a trigger key
271 amott 1.1 try:
272     while True:
273 grchrist 1.23
274     if isGood:
275     LastGoodLS=HeadParser.GetLastLS(isCol)
276     if not isCol:
277     ##clear()
278     MoreTableInfo(HeadParser,HeadLumiRange,Config,False)
279     else:
280 grchrist 1.25 if (len(HeadLumiRange)>0):
281 amott 1.33 RunComparison(HeadParser,RefParser,HeadLumiRange,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config,ListIgnoredPaths,SortBy)
282 grchrist 1.25 if FindL1Zeros:
283     CheckL1Zeros(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config)
284     else:
285 grchrist 1.36 print "No lumisections that are taking physics data 1"
286 amott 1.33 if ShifterMode:
287 grchrist 1.23 #print "Shifter Mode. Continuing"
288     pass
289 amott 1.2 else:
290 grchrist 1.23 print "Expert Mode. Quitting."
291     sys.exit(0)
292 amott 1.2
293 amott 1.1
294     print "Sleeping for 1 minute before repeating "
295 amott 1.16 for iSleep in range(20):
296 amott 1.15 write(".")
297     sys.stdout.flush()
298 amott 1.16 time.sleep(3)
299 grchrist 1.23 write(" Updating\n")
300 amott 1.15 sys.stdout.flush()
301 grchrist 1.23
302     ##print "\nminLS=",min(HeadLumiRange),"Last LS=",HeadParser.GetLastLS(isCol),"run=",HeadParser.RunNumber
303     ###Get a new run if DAQ stops
304     ##print "\nLastGoodLS=",LastGoodLS
305    
306     ##### NEED PLACEHOLDER TO COMPARE CURRENT RUN TO LATEST RUN #####
307    
308     NewRun,isCol,isGood = GetLatestRunNumber(9999999) ## update to the latest run and lumi range
309    
310     try:
311     maxLumi=max(HeadLumiRange)
312     except:
313     maxLumi=0
314    
315     ##### THESE ARE CONDITIONS TO GET NEW RUN #####
316     if maxLumi>(LastGoodLS+1) or not isGood or NewRun!=CurrRun:
317     print "Trying to get new Run"
318     try:
319     HeadParser = DatabaseParser()
320     HeadParser.RunNumber = NewRun
321     HeadParser.ParseRunSetup()
322     CurrRun,isCol,isGood=GetLatestRunNumber(9999999)
323     FirstLS=9999
324     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,isCol)
325     if len(HeadLumiRange) is 0:
326     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
327 grchrist 1.36 print "No lumisections that are taking physics data 2"
328 grchrist 1.23 if len(HeadLumiRange)>0:
329     isGood=1
330     isCol=0
331    
332 grchrist 1.26
333 grchrist 1.23 LastGoodLS=HeadParser.GetLastLS(isCol)
334 grchrist 1.25 ##print CurrRun, isCol, isGood
335 grchrist 1.23 except:
336     isGood=0
337     isCol=0
338     print "failed"
339    
340    
341    
342    
343     ##CurrRun,isCol,isGood = GetLatestRunNumber(CurrRun) ## update to the latest run and lumi range
344     else:
345     try:
346     HeadParser.ParseRunSetup()
347     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,isCol)
348     if len(HeadLumiRange) is 0:
349     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
350 grchrist 1.26 print "No lumisections that are taking physics data"
351 grchrist 1.23 if len(HeadLumiRange)>0:
352     isGood=1
353     isCol=0
354     LastGoodLS=HeadParser.GetLastLS(isCol)
355    
356     except:
357     isGood=0
358     isCol=0
359     clear()
360     print "NO TRIGGER KEY FOUND YET for run", NewRun ,"repeating search"
361    
362    
363     ## try:
364     ## HeadParser.GetLumiInfo()
365     ## if len(HeadParser.Active)>0:
366     ## isGood=1
367     ## ##print "setting to good"
368     ## except:
369     ## pass
370 grchrist 1.22
371 grchrist 1.23
372 amott 1.1 #end while True
373     #end try
374     except KeyboardInterrupt:
375     print "Quitting. Peace Out."
376    
377    
378 amott 1.33 def RunComparison(HeadParser,RefParser,HeadLumiRange,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config,ListIgnoredPaths,SortBy):
379 amott 1.1 Header = ["Trigger Name","Actual","Expected","% Inc","Cur PS","Comments"]
380     Data = []
381     Warn = []
382     IgnoredRates=[]
383 grchrist 1.23
384 abrinke1 1.9 [HeadAvInstLumi,HeadAvLiveLumi,HeadAvDeliveredLumi,HeadAvDeadTime,HeadPSCols] = HeadParser.GetAvLumiInfo(HeadLumiRange)
385 abrinke1 1.3 ##[HeadUnprescaledRates, HeadTotalPrescales, HeadL1Prescales, HeadTriggerRates] = HeadParser.UpdateRun(HeadLumiRange)
386     HeadUnprescaledRates = HeadParser.UpdateRun(HeadLumiRange)
387 abrinke1 1.9 [PSColumnByLS,InstLumiByLS,DeliveredLumiByLS,LiveLumiByLS,DeadTimeByLS,PhysicsByLS,ActiveByLS] = HeadParser.LumiInfo
388 grchrist 1.30 deadtimebeamactive=HeadParser.GetDeadTimeBeamActive(HeadLumiRange)
389 grchrist 1.18 try:
390     pkl_file = open(Config.FitFileName, 'rb')
391     FitInput = pickle.load(pkl_file)
392     pkl_file.close()
393 grchrist 1.29 ##print "fit file name=",Config.FitFileName
394 grchrist 1.31
395 grchrist 1.18 except:
396 grchrist 1.27 print "No fit file specified"
397 grchrist 1.20 sys.exit(2)
398    
399 grchrist 1.23 try:
400     refrunfile="RefRuns/%s/Rates_HLT_10LS_JPAP.pkl" % (thisyear)
401     pkl_file = open(refrunfile, 'rb')
402     RefRatesInput = pickle.load(pkl_file)
403     pkl_file.close()
404     except:
405 grchrist 1.24 RefRatesInput={}
406 grchrist 1.34 print "Didn't open ref file"
407 amott 1.1
408 grchrist 1.30
409     trig_list=Config.MonitorList
410    
411     if Config.NoVersion:
412     trig_list=[]
413     FitInputNoV={}
414    
415     for trigger in Config.MonitorList:
416     trig_list.append(StripVersion(trigger))
417     for trigger in FitInput.iterkeys():
418     FitInputNoV[StripVersion(trigger)]=FitInput[trigger]
419     FitInput=FitInputNoV
420 grchrist 1.31
421 grchrist 1.30
422     ##trig_list=Config.MonitorList
423 abrinke1 1.3 for HeadName in HeadUnprescaledRates:
424 grchrist 1.30
425     HeadNameNoV=StripVersion(HeadName)
426 grchrist 1.34
427     if RefParser.RunNumber == 0: ## If not ref run then just use trigger list
428     if Config.NoVersion:
429     if HeadNameNoV not in trig_list and not ListIgnoredPaths:
430     continue
431     if HeadNameNoV not in FitInput.keys() and not ListIgnoredPaths:
432     continue
433     else:
434     if HeadName not in trig_list and not ListIgnoredPaths:
435     continue
436     if HeadName not in FitInput.keys() and not ListIgnoredPaths:
437     continue
438     else:
439     if HeadUnprescaledRates[HeadName][2]<0.5:
440 grchrist 1.30 continue
441 grchrist 1.34
442     ##if HeadUnprescaledRates[HeadName][0]>1.9:
443     ## continue
444    
445 grchrist 1.24
446 grchrist 1.25 ##masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_L2", "HLT_Zero"]
447 grchrist 1.28 masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_Zero"]
448 abrinke1 1.9 masked_trig = False
449     for mask in masked_triggers:
450     if str(mask) in HeadName:
451     masked_trig = True
452     if masked_trig:
453     continue
454    
455 amott 1.1 skipTrig=False
456 abrinke1 1.3 TriggerRate = round(HeadUnprescaledRates[HeadName][2],2)
457 amott 1.1 if RefParser.RunNumber == 0: ## Use rate prediction functions
458    
459 grchrist 1.30
460     PSCorrectedExpectedRate = Config.GetExpectedRate(HeadName,FitInput,RefRatesInput,HeadAvLiveLumi,HeadAvDeliveredLumi,deadtimebeamactive)
461    
462 abrinke1 1.9
463 amott 1.33 #if PSCorrectedExpectedRate[0] < 0: ##This means we don't have a prediction for this trigger
464     # continue
465 grchrist 1.32 try:
466     ExpectedRate = round((PSCorrectedExpectedRate[0] / HeadUnprescaledRates[HeadName][1]),2)
467     except:
468     ExpectedRate=0.
469 amott 1.33 #print "No rate for ", HeadName
470 grchrist 1.30
471 amott 1.1 PerDiff=0
472 grchrist 1.37 VC = ""
473 amott 1.1 if ExpectedRate>0:
474     PerDiff = int(round( (TriggerRate-ExpectedRate)/ExpectedRate,2 )*100)
475 grchrist 1.37 else:
476     PerDiff=-999.
477     if ExpectedRate==0:
478     VC="0 expected rate"
479     else:
480     VC="lt 0 expected rate"
481 amott 1.1
482 amott 1.33 if TriggerRate < IgnoreThreshold and (ExpectedRate < IgnoreThreshold and ExpectedRate!=0):
483 amott 1.1 continue
484    
485 grchrist 1.37
486 amott 1.1
487 abrinke1 1.3 Data.append([HeadName,TriggerRate,ExpectedRate,PerDiff,round(HeadUnprescaledRates[HeadName][1],1),VC])
488 amott 1.1
489     else: ## Use a reference run
490     ## cheap trick to only get triggers in list when in shifter mode
491     #print "shifter mode=",int(Config.ShifterMode)
492 grchrist 1.34
493    
494    
495    
496     ##if not HeadParser.AvgL1Prescales[HeadParser.HLTSeed[HeadName]]==1:
497     ## continue
498 amott 1.1
499     RefInstLumi = 0
500     RefIterator = 0
501    
502     RefStartIndex = ClosestIndex(HeadAvInstLumi,RefParser.GetAvLumiPerRange())
503 grchrist 1.34
504 amott 1.1 RefLen = -10
505 grchrist 1.34
506    
507 abrinke1 1.3 RefUnprescaledRates = RefParser.UpdateRun(RefParser.GetLSRange(RefStartIndex,RefLen))
508 amott 1.1 [RefAvInstLumi,RefAvLiveLumi,RefAvDeliveredLumi,RefAvDeadTime,RefPSCols] = RefParser.GetAvLumiInfo(RefParser.GetLSRange(RefStartIndex,RefLen))
509 grchrist 1.34 deadtimebeamactive=RefParser.GetDeadTimeBeamActive(RefParser.GetLSRange(RefStartIndex,RefLen))
510    
511 amott 1.1 RefRate = -1
512     for k,v in RefUnprescaledRates.iteritems():
513 grchrist 1.19 #if StripVersion(HeadName) == StripVersion(k): # versions may not match
514 grchrist 1.34 if HeadName==k:
515     RefRate = RefUnprescaledRates[k][2]
516    
517     try:
518     ScaledRefRate = round( (RefRate*HeadAvLiveLumi/RefAvLiveLumi*(1-deadtimebeamactive)), 2 )
519    
520     except ZeroDivisionError:
521     ScaledRefRate=0
522    
523    
524    
525     ##print HeadName,"ScaledRefRate=",ScaledRefRate
526 amott 1.1 if ScaledRefRate == 0:
527     PerDiff = 100
528     else:
529     PerDiff = int( round( (TriggerRate - ScaledRefRate)/ScaledRefRate , 2)*100)
530    
531     if TriggerRate < IgnoreThreshold and ScaledRefRate < IgnoreThreshold:
532     continue
533    
534     VC = ""
535 amott 1.15 Data.append([HeadName,TriggerRate,ScaledRefRate,PerDiff,round((HeadUnprescaledRates[HeadName][1]),1),VC])
536 amott 1.1
537 amott 1.33 SortedData = []
538     if SortBy == "":
539     SortedData = Data # don't do any sorting
540 grchrist 1.35 if RefParser.RunNumber>0:
541 grchrist 1.34 SortedData=sorted(Data, key=lambda entry: abs(entry[3]),reverse=True)
542 amott 1.33 elif SortBy == "name":
543     SortedData=sorted(Data, key=lambda entry: entry[0])
544     elif SortBy == "rate":
545     SortedData=sorted(Data, key=lambda entry: entry[1],reverse=True)
546     elif SortBy == "rateDiff":
547     SortedData=sorted(Data, key=lambda entry: abs(entry[3]),reverse=True)
548     else:
549     print "Invalid sorting option %s\n"%SortBy
550     SortedData = Data
551    
552     #check for triggers above the warning threshold
553     Warn=[]
554     for entry in SortedData:
555     if abs(entry[3]) > AllowedRateDiff:
556     Warn.append(True)
557     else:
558     Warn.append(False)
559    
560     PrettyPrintTable(Header,SortedData,[80,10,10,10,10,20],Warn)
561 amott 1.1
562 amott 1.4 MoreTableInfo(HeadParser,HeadLumiRange,Config)
563 amott 1.1
564     def CheckTriggerList(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config):
565     print "checking trigger list"
566    
567     def CheckL1Zeros(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config):
568     L1Zeros=[]
569     IgnoreBits = ["L1_PreCollisions","L1_InterBunch_Bsc","L1_BeamHalo","L1_BeamGas_Hf"]
570     for key in HeadParser.TriggerRates:
571     ## Skip events in the skip list
572     skipTrig=False
573     ##for trig in Config.ExcludeList:
574     ##if not trigN.find(trig) == -1:
575     ##skipTrig=True
576     ##break
577     if skipTrig:
578     continue
579     ## if no events pass the L1, add it to the L1Zeros list if not already there
580     if HeadParser.TriggerRates[key][1]==0 and not HeadParser.TriggerRates[key][4] in L1Zeros:
581     if HeadParser.TriggerRates[key][4].find('L1_BeamHalo')==-1 and HeadParser.TriggerRates[key][4].find('L1_PreCollisions')==-1 and HeadParser.TriggerRates[key][4].find('L1_InterBunch_Bsc')==-1:
582    
583     L1Zeros.append(HeadParser.TriggerRates[key][4])
584     print "L1Zeros=", L1Zeros
585    
586     if len(L1Zeros) == 0:
587     #print "It looks like no masked L1 bits seed trigger paths"
588     pass
589     else:
590     print "The following seeds are used to seed HLT bits but accept 0 events:"
591     #print "The average lumi of this run is: "+str(round(HeadParser.LumiInfo[6],1))+"e30"
592     for Seed in L1Zeros:
593     print Seed
594    
595     if __name__=='__main__':
596 grchrist 1.20 global thisyear
597 amott 1.1 main()