ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.16
Committed: Mon Mar 19 16:43:03 2012 UTC (13 years, 1 month ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-20, V00-00-19, V00-00-18, V00-00-17, V00-00-16, V00-00-15
Changes since 1.15: +4 -3 lines
Log Message:
debug stream A warning

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