ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
Revision: 1.17
Committed: Mon Mar 26 15:50:19 2012 UTC (13 years, 1 month ago) by grchrist
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-24, V00-00-23, V00-00-22, V00-00-21
Changes since 1.16: +5 -8 lines
Log Message:
changed the fit ref file, and now RMonitoring is with deadtimebeamactive from db

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    
19     aRates = parser.GetTriggerRatesByLS("AOutput")
20     expressRates = {}
21     if isCol:
22     expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
23     else:
24     expressRates = parser.GetTriggerRatesByLS("ExpressCosmicsOutput")
25 amott 1.12 ExpRate=0
26     PeakRate=0
27 amott 1.13 AvgExpRate=0
28 grchrist 1.15
29 amott 1.13 ARate=0
30 grchrist 1.15 PeakRateA=0
31     AvgRateA=0
32    
33 amott 1.13 if len(expressRates.values()) > 20:
34     AvgExpRate = sum(expressRates.values())/len(expressRates.values())
35    
36 amott 1.12 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 grchrist 1.15
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 amott 1.12
51 amott 1.13 Warn = False
52 amott 1.12
53 grchrist 1.15 ##########################################
54 amott 1.12 ## Check if the express stream is too high
55 grchrist 1.15 ##########################################
56 amott 1.12 global NHighExpress
57     badExpress = ExpRate/len(LumiRange) > config.MaxExpressRate ## avg express stream rate too high?
58 grchrist 1.16 baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
59 amott 1.12 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 amott 1.13 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 grchrist 1.15
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 grchrist 1.16 textA=colored(baseTextA,'red',attrs=['reverse']) ## bad, make the text white on red
89 grchrist 1.15 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 grchrist 1.16 write(colored(" << WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
101 grchrist 1.15 Warn = True
102 amott 1.13 write("\n\n")
103 grchrist 1.15
104     ######################################
105     ##Warning for HLT doc
106     ######################################
107 amott 1.13 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 amott 1.12
113 amott 1.13 write( colored(line,'red',attrs=['reverse','blink']) )
114     write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
115 amott 1.12
116 grchrist 1.17
117 amott 1.1 PrescaleColumnString=''
118 abrinke1 1.10 PSCols = list(set(PSCols))
119 amott 1.1 for c in PSCols:
120     PrescaleColumnString = PrescaleColumnString + str(c) + ","
121    
122 amott 1.13 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 grchrist 1.17 if deadtimebeamactive > 5:
131 amott 1.13 write(bcolors.FAIL)
132 grchrist 1.17 elif deadtimebeamactive > 10:
133 amott 1.13 write(bcolors.WARNING)
134     else:
135     write(bcolors.OKBLUE)
136 grchrist 1.17 write(str(round(deadtimebeamactive,2))+"%")
137 amott 1.13 write(bcolors.ENDC+"\n")
138 amott 1.1
139 amott 1.3 print "Used prescale column(s): "+str(PrescaleColumnString)
140 amott 1.4 write("Lumisections: ")
141 amott 1.3 if not isSequential(LumiRange):
142 amott 1.4 write(str(LumiRange)+" Lumisections are not sequential (bad LS skipped)\n")
143     else:
144     write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
145 amott 1.3 print "\nLast Lumisection of the run is: "+str(parser.GetLastLS())
146     write( "Last Lumisection good for physics is: "+str(parser.GetLastLS(True)) )
147 amott 1.12 write("\n\n\n")
148 amott 1.5
149 amott 1.13 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 amott 1.6
159 amott 1.5
160 amott 1.3
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