ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.22
Committed: Thu Apr 5 06:13:40 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.21: +9 -9 lines
Log Message:
masked L1 predictions for now

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