1 |
import sys
|
2 |
from colors import *
|
3 |
from DatabaseParser import *
|
4 |
from termcolor import colored, cprint
|
5 |
write = sys.stdout.write
|
6 |
|
7 |
NHighExpress=0
|
8 |
NHighStreamA=0
|
9 |
|
10 |
def MoreTableInfo(parser,LumiRange,config,isCol=True):
|
11 |
print "Monitoring Run %d" % (parser.RunNumber,)
|
12 |
print "len=",len(LumiRange)
|
13 |
if len(LumiRange)>0:
|
14 |
|
15 |
[AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
|
16 |
deadtimebeamactive=parser.GetDeadTimeBeamActive(LumiRange)*100
|
17 |
##print "dtba=",deadtimebeamactive
|
18 |
else:
|
19 |
print "no lumisections to monitor"
|
20 |
return
|
21 |
try:
|
22 |
LastPSCol = PSCols[-1]
|
23 |
except:
|
24 |
LastPSCol = -1
|
25 |
if isCol:
|
26 |
|
27 |
aRates = parser.GetTriggerRatesByLS("AOutput")
|
28 |
else:
|
29 |
if len(parser.GetTriggerRatesByLS("AOutput"))>0:
|
30 |
aRates = parser.GetTriggerRatesByLS("AOutput")
|
31 |
else:
|
32 |
aRates = parser.GetTriggerRatesByLS("AForPPOutput")
|
33 |
|
34 |
|
35 |
expressRates = {}
|
36 |
if isCol:
|
37 |
expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
|
38 |
else:
|
39 |
if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
|
40 |
expressRates=parser.GetTriggerRatesByLS("ExpressOutput")
|
41 |
else:
|
42 |
expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
|
43 |
ExpRate=0
|
44 |
PeakRate=0
|
45 |
AvgExpRate=0
|
46 |
|
47 |
ARate=0
|
48 |
PeakRateA=0
|
49 |
AvgRateA=0
|
50 |
|
51 |
if len(expressRates.values()) > 20:
|
52 |
AvgExpRate = sum(expressRates.values())/len(expressRates.values())
|
53 |
|
54 |
for ls in LumiRange: ## Find the sum and peak express stream rates
|
55 |
thisR = expressRates.get(ls,0)
|
56 |
ExpRate+=thisR
|
57 |
if thisR>PeakRate:
|
58 |
PeakRate=thisR
|
59 |
|
60 |
thisRateA=aRates.get(ls,0)
|
61 |
ARate+=thisRateA
|
62 |
if thisRateA>PeakRateA:
|
63 |
PeakRateA=thisRateA
|
64 |
|
65 |
#ARate+=aRates.get(ls,0)
|
66 |
## Print Stream A Rate --moved see below
|
67 |
##print "Current Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
|
68 |
|
69 |
Warn = False
|
70 |
|
71 |
##########################################
|
72 |
## Check if the express stream is too high
|
73 |
##########################################
|
74 |
global NHighExpress
|
75 |
badExpress = ExpRate/len(LumiRange) > config.MaxExpressRate ## avg express stream rate too high?
|
76 |
baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
|
77 |
if badExpress:
|
78 |
text = colored(baseText,'red',attrs=['reverse']) ## bad, make the text white on red
|
79 |
NHighExpress+=1 ## increment the bad express counter
|
80 |
else:
|
81 |
text = baseText
|
82 |
NHighExpress=0
|
83 |
|
84 |
write(text)
|
85 |
if badExpress:
|
86 |
if len(LumiRange)>1:
|
87 |
if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
|
88 |
write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
|
89 |
else:
|
90 |
if NHighExpress > 1: # big problem, call HLT DOC
|
91 |
write(colored(" << WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
|
92 |
Warn = True
|
93 |
|
94 |
# if AvgExpRate > config.MaxExpressRate:
|
95 |
# write( colored("\n\nWARNING: Average Express Stream Rate is too high (%0.1f Hz) << CALL HLT DOC" % AvgExpRate,'red',attrs=['reverse']) )
|
96 |
# Warn = True
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
#########################################
|
102 |
##Check if Stream A is too high
|
103 |
#########################################
|
104 |
global NHighStreamA
|
105 |
badStreamA =ARate/len(LumiRange) > config.MaxStreamARate ##Cosmics Express Rate 300 Hz max
|
106 |
baseTextA= "\nCurrent Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
|
107 |
if badStreamA:
|
108 |
textA=colored(baseTextA,'red',attrs=['reverse']) ## bad, make the text white on red
|
109 |
NHighStreamA+=1
|
110 |
else:
|
111 |
textA=baseTextA
|
112 |
NHighStreamA=0
|
113 |
|
114 |
write(textA)
|
115 |
if badStreamA:
|
116 |
if len(LumiRange)>1:
|
117 |
if (ARate-PeakRateA)/(len(LumiRange)-1) <=config.MaxStreamARate: ## one lumisection causes this
|
118 |
write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
|
119 |
else:
|
120 |
if NHighStreamA >1: ##Call HLT doc!
|
121 |
write(colored(" << WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
|
122 |
Warn = True
|
123 |
write("\n\n")
|
124 |
|
125 |
######################################
|
126 |
##Warning for HLT doc
|
127 |
######################################
|
128 |
if Warn: ## WARNING
|
129 |
rows, columns = os.popen('stty size', 'r').read().split() ## Get the terminal size
|
130 |
cols = int(columns)
|
131 |
write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
|
132 |
line = "*" + " "*int((cols-22)/2)+"CALL HLT DOC (165575)"+" "*int((cols-23)/2)+"*\n"
|
133 |
|
134 |
write( colored(line,'red',attrs=['reverse','blink']) )
|
135 |
write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
|
136 |
|
137 |
|
138 |
PrescaleColumnString=''
|
139 |
PSCols = list(set(PSCols))
|
140 |
for c in PSCols:
|
141 |
PrescaleColumnString = PrescaleColumnString + str(c) + ","
|
142 |
|
143 |
if isCol:
|
144 |
write("The average instantaneous lumi of these lumisections is: ")
|
145 |
write(str(round(AvInstLumi,1))+"e30\n")
|
146 |
write("The delivered lumi of these lumi sections is: ")
|
147 |
write(str(round(len(LumiRange)*AvDeliveredLumi,1))+"e30"+"\n")
|
148 |
write("The live (recorded) lumi of these lumi sections is: ")
|
149 |
write(str(round(len(LumiRange)*AvLiveLumi,1))+"e30\n\n")
|
150 |
write("The average deadtime of these lumi sections is: ")
|
151 |
if deadtimebeamactive > 5:
|
152 |
write(bcolors.FAIL)
|
153 |
elif deadtimebeamactive > 10:
|
154 |
write(bcolors.WARNING)
|
155 |
else:
|
156 |
write(bcolors.OKBLUE)
|
157 |
write(str(round(deadtimebeamactive,2))+"%")
|
158 |
write(bcolors.ENDC+"\n")
|
159 |
|
160 |
print "Used prescale column(s): "+str(PrescaleColumnString)
|
161 |
write("Lumisections: ")
|
162 |
if not isSequential(LumiRange):
|
163 |
write(str(LumiRange)+" Lumisections are not sequential (bad LS skipped)\n")
|
164 |
else:
|
165 |
write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
|
166 |
##print "\nLast Lumisection of the run is: "+str(parser.GetLastLS())
|
167 |
write( "\nLast Lumisection good where DAQ is active is: "+str(parser.GetLastLS(isCol)) )
|
168 |
##write( "Last Lumisection where DAQ is active is: "+str(parser.GetLastLS(True)) )
|
169 |
write("\n\n\n")
|
170 |
|
171 |
## if isCol:
|
172 |
## L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
|
173 |
## if len(L1RatePredictions):
|
174 |
## print "Expected Level 1 Rates:"
|
175 |
## for key,val in L1RatePredictions.iteritems():
|
176 |
## write("Prescale Column "+str(key)+": "+str(round(val/1000,1))+" kHz")
|
177 |
## if key == LastPSCol:
|
178 |
## write(' << taking data in this column')
|
179 |
## write('\n')
|
180 |
|
181 |
|
182 |
|
183 |
def isSequential(t):
|
184 |
try:
|
185 |
if len(t)<2:
|
186 |
return True
|
187 |
except:
|
188 |
return True
|
189 |
for i,e in enumerate(t[1:]):
|
190 |
if not abs(e-t[i])==1:
|
191 |
return False
|
192 |
return True
|