ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/DatabaseRateMonitor.py
Revision: 1.35
Committed: Tue Apr 17 20:26:04 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-32, V00-00-31
Changes since 1.34: +5 -2 lines
Log Message:
No Version cleaned up

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     except:
235     HeadLumiRange=[]
236     LastGoodLS=-1
237     CurrRun=CompareRunNum
238     isGood=0
239    
240     if len(HeadLumiRange) is 0:
241     print "No lumisections that are taking physics data"
242     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
243     if len(HeadLumiRange)>0:
244     isGood=1
245     isCol=0
246     ##sys.exit(0)
247    
248    
249 amott 1.1 if PrintLumi:
250     for LS in HeadParser.LumiInfo[0]:
251     try:
252     if (LS < FirstLS or LS > LastLS) and not FirstLS==999999:
253     continue
254     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))
255     except:
256     print "Lumisection "+str(LS-1)+" was not parsed from the LumiSections page"
257    
258 grchrist 1.23 sys.exit(0)
259 amott 1.1
260     if RefRunNum == 0:
261     RefRates = 0
262     RefLumis = 0
263     LastSuccessfulIterator = 0
264    
265     ### Now actually compare the rates, make tables and look at L1. Loops for ShifterMode
266     #CheckTriggerList(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config)
267 grchrist 1.23
268     ###isGood=1##if there is a trigger key
269 amott 1.1 try:
270     while True:
271 grchrist 1.23
272     if isGood:
273     LastGoodLS=HeadParser.GetLastLS(isCol)
274     if not isCol:
275     ##clear()
276     MoreTableInfo(HeadParser,HeadLumiRange,Config,False)
277     else:
278 grchrist 1.25 if (len(HeadLumiRange)>0):
279 amott 1.33 RunComparison(HeadParser,RefParser,HeadLumiRange,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config,ListIgnoredPaths,SortBy)
280 grchrist 1.25 if FindL1Zeros:
281     CheckL1Zeros(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config)
282     else:
283 grchrist 1.26 print "No lumisections that are taking physics data"
284 amott 1.33 if ShifterMode:
285 grchrist 1.23 #print "Shifter Mode. Continuing"
286     pass
287 amott 1.2 else:
288 grchrist 1.23 print "Expert Mode. Quitting."
289     sys.exit(0)
290 amott 1.2
291 amott 1.1
292     print "Sleeping for 1 minute before repeating "
293 amott 1.16 for iSleep in range(20):
294 amott 1.15 write(".")
295     sys.stdout.flush()
296 amott 1.16 time.sleep(3)
297 grchrist 1.23 write(" Updating\n")
298 amott 1.15 sys.stdout.flush()
299 grchrist 1.23
300     ##print "\nminLS=",min(HeadLumiRange),"Last LS=",HeadParser.GetLastLS(isCol),"run=",HeadParser.RunNumber
301     ###Get a new run if DAQ stops
302     ##print "\nLastGoodLS=",LastGoodLS
303    
304     ##### NEED PLACEHOLDER TO COMPARE CURRENT RUN TO LATEST RUN #####
305    
306     NewRun,isCol,isGood = GetLatestRunNumber(9999999) ## update to the latest run and lumi range
307    
308     try:
309     maxLumi=max(HeadLumiRange)
310     except:
311     maxLumi=0
312    
313     ##### THESE ARE CONDITIONS TO GET NEW RUN #####
314     if maxLumi>(LastGoodLS+1) or not isGood or NewRun!=CurrRun:
315     print "Trying to get new Run"
316     try:
317     HeadParser = DatabaseParser()
318     HeadParser.RunNumber = NewRun
319     HeadParser.ParseRunSetup()
320     CurrRun,isCol,isGood=GetLatestRunNumber(9999999)
321     FirstLS=9999
322     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,isCol)
323     if len(HeadLumiRange) is 0:
324     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
325 grchrist 1.26 print "No lumisections that are taking physics data"
326 grchrist 1.23 if len(HeadLumiRange)>0:
327     isGood=1
328     isCol=0
329    
330 grchrist 1.26
331 grchrist 1.23 LastGoodLS=HeadParser.GetLastLS(isCol)
332 grchrist 1.25 ##print CurrRun, isCol, isGood
333 grchrist 1.23 except:
334     isGood=0
335     isCol=0
336     print "failed"
337    
338    
339    
340    
341     ##CurrRun,isCol,isGood = GetLatestRunNumber(CurrRun) ## update to the latest run and lumi range
342     else:
343     try:
344     HeadParser.ParseRunSetup()
345     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,isCol)
346     if len(HeadLumiRange) is 0:
347     HeadLumiRange = HeadParser.GetLSRange(FirstLS,NumLS,False)
348 grchrist 1.26 print "No lumisections that are taking physics data"
349 grchrist 1.23 if len(HeadLumiRange)>0:
350     isGood=1
351     isCol=0
352     LastGoodLS=HeadParser.GetLastLS(isCol)
353    
354     except:
355     isGood=0
356     isCol=0
357     clear()
358     print "NO TRIGGER KEY FOUND YET for run", NewRun ,"repeating search"
359    
360    
361     ## try:
362     ## HeadParser.GetLumiInfo()
363     ## if len(HeadParser.Active)>0:
364     ## isGood=1
365     ## ##print "setting to good"
366     ## except:
367     ## pass
368 grchrist 1.22
369 grchrist 1.23
370 amott 1.1 #end while True
371     #end try
372     except KeyboardInterrupt:
373     print "Quitting. Peace Out."
374    
375    
376 amott 1.33 def RunComparison(HeadParser,RefParser,HeadLumiRange,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config,ListIgnoredPaths,SortBy):
377 amott 1.1 Header = ["Trigger Name","Actual","Expected","% Inc","Cur PS","Comments"]
378     Data = []
379     Warn = []
380     IgnoredRates=[]
381 grchrist 1.23
382 abrinke1 1.9 [HeadAvInstLumi,HeadAvLiveLumi,HeadAvDeliveredLumi,HeadAvDeadTime,HeadPSCols] = HeadParser.GetAvLumiInfo(HeadLumiRange)
383 abrinke1 1.3 ##[HeadUnprescaledRates, HeadTotalPrescales, HeadL1Prescales, HeadTriggerRates] = HeadParser.UpdateRun(HeadLumiRange)
384     HeadUnprescaledRates = HeadParser.UpdateRun(HeadLumiRange)
385 abrinke1 1.9 [PSColumnByLS,InstLumiByLS,DeliveredLumiByLS,LiveLumiByLS,DeadTimeByLS,PhysicsByLS,ActiveByLS] = HeadParser.LumiInfo
386 grchrist 1.30 deadtimebeamactive=HeadParser.GetDeadTimeBeamActive(HeadLumiRange)
387 grchrist 1.18 try:
388     pkl_file = open(Config.FitFileName, 'rb')
389     FitInput = pickle.load(pkl_file)
390     pkl_file.close()
391 grchrist 1.29 ##print "fit file name=",Config.FitFileName
392 grchrist 1.31
393 grchrist 1.18 except:
394 grchrist 1.27 print "No fit file specified"
395 grchrist 1.20 sys.exit(2)
396    
397 grchrist 1.23 try:
398     refrunfile="RefRuns/%s/Rates_HLT_10LS_JPAP.pkl" % (thisyear)
399     pkl_file = open(refrunfile, 'rb')
400     RefRatesInput = pickle.load(pkl_file)
401     pkl_file.close()
402     except:
403 grchrist 1.24 RefRatesInput={}
404 grchrist 1.34 print "Didn't open ref file"
405 amott 1.1
406 grchrist 1.30
407     trig_list=Config.MonitorList
408    
409     if Config.NoVersion:
410     trig_list=[]
411     FitInputNoV={}
412    
413     for trigger in Config.MonitorList:
414     trig_list.append(StripVersion(trigger))
415     for trigger in FitInput.iterkeys():
416     FitInputNoV[StripVersion(trigger)]=FitInput[trigger]
417     FitInput=FitInputNoV
418 grchrist 1.31
419 grchrist 1.30
420     ##trig_list=Config.MonitorList
421 abrinke1 1.3 for HeadName in HeadUnprescaledRates:
422 grchrist 1.30
423     HeadNameNoV=StripVersion(HeadName)
424 grchrist 1.34
425     if RefParser.RunNumber == 0: ## If not ref run then just use trigger list
426     if Config.NoVersion:
427     if HeadNameNoV not in trig_list and not ListIgnoredPaths:
428     continue
429     if HeadNameNoV not in FitInput.keys() and not ListIgnoredPaths:
430     continue
431     else:
432     if HeadName not in trig_list and not ListIgnoredPaths:
433     continue
434     if HeadName not in FitInput.keys() and not ListIgnoredPaths:
435     continue
436     else:
437     if HeadUnprescaledRates[HeadName][2]<0.5:
438 grchrist 1.30 continue
439 grchrist 1.34
440     ##if HeadUnprescaledRates[HeadName][0]>1.9:
441     ## continue
442    
443 grchrist 1.24
444 grchrist 1.25 ##masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_L2", "HLT_Zero"]
445 grchrist 1.28 masked_triggers = ["AlCa_", "DST_", "HLT_L1", "HLT_Zero"]
446 abrinke1 1.9 masked_trig = False
447     for mask in masked_triggers:
448     if str(mask) in HeadName:
449     masked_trig = True
450     if masked_trig:
451     continue
452    
453 amott 1.1 skipTrig=False
454 abrinke1 1.3 TriggerRate = round(HeadUnprescaledRates[HeadName][2],2)
455 grchrist 1.30
456 amott 1.1 if RefParser.RunNumber == 0: ## Use rate prediction functions
457    
458 grchrist 1.30
459     PSCorrectedExpectedRate = Config.GetExpectedRate(HeadName,FitInput,RefRatesInput,HeadAvLiveLumi,HeadAvDeliveredLumi,deadtimebeamactive)
460    
461 abrinke1 1.9
462 amott 1.33 #if PSCorrectedExpectedRate[0] < 0: ##This means we don't have a prediction for this trigger
463     # continue
464 grchrist 1.32 try:
465     ExpectedRate = round((PSCorrectedExpectedRate[0] / HeadUnprescaledRates[HeadName][1]),2)
466     except:
467     ExpectedRate=0.
468 amott 1.33 #print "No rate for ", HeadName
469 grchrist 1.30
470 amott 1.1 PerDiff=0
471     if ExpectedRate>0:
472     PerDiff = int(round( (TriggerRate-ExpectedRate)/ExpectedRate,2 )*100)
473    
474 amott 1.33 if TriggerRate < IgnoreThreshold and (ExpectedRate < IgnoreThreshold and ExpectedRate!=0):
475 amott 1.1 continue
476    
477     VC = ""
478    
479 abrinke1 1.3 Data.append([HeadName,TriggerRate,ExpectedRate,PerDiff,round(HeadUnprescaledRates[HeadName][1],1),VC])
480 amott 1.1
481     else: ## Use a reference run
482     ## cheap trick to only get triggers in list when in shifter mode
483     #print "shifter mode=",int(Config.ShifterMode)
484 grchrist 1.34
485    
486    
487    
488     ##if not HeadParser.AvgL1Prescales[HeadParser.HLTSeed[HeadName]]==1:
489     ## continue
490 amott 1.1
491     RefInstLumi = 0
492     RefIterator = 0
493    
494     RefStartIndex = ClosestIndex(HeadAvInstLumi,RefParser.GetAvLumiPerRange())
495 grchrist 1.34
496 amott 1.1 RefLen = -10
497 grchrist 1.34
498    
499 abrinke1 1.3 RefUnprescaledRates = RefParser.UpdateRun(RefParser.GetLSRange(RefStartIndex,RefLen))
500 amott 1.1 [RefAvInstLumi,RefAvLiveLumi,RefAvDeliveredLumi,RefAvDeadTime,RefPSCols] = RefParser.GetAvLumiInfo(RefParser.GetLSRange(RefStartIndex,RefLen))
501 grchrist 1.34 deadtimebeamactive=RefParser.GetDeadTimeBeamActive(RefParser.GetLSRange(RefStartIndex,RefLen))
502    
503 amott 1.1 RefRate = -1
504     for k,v in RefUnprescaledRates.iteritems():
505 grchrist 1.19 #if StripVersion(HeadName) == StripVersion(k): # versions may not match
506 grchrist 1.34 if HeadName==k:
507     RefRate = RefUnprescaledRates[k][2]
508    
509     try:
510     ScaledRefRate = round( (RefRate*HeadAvLiveLumi/RefAvLiveLumi*(1-deadtimebeamactive)), 2 )
511    
512     except ZeroDivisionError:
513     ScaledRefRate=0
514    
515    
516    
517     ##print HeadName,"ScaledRefRate=",ScaledRefRate
518 amott 1.1 if ScaledRefRate == 0:
519     PerDiff = 100
520     else:
521     PerDiff = int( round( (TriggerRate - ScaledRefRate)/ScaledRefRate , 2)*100)
522    
523     if TriggerRate < IgnoreThreshold and ScaledRefRate < IgnoreThreshold:
524     continue
525    
526     VC = ""
527 amott 1.15 Data.append([HeadName,TriggerRate,ScaledRefRate,PerDiff,round((HeadUnprescaledRates[HeadName][1]),1),VC])
528 amott 1.1
529 amott 1.33 SortedData = []
530     if SortBy == "":
531     SortedData = Data # don't do any sorting
532 grchrist 1.35 if RefParser.RunNumber>0:
533 grchrist 1.34 SortedData=sorted(Data, key=lambda entry: abs(entry[3]),reverse=True)
534 amott 1.33 elif SortBy == "name":
535     SortedData=sorted(Data, key=lambda entry: entry[0])
536     elif SortBy == "rate":
537     SortedData=sorted(Data, key=lambda entry: entry[1],reverse=True)
538     elif SortBy == "rateDiff":
539     SortedData=sorted(Data, key=lambda entry: abs(entry[3]),reverse=True)
540     else:
541     print "Invalid sorting option %s\n"%SortBy
542     SortedData = Data
543    
544     #check for triggers above the warning threshold
545     Warn=[]
546     for entry in SortedData:
547     if abs(entry[3]) > AllowedRateDiff:
548     Warn.append(True)
549     else:
550     Warn.append(False)
551    
552     PrettyPrintTable(Header,SortedData,[80,10,10,10,10,20],Warn)
553 amott 1.1
554 amott 1.4 MoreTableInfo(HeadParser,HeadLumiRange,Config)
555 amott 1.1
556     def CheckTriggerList(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config):
557     print "checking trigger list"
558    
559     def CheckL1Zeros(HeadParser,RefRunNum,RefRates,RefLumis,LastSuccessfulIterator,ShowPSTriggers,AllowedRateDiff,IgnoreThreshold,Config):
560     L1Zeros=[]
561     IgnoreBits = ["L1_PreCollisions","L1_InterBunch_Bsc","L1_BeamHalo","L1_BeamGas_Hf"]
562     for key in HeadParser.TriggerRates:
563     ## Skip events in the skip list
564     skipTrig=False
565     ##for trig in Config.ExcludeList:
566     ##if not trigN.find(trig) == -1:
567     ##skipTrig=True
568     ##break
569     if skipTrig:
570     continue
571     ## if no events pass the L1, add it to the L1Zeros list if not already there
572     if HeadParser.TriggerRates[key][1]==0 and not HeadParser.TriggerRates[key][4] in L1Zeros:
573     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:
574    
575     L1Zeros.append(HeadParser.TriggerRates[key][4])
576     print "L1Zeros=", L1Zeros
577    
578     if len(L1Zeros) == 0:
579     #print "It looks like no masked L1 bits seed trigger paths"
580     pass
581     else:
582     print "The following seeds are used to seed HLT bits but accept 0 events:"
583     #print "The average lumi of this run is: "+str(round(HeadParser.LumiInfo[6],1))+"e30"
584     for Seed in L1Zeros:
585     print Seed
586    
587     if __name__=='__main__':
588 grchrist 1.20 global thisyear
589 amott 1.1 main()