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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines