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 |
|
|
def RateMon(InputRun,BeginningLS):
|
19 |
|
|
|
20 |
|
|
Config = RateMonConfig(os.path.abspath(os.path.dirname(sys.argv[0])))
|
21 |
|
|
|
22 |
|
|
Config.ReadCFG()
|
23 |
|
|
|
24 |
|
|
IgnoreVersion = False
|
25 |
|
|
ZerosOnly = False
|
26 |
|
|
ListIgnoredPaths = False
|
27 |
|
|
AllowedRateDiff = Config.DefAllowRateDiff
|
28 |
|
|
IgnoreThreshold = Config.DefAllowIgnoreThresh
|
29 |
|
|
CompareRunNum = InputRun
|
30 |
|
|
FindL1Zeros = Config.FindL1Zeros
|
31 |
|
|
FirstLS = BeginningLS
|
32 |
|
|
EndEndLS = 111111
|
33 |
|
|
LastLS = FirstLS+10
|
34 |
|
|
RefRunNum = int(Config.ReferenceRun)
|
35 |
|
|
|
36 |
|
|
if Config.LSWindow > 0 and FirstLS == 999999:
|
37 |
|
|
FirstLS = -1*Config.LSWindow
|
38 |
|
|
|
39 |
|
|
FirstTime = 0
|
40 |
|
|
try:
|
41 |
|
|
if FirstTime == 0:
|
42 |
|
|
### Get the most recent run
|
43 |
|
|
SaveRun=False
|
44 |
|
|
if CompareRunNum=="": # if no run # specified on the CL, get the most recent run
|
45 |
|
|
RunListParser = Page1Parser()
|
46 |
|
|
|
47 |
|
|
RunListParser._Parse(WBMRunInfoPage) # this is the page that lists all the runs in the last 24 hours with at least 1 trigger
|
48 |
|
|
RunListPage = RunListParser.ParsePage1()
|
49 |
|
|
if RunListPage == '': # this will be '' if the mode of the most recent run is not l1_hlt_collisions/v*
|
50 |
|
|
print "Most Recent run is NOT collisions"
|
51 |
|
|
sys.exit(0) # maybe we should walk back and try to find a collisions run, but for now just exit
|
52 |
|
|
CompareRunNum = RunListParser.RunNumber
|
53 |
|
|
print "Most Recent run is "+CompareRunNum
|
54 |
|
|
else:
|
55 |
|
|
SaveRun=False
|
56 |
|
|
HeadRunFile = RefRunNameTemplate % CompareRunNum
|
57 |
|
|
RefRunFile = RefRunNameTemplate % str(RefRunNum)
|
58 |
|
|
|
59 |
|
|
if not os.path.exists(RefRunFile[:RefRunFile.rfind('/')]): # folder for ref run file must exist
|
60 |
|
|
print "Reference run folder does not exist, please create" # should probably create programmatically, but for now force user to create
|
61 |
|
|
print RefRunFile[:RefRunFile.rfind('/')]
|
62 |
|
|
sys.exit(0)
|
63 |
|
|
|
64 |
|
|
if not os.path.exists(RefRunFile) and RefRunNum != 0: # if the reference run is not saved, get it from wbm
|
65 |
|
|
print "Updated reference run file"
|
66 |
|
|
RefParser = GetRun(RefRunNum, RefRunFile, True)
|
67 |
|
|
else: # otherwise load it from the file
|
68 |
|
|
if RefRunNum != 0:
|
69 |
|
|
RefParser = pickle.load( open( RefRunFile ) )
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
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
|
73 |
|
|
HeadParser = pickle.load( open( HeadRunFile ) )
|
74 |
|
|
else:
|
75 |
|
|
HeadParser = GetRun(CompareRunNum,HeadRunFile,SaveRun,FirstLS,EndEndLS)
|
76 |
|
|
|
77 |
|
|
if HeadParser.FirstLS==-1:
|
78 |
|
|
print bcolors.OKBLUE+">> Stable Beams NOT yet declared, be patient..."+bcolors.ENDC
|
79 |
|
|
sys.exit(0)
|
80 |
|
|
|
81 |
|
|
HeadRates = HeadParser.TriggerRates
|
82 |
|
|
|
83 |
|
|
write=sys.stdout.write
|
84 |
|
|
|
85 |
|
|
write ('\nCalculation using FirstLS = %s to LastLS = %s\n' % (HeadParser.FirstLS, HeadParser.LastLS))
|
86 |
|
|
|
87 |
|
|
write("The average lumi of these lumi sections is: ")
|
88 |
|
|
if HeadParser.AvLiveLumi==0:
|
89 |
|
|
write(bcolors.FAIL)
|
90 |
|
|
elif HeadParser.AvLiveLumi<100:
|
91 |
|
|
write(bcolors.WARNING)
|
92 |
|
|
else:
|
93 |
|
|
write(bcolors.OKBLUE)
|
94 |
|
|
write(str(round(HeadParser.AvLiveLumi,1))+"e30")
|
95 |
|
|
write(bcolors.ENDC+"\n\n")
|
96 |
|
|
|
97 |
|
|
#print "Printing all PS columns"
|
98 |
|
|
#print HeadParser.PrescaleColumn
|
99 |
|
|
print "Using prescale column %s" % HeadParser.PrescaleColumn[-2]
|
100 |
|
|
|
101 |
|
|
#print HeadParser.PrescaleColumn
|
102 |
|
|
if HeadParser.PrescaleColumn[-2]==0:
|
103 |
|
|
write(bcolors.FAIL)
|
104 |
|
|
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) )
|
105 |
|
|
write("If this is a mistake FIX IT NOW \nif not, the TFM and HLT DOC must be informed\n\n")
|
106 |
|
|
|
107 |
|
|
write("\n\n")
|
108 |
|
|
write(bcolors.ENDC)
|
109 |
|
|
|
110 |
|
|
nameBufLen=60
|
111 |
|
|
RateBuffLen=10
|
112 |
|
|
write('*'*(nameBufLen+3*RateBuffLen+2)+'\n')
|
113 |
|
|
write('* Trigger Name'+' '*(nameBufLen-17)+'* Actual * Expected * % Diff *\n')
|
114 |
|
|
write('*'*(nameBufLen+3*RateBuffLen+2)+'\n')
|
115 |
|
|
|
116 |
|
|
IgnoredRates=[]
|
117 |
|
|
LargeRateDifference=False
|
118 |
|
|
for headTrigN,headTrigRate,headTrigPS,headL1 in HeadRates:
|
119 |
|
|
headTrigNNoVersion = headTrigN[:headTrigN.rfind('_')]
|
120 |
|
|
if not Config.AnalyzeTrigger(headTrigNNoVersion): ## SKIP triggers in the skip list
|
121 |
|
|
continue
|
122 |
|
|
ExpectedRate = round(Config.GetExpectedRate(headTrigNNoVersion,HeadParser.AvLiveLumi),1)
|
123 |
|
|
PerDiff=0
|
124 |
|
|
if ExpectedRate>0:
|
125 |
|
|
PerDiff = int(round( (headTrigRate-ExpectedRate)/ExpectedRate,2 )*100)
|
126 |
|
|
##Write Line ##
|
127 |
|
|
if headTrigRate==0:
|
128 |
|
|
write(bcolors.FAIL)
|
129 |
|
|
elif abs(PerDiff) > AllowedRateDiff:
|
130 |
|
|
write(bcolors.FAIL)
|
131 |
|
|
else:
|
132 |
|
|
write(bcolors.OKGREEN)
|
133 |
|
|
write('* '+headTrigN+' '*(nameBufLen-len(headTrigN)-5)+'*')
|
134 |
|
|
write(' '*(RateBuffLen-len(str(headTrigRate))-1)+str(headTrigRate)+' *')
|
135 |
|
|
write(' '*(RateBuffLen-len(str(ExpectedRate))-1)+str(ExpectedRate)+' *')
|
136 |
|
|
if ExpectedRate>0:
|
137 |
|
|
if abs(PerDiff) > AllowedRateDiff/2:
|
138 |
|
|
write(' '+' '*(RateBuffLen-len(str(PerDiff))-2)+str(PerDiff)+'%')
|
139 |
|
|
else:
|
140 |
|
|
write(' good ')
|
141 |
|
|
else:
|
142 |
|
|
write(' ')
|
143 |
|
|
write(' *')
|
144 |
|
|
if headTrigRate==0:
|
145 |
|
|
write(" << TRIGGER RATE IS ZERO! check shift instructions")
|
146 |
|
|
elif abs(PerDiff) > AllowedRateDiff:
|
147 |
|
|
write(" << LARGE RATE DIFFERENCE: check shift instructions")
|
148 |
|
|
LargeRateDifference=True # this means we automatically check the reference run
|
149 |
|
|
write(bcolors.ENDC+'\n')
|
150 |
|
|
|
151 |
|
|
CallDOC=False
|
152 |
|
|
if ( LargeRateDifference or Config.CompareReference ) and RefRunNum != 0:
|
153 |
|
|
if LargeRateDifference:
|
154 |
|
|
write(bcolors.WARNING)
|
155 |
|
|
print """
|
156 |
|
|
\n\n
|
157 |
|
|
********************************************************************
|
158 |
|
|
A trigger in this run has a substantial difference from expectations.\n
|
159 |
|
|
Comparing the current run to a reference run
|
160 |
|
|
********************************************************************
|
161 |
|
|
"""
|
162 |
|
|
write(bcolors.ENDC)
|
163 |
|
|
else:
|
164 |
|
|
print "\n\n Comparing to reference Run:\n\n"
|
165 |
|
|
|
166 |
|
|
write('*'*(nameBufLen+3*RateBuffLen+2)+'\n')
|
167 |
|
|
write('* Trigger Name'+' '*(nameBufLen-17)+'* Actual * Expected * % Diff *\n')
|
168 |
|
|
write('*'*(nameBufLen+3*RateBuffLen+2)+'\n')
|
169 |
|
|
|
170 |
|
|
NotFound=[]
|
171 |
|
|
for headTrigN,headTrigRate,headTrigPS,headL1 in HeadRates:
|
172 |
|
|
headTrigNNoVersion = headTrigN[:headTrigN.rfind('_')]
|
173 |
|
|
if not Config.AnalyzeTrigger(headTrigNNoVersion): ## SKIP triggers in the skip list
|
174 |
|
|
continue
|
175 |
|
|
ExpectedRate=-1
|
176 |
|
|
for refTrigN,refTrigRate,refTrigPS,refLa in RefParser.TriggerRates:
|
177 |
|
|
refTrigNNoVersion = refTrigN[:refTrigN.rfind('_')]
|
178 |
|
|
if refTrigNNoVersion == headTrigNNoVersion:
|
179 |
|
|
ExpectedRate = round(refTrigRate * HeadParser.AvLiveLumi/RefParser.AvLiveLumi,2)
|
180 |
|
|
break
|
181 |
|
|
if ExpectedRate==-1:
|
182 |
|
|
NotFound.append(headTrigNNoVersion)
|
183 |
|
|
continue
|
184 |
|
|
PerDiff=0
|
185 |
|
|
if ExpectedRate>0:
|
186 |
|
|
PerDiff = int(round( (headTrigRate-ExpectedRate)/ExpectedRate,2 )*100)
|
187 |
|
|
##Write Line ##
|
188 |
|
|
if headTrigRate==0:
|
189 |
|
|
write(bcolors.FAIL)
|
190 |
|
|
elif abs(PerDiff) >AllowedRateDiff:
|
191 |
|
|
write(bcolors.FAIL)
|
192 |
|
|
else:
|
193 |
|
|
write(bcolors.OKGREEN)
|
194 |
|
|
write('* '+headTrigN+' '*(nameBufLen-len(headTrigN)-5)+'*')
|
195 |
|
|
write(' '*(RateBuffLen-len(str(headTrigRate))-1)+str(headTrigRate)+' *')
|
196 |
|
|
write(' '*(RateBuffLen-len(str(ExpectedRate))-1)+str(ExpectedRate)+' *')
|
197 |
|
|
if ExpectedRate>0:
|
198 |
|
|
if abs(PerDiff) > AllowedRateDiff/2:
|
199 |
|
|
write(' '+' '*(RateBuffLen-len(str(PerDiff))-2)+str(PerDiff)+'%')
|
200 |
|
|
else:
|
201 |
|
|
write(' good ')
|
202 |
|
|
else:
|
203 |
|
|
write(' ')
|
204 |
|
|
write(' *')
|
205 |
|
|
if headTrigRate==0:
|
206 |
|
|
write(" << TRIGGER RATE IS ZERO! CALL HLT DOC")
|
207 |
|
|
CallDOC=True
|
208 |
|
|
elif abs(PerDiff) > AllowedRateDiff:
|
209 |
|
|
write(" << LARGE RATE DIFFERENCE WITH REFERENCE RUN")
|
210 |
|
|
CallDOC=True
|
211 |
|
|
write(bcolors.ENDC+'\n')
|
212 |
|
|
|
213 |
|
|
if CallDOC:
|
214 |
|
|
write(bcolors.FAIL)
|
215 |
|
|
print "\nSomething looks very wrong in this run"
|
216 |
|
|
print "If there is no obvious reason for this (subdetector out, etc.): **inform the SHIFT LEADER and call the HLT DOC!**"
|
217 |
|
|
raw_input("Press Enter to continue ... ")
|
218 |
|
|
write(bcolors.ENDC)
|
219 |
|
|
|
220 |
|
|
if FindL1Zeros:
|
221 |
|
|
L1Zeros=[]
|
222 |
|
|
IgnoreBits = ["L1_PreCollisions","L1_InterBunch_Bsc","L1_BeamHalo","L1_BeamGas_Hf"]
|
223 |
|
|
for trigN,L1Pass,PSPass,PAccept,SeedName in HeadParser.Nevts:
|
224 |
|
|
## Skip events in the skip list
|
225 |
|
|
trigNNoVersion = trigN[:trigN.rfind('_')]
|
226 |
|
|
if Config.AnalyzeTrigger(trigNNoVersion):
|
227 |
|
|
continue
|
228 |
|
|
## if no events pass the L1, add it to the L1Zeros list if not already there
|
229 |
|
|
if SeedName in IgnoreBits:
|
230 |
|
|
continue
|
231 |
|
|
if L1Pass==0 and not SeedName in L1Zeros and SeedName.find("BeamGas")==-1 and SeedName.find('L1_SingleMuOpen')==-1:
|
232 |
|
|
L1Zeros.append(SeedName)
|
233 |
|
|
if len(L1Zeros) == 0:
|
234 |
|
|
pass
|
235 |
|
|
#print bcolors.OKGREEN+">>> L1 Seeds are fine"+bcolors.ENDC
|
236 |
|
|
|
237 |
|
|
# end if find l1 zeros
|
238 |
|
|
|
239 |
|
|
FirstTime+=1
|
240 |
|
|
# End of if FirstTime
|
241 |
|
|
#end of try
|
242 |
|
|
except KeyboardInterrupt:
|
243 |
|
|
print "Quitting the program"
|