ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.35
Committed: Tue Jul 17 15:12:27 2012 UTC (12 years, 9 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-01-06, V00-01-05, V00-01-04, V00-01-03, V00-01-02, V00-01-01, V00-00-34, V00-00-33
Changes since 1.34: +36 -5 lines
Log Message:
log monitoring, tier0 warnings, correct prompt stream A rate

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