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