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