ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/AddTableInfo_db.py
(Generate patch)

Comparing UserCode/RateMonShiftTool_dev/AddTableInfo_db.py (file contents):
Revision 1.4 by amott, Wed Feb 15 12:16:37 2012 UTC vs.
Revision 1.43 by awoodard, Tue Dec 4 17:25:17 2012 UTC

# Line 1 | Line 1
1   import sys
2   from colors import *
3   from DatabaseParser import *
4 + from termcolor import colored, cprint
5 + from StreamMonitor import *
6 + import time
7 +
8 +
9   write = sys.stdout.write
10  
11 < def MoreTableInfo(parser,LumiRange):
12 <    [AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
11 > NHighStreamA = 0
12 > NHighExpress = 0
13  
14 <    if AvDeadTime==0:  ## For some reason the dead time in the DB is occasionally broken
15 <        try:
16 <            AvDeadTime = AvLiveLumi/AvDeliveredLumi * 100
17 <        except:
18 <            AvDeadTime = 100
19 <    PrescaleColumnString=''
20 <    for c in PSCols:
21 <        PrescaleColumnString = PrescaleColumnString + str(c) + ","
14 > def MoreTableInfo(parser,LumiRange,config,isCol=True):
15 >    global NHighStreamA
16 >    global NHighExpress
17 >    print "Monitoring Run %d" % (parser.RunNumber,)
18 >    localtime = time.asctime( time.localtime(time.time()) )
19 >    print "Local current time :", localtime
20 >    #print "Lumisections used=", LumiRange
21 >    if len(LumiRange)>0:
22 >        
23 >        [AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
24 >        deadtimebeamactive=parser.GetDeadTimeBeamActive(LumiRange)*100
25 >        
26 >        ##print "dtba=",deadtimebeamactive
27 >    else:
28 >        print "no lumisections to monitor"
29 >        return
30 >  ## check if lumi is being filled
31 >    if parser.LastLSParsed > 4 and isCol:
32 >        if set(parser.InstLumiByLS.values()) == set([None]):
33 >            write(colored("\n\nLUMI INFORMATION NOT BEING SENT!\n",'red',attrs=['reverse']))
34 >            write(colored("Check with Shift Leader if this is expected\n",'red',attrs=['reverse']))
35 >            write(colored("If not, HFLUMI needs to be red-recycled\n\n\n",'red',attrs=['reverse']))
36 >            write(colored("If in doubt, call Lumi DOC\n\n\n",'red',attrs=['reverse']))
37 >                                                                                                                                                                                                                                                                    
38 >    try:
39 >        lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v3")
40 >        if not len(lograte):
41 >            lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v4")
42 >
43 >        for ls in LumiRange:
44 >            current_lograte = lograte.get(ls,0)
45 >            lograte_sum =+ current_lograte
46  
47 <    write("The average instantaneous lumi of these lumisections is: ")
48 <    write(str(round(AvInstLumi,1))+"e30\n")
49 <    write("The delivered lumi of these lumi sections is:            ")
50 <    write(str(round(1000*AvDeliveredLumi,1))+"e30"+"\n")
51 <    write("The live (recorded) lumi of these lumi sections is:      ")
52 <    write(str(round(1000*AvLiveLumi,1))+"e30\n\n")
53 <    write("The average deadtime of these lumi sections is:          ")
25 <    if AvDeadTime > 5:
26 <        write(bcolors.FAIL)
27 <    elif AvDeadTime > 10:
47 >        lograte_average = lograte_sum/len(LumiRange)
48 >        if lograte_average > config.MaxLogMonRate:
49 >            write(bcolors.WARNING)
50 >            print "Post to elog. LogMonitor rate is high: %.2f" % (lograte_average)
51 >            write(bcolors.ENDC+"\n")              
52 >
53 >    except:
54          write(bcolors.WARNING)
55 +        print "problem getting log monitor rates"
56 +        write(bcolors.ENDC+"\n")
57 +
58 +    try:
59 +        LastPSCol = PSCols[-1]
60 +    except:
61 +        LastPSCol = -1
62 +    
63 +    expressRates = {}
64 +    if isCol:
65 +        expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
66      else:
67 <        write(bcolors.OKBLUE)
68 <    write(str(round(AvDeadTime,1))+"%")
69 <    write(bcolors.ENDC+"\n")
67 >        if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
68 >            expressRates=parser.GetTriggerRatesByLS("ExpressOutput")
69 >        else:
70 >            expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
71 >
72 >    ExpRate=0
73 >    PeakRate=0
74 >    AvgExpRate=0
75 >    
76 >    if len(expressRates.values()) > 20:
77 >        AvgExpRate = sum(expressRates.values())/len(expressRates.values())
78 >    counter=0    
79 >
80 >    for ls in LumiRange:  ## Find the sum and peak express stream rates
81 >        thisR = expressRates.get(ls,0)
82 >        ExpRate+=thisR
83 >        if thisR>PeakRate:
84 >            PeakRate=thisR
85 >
86 >
87 >    ## Print Stream A Rate --moved see below
88 >    ##print "Current Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
89 >
90 >    Warn = False
91  
92 <    print "Used prescale column(s): "+str(PrescaleColumnString)    
93 <    write("Lumisections: ")
92 >    ##########################################
93 >    ## Check if the express stream is too high or low
94 >    ##########################################
95 >    badExpress = ((ExpRate/len(LumiRange) > config.MaxExpressRate) or (ExpRate/len(LumiRange)<0.1 and isCol)) ## avg express stream rate too high?
96 >    baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
97 >    if badExpress:
98 >        text = colored(baseText,'red',attrs=['reverse'])  ## bad, make the text white on red
99 >        NHighExpress+=1  ## increment the bad express counter
100 >    else:
101 >        text = baseText
102 >        NHighExpress=0
103 >        
104 >    write(text)
105 >    if badExpress:
106 >        if len(LumiRange)>1:
107 >            if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
108 >                write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
109 >            else:
110 >                if NHighExpress > 1:  # big problem, call HLT DOC
111 >                    write(colored("  <<  WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
112 >                    Warn = True
113 >
114 >                #    if AvgExpRate > config.MaxExpressRate:
115 >                #        write( colored("\n\nWARNING: Average Express Stream Rate is too high (%0.1f Hz)  << CALL HLT DOC" % AvgExpRate,'red',attrs=['reverse']) )
116 >                #        Warn = True
117 >        
118 >            
119 >
120 >
121 >    #########################################
122 >    ##Check if Stream A is too high
123 >    #########################################
124 >    global NHighStreamA
125 >    stream_mon = StreamMonitor()
126 >    core_a_rates = stream_mon.getStreamACoreRatesByLS(parser,LumiRange,config,isCol).values()
127 >    a_rates = stream_mon.getStreamARatesByLS(parser,LumiRange).values()
128 >    peak_core_a_rate = max(core_a_rates)
129 >
130 >    if len(LumiRange) > 0:
131 >        avg_core_a_rate = sum(core_a_rates)/len(LumiRange)
132 >        avg_a_rate = sum(a_rates)/len(LumiRange)
133 >        badStreamA = stream_mon.compareStreamARate(config, avg_core_a_rate, LumiRange,AvInstLumi,isCol)
134 >
135 >        baseTextA= "\nCurrent Stream A Rate is: %0.1f Hz" % (avg_a_rate)
136 >        baseTextRealA= "\nCurrent PROMPT Stream A Rate is: %0.1f Hz" % (avg_core_a_rate)
137 >
138 >        if badStreamA:
139 >            textA=colored(baseTextA,'red',attrs=['reverse'])  ## bad, make the text white on red
140 >            textRealA=colored(baseTextRealA,'red',attrs=['reverse'])  ## bad, make the text white on red
141 >            NHighStreamA+=1
142 >        else:
143 >            textA=baseTextA
144 >            textRealA=baseTextRealA
145 >
146 >        write(textA)
147 >        write(textRealA)
148 >    
149 >        if badStreamA and len(LumiRange) > 1:
150 >            trimmed_core_a_rates = core_a_rates
151 >            trimmed_core_a_rates.remove(peak_core_a_rate)
152 >            if sum(trimmed_core_a_rates)/(len(LumiRange)-1) <= config.MaxStreamARate: ## one lumisection causes this
153 >                write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
154 >            else:
155 >                if NHighStreamA > 1: ##Call HLT doc!
156 >                    write(colored("  <<  WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
157 >                    Warn = True
158 >    write("\n\n")
159 >            
160 >    ######################################
161 >    ##Warning for HLT doc
162 >    ######################################
163 >    if Warn:  ## WARNING
164 >        rows, columns = os.popen('stty size', 'r').read().split()  ## Get the terminal size
165 >        cols = int(columns)
166 >        write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
167 >        line = "*" + " "*int((cols-22)/2)+"CALL HLT DOC (165575)"+" "*int((cols-23)/2)+"*\n"
168 >
169 >        write( colored(line,'red',attrs=['reverse','blink']) )
170 >        write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
171 >        
172 >    
173 >    PrescaleColumnString=''
174 >    PSCols = list(set(PSCols))
175 >    for c in PSCols:
176 >        PrescaleColumnString = PrescaleColumnString + str(c) + ","
177 >
178 >    if isCol:
179 >        write("The average instantaneous lumi of these lumisections is: ")
180 >        write(str(round(AvInstLumi,1))+"e30\n")
181 >        write("The delivered lumi of these lumi sections is:            ")
182 >        write(str(round(len(LumiRange)*AvDeliveredLumi,1))+"e30"+"\n")
183 >        write("The live (recorded) lumi of these lumi sections is:      ")
184 >        write(str(round(len(LumiRange)*AvLiveLumi,1))+"e30\n\n")
185 >        write("The average deadtime of these lumi sections is:          ")
186 >        if deadtimebeamactive > 5:
187 >            write(bcolors.FAIL)
188 >        elif deadtimebeamactive > 10:
189 >            write(bcolors.WARNING)
190 >        else:
191 >            write(bcolors.OKBLUE)
192 >        write(str(round(deadtimebeamactive,2))+"%")
193 >        write(bcolors.ENDC+"\n")
194 >    write("Used prescale column(s): %s  " % (str(PrescaleColumnString),) )
195 >    if LastPSCol in config.ForbiddenCols and isCol:
196 >        write( colored("<< Using column %d! Please check in the documentation that this is the correct column" % (LastPSCol),'red',attrs=['reverse']) )
197 >    write("\nLumisections: ")
198      if not isSequential(LumiRange):
199          write(str(LumiRange)+"   Lumisections are not sequential (bad LS skipped)\n")
200      else:
201          write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
202 <    print "\nLast Lumisection of the run is:        "+str(parser.GetLastLS())
203 <    write(  "Last Lumisection good for physics is:  "+str(parser.GetLastLS(True)) )
204 <    if parser.GetLastLS(True)!=max(LumiRange):
205 <        write(bcolors.WARNING)
206 <        write("  << This exceeds the last lumisection parsed")
207 <    write(bcolors.ENDC+"\n")
202 >    ##print "\nLast Lumisection of the run is:        "+str(parser.GetLastLS())
203 >    write(  "\nLast Lumisection good where DAQ is active is:  "+str(parser.GetLastLS(isCol)) )
204 >    ##write(  "Last Lumisection where DAQ is active is:  "+str(parser.GetLastLS(True)) )
205 >    write("\n\n\n")
206 >
207 >    ## if isCol:
208 > ##         L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
209 > ##         if len(L1RatePredictions):
210 > ##             print "Expected Level 1 Rates:"
211 > ##         for key,val in L1RatePredictions.iteritems():
212 > ##             write("Prescale Column "+str(key)+":  "+str(round(val/1000,1))+" kHz")
213 > ##             if key == LastPSCol:
214 > ##                 write(' << taking data in this column')
215 > ##             write('\n')
216 >        
217 >    
218  
219   def isSequential(t):
220      try:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines