ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.18
Committed: Mon Apr 2 18:03:12 2012 UTC (13 years ago) by grchrist
Content type: text/x-python
Branch: MAIN
Changes since 1.17: +2 -2 lines
Log Message:
changed the names of stream A and Express cosmics to reflect current menus

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