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