ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.24
Committed: Fri Apr 6 15:32:24 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.23: +2 -1 lines
Log Message:
psi is None bug and new monitor list with new fits

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