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