ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.32
Committed: Mon Jul 2 12:48:31 2012 UTC (12 years, 9 months ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.31: +1 -1 lines
Log Message:
fixes to printouts and min express

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