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