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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines