ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.41
Committed: Thu Oct 18 11:42:44 2012 UTC (12 years, 6 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-02-05
Changes since 1.40: +2 -0 lines
Log Message:
Updates for deployment at P5 and added parking list

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