ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.28
Committed: Thu May 10 14:27:53 2012 UTC (12 years, 11 months ago) by amott
Content type: text/x-python
Branch: MAIN
Changes since 1.27: +23 -3 lines
Log Message:
Added effective stream A monitoring

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