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