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

# Content
1 import sys
2 from colors import *
3 from DatabaseParser import *
4 from termcolor import colored, cprint
5 write = sys.stdout.write
6
7 NHighExpress=0
8 NHighStreamA=0
9
10 def MoreTableInfo(parser,LumiRange,config,isCol=True):
11 print "Monitoring Run %d" % (parser.RunNumber,)
12 [AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
13 deadtimebeamactive=parser.GetDeadTimeBeamActive(LumiRange)
14 try:
15 LastPSCol = PSCols[-1]
16 except:
17 LastPSCol = -1
18 if isCol:
19
20 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 expressRates = {}
29 if isCol:
30 expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
31 else:
32 if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
33 expressRates=parser.GetTriggerRatesByLS("ExpressOutput")
34 else:
35 expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
36 ExpRate=0
37 PeakRate=0
38 AvgExpRate=0
39
40 ARate=0
41 PeakRateA=0
42 AvgRateA=0
43
44 if len(expressRates.values()) > 20:
45 AvgExpRate = sum(expressRates.values())/len(expressRates.values())
46
47 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
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
62 Warn = False
63
64 ##########################################
65 ## Check if the express stream is too high
66 ##########################################
67 global NHighExpress
68 badExpress = ExpRate/len(LumiRange) > config.MaxExpressRate ## avg express stream rate too high?
69 baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
70 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 if len(LumiRange)>1:
80 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
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
91
92
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 textA=colored(baseTextA,'red',attrs=['reverse']) ## bad, make the text white on red
102 NHighStreamA+=1
103 else:
104 textA=baseTextA
105 NHighStreamA=0
106
107 write(textA)
108 if badStreamA:
109 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 write("\n\n")
117
118 ######################################
119 ##Warning for HLT doc
120 ######################################
121 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
127 write( colored(line,'red',attrs=['reverse','blink']) )
128 write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
129
130
131 PrescaleColumnString=''
132 PSCols = list(set(PSCols))
133 for c in PSCols:
134 PrescaleColumnString = PrescaleColumnString + str(c) + ","
135
136 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 if deadtimebeamactive > 5:
145 write(bcolors.FAIL)
146 elif deadtimebeamactive > 10:
147 write(bcolors.WARNING)
148 else:
149 write(bcolors.OKBLUE)
150 write(str(round(deadtimebeamactive,2))+"%")
151 write(bcolors.ENDC+"\n")
152
153 print "Used prescale column(s): "+str(PrescaleColumnString)
154 write("Lumisections: ")
155 if not isSequential(LumiRange):
156 write(str(LumiRange)+" Lumisections are not sequential (bad LS skipped)\n")
157 else:
158 write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
159 print "\nLast Lumisection of the run is: "+str(parser.GetLastLS())
160 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 write("\n\n\n")
163
164 ## 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
174
175
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