ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.43
Committed: Tue Dec 4 17:25:17 2012 UTC (12 years, 4 months ago) by awoodard
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-02-06, HEAD
Changes since 1.42: +11 -12 lines
Log Message:
Merging fixes to logmonitor warning from the P5 version of the script.

File Contents

# User Rev Content
1 amott 1.1 import sys
2     from colors import *
3     from DatabaseParser import *
4 amott 1.12 from termcolor import colored, cprint
5 awoodard 1.36 from StreamMonitor import *
6 grchrist 1.34 import time
7    
8    
9 amott 1.1 write = sys.stdout.write
10    
11 awoodard 1.36 NHighStreamA = 0
12     NHighExpress = 0
13 amott 1.12
14 amott 1.13 def MoreTableInfo(parser,LumiRange,config,isCol=True):
15 grchrist 1.41 global NHighStreamA
16     global NHighExpress
17 amott 1.14 print "Monitoring Run %d" % (parser.RunNumber,)
18 grchrist 1.34 localtime = time.asctime( time.localtime(time.time()) )
19     print "Local current time :", localtime
20 grchrist 1.35 #print "Lumisections used=", LumiRange
21 grchrist 1.23 if len(LumiRange)>0:
22 grchrist 1.25
23 grchrist 1.23 [AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
24 grchrist 1.24 deadtimebeamactive=parser.GetDeadTimeBeamActive(LumiRange)*100
25 grchrist 1.35
26 grchrist 1.24 ##print "dtba=",deadtimebeamactive
27 grchrist 1.23 else:
28     print "no lumisections to monitor"
29     return
30 amott 1.37 ## check if lumi is being filled
31 grchrist 1.40 if parser.LastLSParsed > 4 and isCol:
32 amott 1.37 if set(parser.InstLumiByLS.values()) == set([None]):
33 amott 1.38 write(colored("\n\nLUMI INFORMATION NOT BEING SENT!\n",'red',attrs=['reverse']))
34 amott 1.37 write(colored("Check with Shift Leader if this is expected\n",'red',attrs=['reverse']))
35 amott 1.39 write(colored("If not, HFLUMI needs to be red-recycled\n\n\n",'red',attrs=['reverse']))
36     write(colored("If in doubt, call Lumi DOC\n\n\n",'red',attrs=['reverse']))
37 amott 1.37
38 grchrist 1.35 try:
39     lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v3")
40     if not len(lograte):
41     lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v4")
42 awoodard 1.43
43     for ls in LumiRange:
44     current_lograte = lograte.get(ls,0)
45     lograte_sum =+ current_lograte
46    
47     lograte_average = lograte_sum/len(LumiRange)
48     if lograte_average > config.MaxLogMonRate:
49     write(bcolors.WARNING)
50     print "Post to elog. LogMonitor rate is high: %.2f" % (lograte_average)
51     write(bcolors.ENDC+"\n")
52    
53 grchrist 1.35 except:
54     write(bcolors.WARNING)
55     print "problem getting log monitor rates"
56     write(bcolors.ENDC+"\n")
57    
58 amott 1.13 try:
59     LastPSCol = PSCols[-1]
60     except:
61     LastPSCol = -1
62 grchrist 1.19
63 amott 1.13 expressRates = {}
64     if isCol:
65     expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
66     else:
67 grchrist 1.19 if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
68 awoodard 1.42 expressRates=parser.GetTriggerRatesByLS("ExpressOutput")
69 grchrist 1.19 else:
70     expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
71 awoodard 1.36
72 amott 1.12 ExpRate=0
73     PeakRate=0
74 amott 1.13 AvgExpRate=0
75 grchrist 1.15
76 amott 1.13 if len(expressRates.values()) > 20:
77     AvgExpRate = sum(expressRates.values())/len(expressRates.values())
78 grchrist 1.35 counter=0
79 awoodard 1.36
80 amott 1.12 for ls in LumiRange: ## Find the sum and peak express stream rates
81     thisR = expressRates.get(ls,0)
82     ExpRate+=thisR
83     if thisR>PeakRate:
84     PeakRate=thisR
85 grchrist 1.15
86 awoodard 1.36
87 grchrist 1.15 ## Print Stream A Rate --moved see below
88     ##print "Current Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
89 amott 1.12
90 amott 1.13 Warn = False
91 amott 1.12
92 grchrist 1.15 ##########################################
93 grchrist 1.31 ## Check if the express stream is too high or low
94 grchrist 1.15 ##########################################
95 grchrist 1.33 badExpress = ((ExpRate/len(LumiRange) > config.MaxExpressRate) or (ExpRate/len(LumiRange)<0.1 and isCol)) ## avg express stream rate too high?
96 grchrist 1.16 baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
97 amott 1.12 if badExpress:
98     text = colored(baseText,'red',attrs=['reverse']) ## bad, make the text white on red
99     NHighExpress+=1 ## increment the bad express counter
100     else:
101     text = baseText
102     NHighExpress=0
103    
104     write(text)
105     if badExpress:
106 grchrist 1.21 if len(LumiRange)>1:
107 grchrist 1.20 if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
108     write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
109     else:
110     if NHighExpress > 1: # big problem, call HLT DOC
111     write(colored(" << WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
112     Warn = True
113 amott 1.13
114     # if AvgExpRate > config.MaxExpressRate:
115     # write( colored("\n\nWARNING: Average Express Stream Rate is too high (%0.1f Hz) << CALL HLT DOC" % AvgExpRate,'red',attrs=['reverse']) )
116     # Warn = True
117 grchrist 1.20
118    
119 grchrist 1.15
120    
121     #########################################
122     ##Check if Stream A is too high
123     #########################################
124     global NHighStreamA
125 awoodard 1.36 stream_mon = StreamMonitor()
126     core_a_rates = stream_mon.getStreamACoreRatesByLS(parser,LumiRange,config,isCol).values()
127     a_rates = stream_mon.getStreamARatesByLS(parser,LumiRange).values()
128     peak_core_a_rate = max(core_a_rates)
129    
130     if len(LumiRange) > 0:
131     avg_core_a_rate = sum(core_a_rates)/len(LumiRange)
132     avg_a_rate = sum(a_rates)/len(LumiRange)
133     badStreamA = stream_mon.compareStreamARate(config, avg_core_a_rate, LumiRange,AvInstLumi,isCol)
134    
135     baseTextA= "\nCurrent Stream A Rate is: %0.1f Hz" % (avg_a_rate)
136     baseTextRealA= "\nCurrent PROMPT Stream A Rate is: %0.1f Hz" % (avg_core_a_rate)
137    
138     if badStreamA:
139     textA=colored(baseTextA,'red',attrs=['reverse']) ## bad, make the text white on red
140     textRealA=colored(baseTextRealA,'red',attrs=['reverse']) ## bad, make the text white on red
141     NHighStreamA+=1
142     else:
143     textA=baseTextA
144     textRealA=baseTextRealA
145    
146     write(textA)
147     write(textRealA)
148    
149     if badStreamA and len(LumiRange) > 1:
150     trimmed_core_a_rates = core_a_rates
151     trimmed_core_a_rates.remove(peak_core_a_rate)
152     if sum(trimmed_core_a_rates)/(len(LumiRange)-1) <= config.MaxStreamARate: ## one lumisection causes this
153 grchrist 1.20 write(" << This appears to be due to a 1 lumisection spike, please monitor\n")
154     else:
155 awoodard 1.36 if NHighStreamA > 1: ##Call HLT doc!
156 grchrist 1.20 write(colored(" << WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
157     Warn = True
158 amott 1.13 write("\n\n")
159 grchrist 1.15
160     ######################################
161     ##Warning for HLT doc
162     ######################################
163 amott 1.13 if Warn: ## WARNING
164     rows, columns = os.popen('stty size', 'r').read().split() ## Get the terminal size
165     cols = int(columns)
166     write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
167     line = "*" + " "*int((cols-22)/2)+"CALL HLT DOC (165575)"+" "*int((cols-23)/2)+"*\n"
168 amott 1.12
169 amott 1.13 write( colored(line,'red',attrs=['reverse','blink']) )
170     write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
171 awoodard 1.36
172 grchrist 1.17
173 amott 1.1 PrescaleColumnString=''
174 abrinke1 1.10 PSCols = list(set(PSCols))
175 amott 1.1 for c in PSCols:
176     PrescaleColumnString = PrescaleColumnString + str(c) + ","
177    
178 amott 1.13 if isCol:
179     write("The average instantaneous lumi of these lumisections is: ")
180     write(str(round(AvInstLumi,1))+"e30\n")
181     write("The delivered lumi of these lumi sections is: ")
182     write(str(round(len(LumiRange)*AvDeliveredLumi,1))+"e30"+"\n")
183     write("The live (recorded) lumi of these lumi sections is: ")
184     write(str(round(len(LumiRange)*AvLiveLumi,1))+"e30\n\n")
185     write("The average deadtime of these lumi sections is: ")
186 grchrist 1.17 if deadtimebeamactive > 5:
187 amott 1.13 write(bcolors.FAIL)
188 grchrist 1.17 elif deadtimebeamactive > 10:
189 amott 1.13 write(bcolors.WARNING)
190     else:
191     write(bcolors.OKBLUE)
192 grchrist 1.17 write(str(round(deadtimebeamactive,2))+"%")
193 amott 1.13 write(bcolors.ENDC+"\n")
194 amott 1.27 write("Used prescale column(s): %s " % (str(PrescaleColumnString),) )
195     if LastPSCol in config.ForbiddenCols and isCol:
196     write( colored("<< Using column %d! Please check in the documentation that this is the correct column" % (LastPSCol),'red',attrs=['reverse']) )
197     write("\nLumisections: ")
198 amott 1.3 if not isSequential(LumiRange):
199 amott 1.4 write(str(LumiRange)+" Lumisections are not sequential (bad LS skipped)\n")
200     else:
201     write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
202 grchrist 1.23 ##print "\nLast Lumisection of the run is: "+str(parser.GetLastLS())
203     write( "\nLast Lumisection good where DAQ is active is: "+str(parser.GetLastLS(isCol)) )
204 grchrist 1.19 ##write( "Last Lumisection where DAQ is active is: "+str(parser.GetLastLS(True)) )
205 amott 1.12 write("\n\n\n")
206 amott 1.5
207 grchrist 1.22 ## if isCol:
208     ## L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
209     ## if len(L1RatePredictions):
210     ## print "Expected Level 1 Rates:"
211     ## for key,val in L1RatePredictions.iteritems():
212     ## write("Prescale Column "+str(key)+": "+str(round(val/1000,1))+" kHz")
213     ## if key == LastPSCol:
214     ## write(' << taking data in this column')
215     ## write('\n')
216 amott 1.6
217 amott 1.5
218 amott 1.3
219     def isSequential(t):
220     try:
221     if len(t)<2:
222     return True
223     except:
224     return True
225     for i,e in enumerate(t[1:]):
226     if not abs(e-t[i])==1:
227     return False
228     return True