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