ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.27
Committed: Thu May 3 15:31:09 2012 UTC (13 years ago) by amott
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-32
Changes since 1.26: +4 -3 lines
Log Message:
added a warning for the wrong column

File Contents

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