1 |
amott |
1.1 |
import sys
|
2 |
|
|
from colors import *
|
3 |
|
|
from DatabaseParser import *
|
4 |
amott |
1.12 |
from termcolor import colored, cprint
|
5 |
awoodard |
1.36 |
from StreamMonitor import *
|
6 |
grchrist |
1.34 |
import time
|
7 |
|
|
|
8 |
|
|
|
9 |
amott |
1.1 |
write = sys.stdout.write
|
10 |
|
|
|
11 |
awoodard |
1.36 |
NHighStreamA = 0
|
12 |
|
|
NHighExpress = 0
|
13 |
amott |
1.12 |
|
14 |
amott |
1.13 |
def MoreTableInfo(parser,LumiRange,config,isCol=True):
|
15 |
amott |
1.14 |
print "Monitoring Run %d" % (parser.RunNumber,)
|
16 |
grchrist |
1.34 |
localtime = time.asctime( time.localtime(time.time()) )
|
17 |
|
|
print "Local current time :", localtime
|
18 |
grchrist |
1.35 |
#print "Lumisections used=", LumiRange
|
19 |
grchrist |
1.23 |
if len(LumiRange)>0:
|
20 |
grchrist |
1.25 |
|
21 |
grchrist |
1.23 |
[AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
|
22 |
grchrist |
1.24 |
deadtimebeamactive=parser.GetDeadTimeBeamActive(LumiRange)*100
|
23 |
grchrist |
1.35 |
|
24 |
grchrist |
1.24 |
##print "dtba=",deadtimebeamactive
|
25 |
grchrist |
1.23 |
else:
|
26 |
|
|
print "no lumisections to monitor"
|
27 |
|
|
return
|
28 |
amott |
1.37 |
## check if lumi is being filled
|
29 |
|
|
if parser.LastLSParsed > 4:
|
30 |
|
|
if set(parser.InstLumiByLS.values()) == set([None]):
|
31 |
amott |
1.38 |
write(colored("\n\nLUMI INFORMATION NOT BEING SENT!\n",'red',attrs=['reverse']))
|
32 |
amott |
1.37 |
write(colored("Check with Shift Leader if this is expected\n",'red',attrs=['reverse']))
|
33 |
amott |
1.39 |
write(colored("If not, HFLUMI needs to be red-recycled\n\n\n",'red',attrs=['reverse']))
|
34 |
|
|
write(colored("If in doubt, call Lumi DOC\n\n\n",'red',attrs=['reverse']))
|
35 |
amott |
1.38 |
#return
|
36 |
amott |
1.37 |
|
37 |
grchrist |
1.35 |
try:
|
38 |
|
|
#print "trying v3"
|
39 |
|
|
lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v3")
|
40 |
|
|
#print lograte
|
41 |
|
|
if not len(lograte):
|
42 |
|
|
#print "trying v4"
|
43 |
|
|
lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v4")
|
44 |
|
|
|
45 |
|
|
#print lograte
|
46 |
|
|
for lumi in lograte.iterkeys():
|
47 |
|
|
#print lumi, lograte[lumi]
|
48 |
|
|
if lograte[lumi]>config.MaxLogMonRate:
|
49 |
|
|
write(bcolors.WARNING)
|
50 |
|
|
print lograte[lumi], "post to elog. LogMonitor rate is high."
|
51 |
|
|
write(bcolors.ENDC+"\n")
|
52 |
|
|
except:
|
53 |
|
|
write(bcolors.WARNING)
|
54 |
|
|
print "problem getting log monitor rates"
|
55 |
|
|
write(bcolors.ENDC+"\n")
|
56 |
|
|
|
57 |
amott |
1.13 |
try:
|
58 |
|
|
LastPSCol = PSCols[-1]
|
59 |
|
|
except:
|
60 |
|
|
LastPSCol = -1
|
61 |
grchrist |
1.19 |
|
62 |
amott |
1.13 |
expressRates = {}
|
63 |
|
|
if isCol:
|
64 |
|
|
expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
|
65 |
|
|
else:
|
66 |
grchrist |
1.19 |
if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
|
67 |
awoodard |
1.36 |
expressRates=parser.GetTriggerRatesByLS("else")
|
68 |
grchrist |
1.19 |
else:
|
69 |
|
|
expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
|
70 |
awoodard |
1.36 |
|
71 |
amott |
1.12 |
ExpRate=0
|
72 |
|
|
PeakRate=0
|
73 |
amott |
1.13 |
AvgExpRate=0
|
74 |
grchrist |
1.15 |
|
75 |
amott |
1.13 |
if len(expressRates.values()) > 20:
|
76 |
|
|
AvgExpRate = sum(expressRates.values())/len(expressRates.values())
|
77 |
grchrist |
1.35 |
counter=0
|
78 |
awoodard |
1.36 |
|
79 |
amott |
1.12 |
for ls in LumiRange: ## Find the sum and peak express stream rates
|
80 |
|
|
thisR = expressRates.get(ls,0)
|
81 |
|
|
ExpRate+=thisR
|
82 |
|
|
if thisR>PeakRate:
|
83 |
|
|
PeakRate=thisR
|
84 |
grchrist |
1.15 |
|
85 |
awoodard |
1.36 |
|
86 |
grchrist |
1.15 |
## Print Stream A Rate --moved see below
|
87 |
|
|
##print "Current Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
|
88 |
amott |
1.12 |
|
89 |
amott |
1.13 |
Warn = False
|
90 |
amott |
1.12 |
|
91 |
grchrist |
1.15 |
##########################################
|
92 |
grchrist |
1.31 |
## Check if the express stream is too high or low
|
93 |
grchrist |
1.15 |
##########################################
|
94 |
grchrist |
1.33 |
badExpress = ((ExpRate/len(LumiRange) > config.MaxExpressRate) or (ExpRate/len(LumiRange)<0.1 and isCol)) ## avg express stream rate too high?
|
95 |
grchrist |
1.16 |
baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
|
96 |
amott |
1.12 |
if badExpress:
|
97 |
|
|
text = colored(baseText,'red',attrs=['reverse']) ## bad, make the text white on red
|
98 |
|
|
NHighExpress+=1 ## increment the bad express counter
|
99 |
|
|
else:
|
100 |
|
|
text = baseText
|
101 |
|
|
NHighExpress=0
|
102 |
|
|
|
103 |
|
|
write(text)
|
104 |
|
|
if badExpress:
|
105 |
grchrist |
1.21 |
if len(LumiRange)>1:
|
106 |
grchrist |
1.20 |
if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
|
107 |
|
|
write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
|
108 |
|
|
else:
|
109 |
|
|
if NHighExpress > 1: # big problem, call HLT DOC
|
110 |
|
|
write(colored(" << WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
|
111 |
|
|
Warn = True
|
112 |
amott |
1.13 |
|
113 |
|
|
# if AvgExpRate > config.MaxExpressRate:
|
114 |
|
|
# write( colored("\n\nWARNING: Average Express Stream Rate is too high (%0.1f Hz) << CALL HLT DOC" % AvgExpRate,'red',attrs=['reverse']) )
|
115 |
|
|
# Warn = True
|
116 |
grchrist |
1.20 |
|
117 |
|
|
|
118 |
grchrist |
1.15 |
|
119 |
|
|
|
120 |
|
|
#########################################
|
121 |
|
|
##Check if Stream A is too high
|
122 |
|
|
#########################################
|
123 |
|
|
global NHighStreamA
|
124 |
awoodard |
1.36 |
stream_mon = StreamMonitor()
|
125 |
|
|
core_a_rates = stream_mon.getStreamACoreRatesByLS(parser,LumiRange,config,isCol).values()
|
126 |
|
|
a_rates = stream_mon.getStreamARatesByLS(parser,LumiRange).values()
|
127 |
|
|
peak_core_a_rate = max(core_a_rates)
|
128 |
|
|
|
129 |
|
|
if len(LumiRange) > 0:
|
130 |
|
|
avg_core_a_rate = sum(core_a_rates)/len(LumiRange)
|
131 |
|
|
avg_a_rate = sum(a_rates)/len(LumiRange)
|
132 |
|
|
badStreamA = stream_mon.compareStreamARate(config, avg_core_a_rate, LumiRange,AvInstLumi,isCol)
|
133 |
|
|
|
134 |
|
|
baseTextA= "\nCurrent Stream A Rate is: %0.1f Hz" % (avg_a_rate)
|
135 |
|
|
baseTextRealA= "\nCurrent PROMPT Stream A Rate is: %0.1f Hz" % (avg_core_a_rate)
|
136 |
|
|
|
137 |
|
|
if badStreamA:
|
138 |
|
|
textA=colored(baseTextA,'red',attrs=['reverse']) ## bad, make the text white on red
|
139 |
|
|
textRealA=colored(baseTextRealA,'red',attrs=['reverse']) ## bad, make the text white on red
|
140 |
|
|
NHighStreamA+=1
|
141 |
|
|
else:
|
142 |
|
|
textA=baseTextA
|
143 |
|
|
textRealA=baseTextRealA
|
144 |
|
|
|
145 |
|
|
write(textA)
|
146 |
|
|
write(textRealA)
|
147 |
|
|
|
148 |
|
|
if badStreamA and len(LumiRange) > 1:
|
149 |
|
|
trimmed_core_a_rates = core_a_rates
|
150 |
|
|
trimmed_core_a_rates.remove(peak_core_a_rate)
|
151 |
|
|
if sum(trimmed_core_a_rates)/(len(LumiRange)-1) <= config.MaxStreamARate: ## one lumisection causes this
|
152 |
grchrist |
1.20 |
write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
|
153 |
|
|
else:
|
154 |
awoodard |
1.36 |
if NHighStreamA > 1: ##Call HLT doc!
|
155 |
grchrist |
1.20 |
write(colored(" << WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
|
156 |
|
|
Warn = True
|
157 |
amott |
1.13 |
write("\n\n")
|
158 |
grchrist |
1.15 |
|
159 |
|
|
######################################
|
160 |
|
|
##Warning for HLT doc
|
161 |
|
|
######################################
|
162 |
amott |
1.13 |
if Warn: ## WARNING
|
163 |
|
|
rows, columns = os.popen('stty size', 'r').read().split() ## Get the terminal size
|
164 |
|
|
cols = int(columns)
|
165 |
|
|
write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
|
166 |
|
|
line = "*" + " "*int((cols-22)/2)+"CALL HLT DOC (165575)"+" "*int((cols-23)/2)+"*\n"
|
167 |
amott |
1.12 |
|
168 |
amott |
1.13 |
write( colored(line,'red',attrs=['reverse','blink']) )
|
169 |
|
|
write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
|
170 |
awoodard |
1.36 |
|
171 |
grchrist |
1.17 |
|
172 |
amott |
1.1 |
PrescaleColumnString=''
|
173 |
abrinke1 |
1.10 |
PSCols = list(set(PSCols))
|
174 |
amott |
1.1 |
for c in PSCols:
|
175 |
|
|
PrescaleColumnString = PrescaleColumnString + str(c) + ","
|
176 |
|
|
|
177 |
amott |
1.13 |
if isCol:
|
178 |
|
|
write("The average instantaneous lumi of these lumisections is: ")
|
179 |
|
|
write(str(round(AvInstLumi,1))+"e30\n")
|
180 |
|
|
write("The delivered lumi of these lumi sections is: ")
|
181 |
|
|
write(str(round(len(LumiRange)*AvDeliveredLumi,1))+"e30"+"\n")
|
182 |
|
|
write("The live (recorded) lumi of these lumi sections is: ")
|
183 |
|
|
write(str(round(len(LumiRange)*AvLiveLumi,1))+"e30\n\n")
|
184 |
|
|
write("The average deadtime of these lumi sections is: ")
|
185 |
grchrist |
1.17 |
if deadtimebeamactive > 5:
|
186 |
amott |
1.13 |
write(bcolors.FAIL)
|
187 |
grchrist |
1.17 |
elif deadtimebeamactive > 10:
|
188 |
amott |
1.13 |
write(bcolors.WARNING)
|
189 |
|
|
else:
|
190 |
|
|
write(bcolors.OKBLUE)
|
191 |
grchrist |
1.17 |
write(str(round(deadtimebeamactive,2))+"%")
|
192 |
amott |
1.13 |
write(bcolors.ENDC+"\n")
|
193 |
amott |
1.27 |
write("Used prescale column(s): %s " % (str(PrescaleColumnString),) )
|
194 |
|
|
if LastPSCol in config.ForbiddenCols and isCol:
|
195 |
|
|
write( colored("<< Using column %d! Please check in the documentation that this is the correct column" % (LastPSCol),'red',attrs=['reverse']) )
|
196 |
|
|
write("\nLumisections: ")
|
197 |
amott |
1.3 |
if not isSequential(LumiRange):
|
198 |
amott |
1.4 |
write(str(LumiRange)+" Lumisections are not sequential (bad LS skipped)\n")
|
199 |
|
|
else:
|
200 |
|
|
write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
|
201 |
grchrist |
1.23 |
##print "\nLast Lumisection of the run is: "+str(parser.GetLastLS())
|
202 |
|
|
write( "\nLast Lumisection good where DAQ is active is: "+str(parser.GetLastLS(isCol)) )
|
203 |
grchrist |
1.19 |
##write( "Last Lumisection where DAQ is active is: "+str(parser.GetLastLS(True)) )
|
204 |
amott |
1.12 |
write("\n\n\n")
|
205 |
amott |
1.5 |
|
206 |
grchrist |
1.22 |
## if isCol:
|
207 |
|
|
## L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
|
208 |
|
|
## if len(L1RatePredictions):
|
209 |
|
|
## print "Expected Level 1 Rates:"
|
210 |
|
|
## for key,val in L1RatePredictions.iteritems():
|
211 |
|
|
## write("Prescale Column "+str(key)+": "+str(round(val/1000,1))+" kHz")
|
212 |
|
|
## if key == LastPSCol:
|
213 |
|
|
## write(' << taking data in this column')
|
214 |
|
|
## write('\n')
|
215 |
amott |
1.6 |
|
216 |
amott |
1.5 |
|
217 |
amott |
1.3 |
|
218 |
|
|
def isSequential(t):
|
219 |
|
|
try:
|
220 |
|
|
if len(t)<2:
|
221 |
|
|
return True
|
222 |
|
|
except:
|
223 |
|
|
return True
|
224 |
|
|
for i,e in enumerate(t[1:]):
|
225 |
|
|
if not abs(e-t[i])==1:
|
226 |
|
|
return False
|
227 |
|
|
return True
|