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.15 by grchrist, Mon Mar 19 16:13:02 2012 UTC vs.
Revision 1.39 by amott, Mon Sep 17 15:16:09 2012 UTC

# Line 2 | Line 2 | 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 < NHighExpress=0
11 > NHighStreamA = 0
12 > NHighExpress = 0
13  
14   def MoreTableInfo(parser,LumiRange,config,isCol=True):
15      print "Monitoring Run %d" % (parser.RunNumber,)
16 <    [AvInstLumi, AvLiveLumi, AvDeliveredLumi, AvDeadTime,PSCols] = parser.GetAvLumiInfo(LumiRange)
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      try:
58          LastPSCol = PSCols[-1]
59      except:
60          LastPSCol = -1
61 <        
17 <    aRates = parser.GetTriggerRatesByLS("AOutput")
61 >    
62      expressRates = {}
63      if isCol:
64          expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
65      else:
66 <        expressRates = parser.GetTriggerRatesByLS("ExpressCosmicsOutput")
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      
27    ARate=0
28    PeakRateA=0
29    AvgRateA=0
30    
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)
# Line 37 | Line 82 | def MoreTableInfo(parser,LumiRange,confi
82          if thisR>PeakRate:
83              PeakRate=thisR
84  
85 <        thisRateA=aRates.get(ls,0)
41 <        ARate+=thisRateA
42 <        if thisRateA>PeakRateA:
43 <            PeakRateA=thisRateA
44 <        
45 <        #ARate+=aRates.get(ls,0)
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
92 >    ## Check if the express stream is too high or low
93      ##########################################
94 <    global NHighExpress
95 <    badExpress = ExpRate/len(LumiRange) > config.MaxExpressRate ## avg express stream rate too high?
56 <    baseText = "Current Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
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
# Line 63 | Line 102 | def MoreTableInfo(parser,LumiRange,confi
102          
103      write(text)
104      if badExpress:
105 <        if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
106 <            write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
107 <        else:
108 <            if NHighExpress > 1:  # big problem, call HLT DOC
109 <                write(colored("  <<  WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
110 <                Warn = True
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 <    
116 >        
117 >            
118  
119  
120      #########################################
121      ##Check if Stream A is too high
122      #########################################
123      global NHighStreamA
124 <    badStreamA =ARate/len(LumiRange) > config.MaxStreamARate ##Cosmics Express Rate 300 Hz max
125 <    baseTextA= "\nCurrent Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
126 <    if badStreamA:
127 <        textA=colored(baseText,'red',attrs=['reverse'])  ## bad, make the text white on red
128 <        NHighStreamA+=1
129 <    else:
130 <        textA=baseTextA
131 <        NHighStreamA=0
132 <
133 <    write(textA)
134 <    if badStreamA:
135 <        if (ARate-PeakRateA)/(len(LumiRange)-1) <=config.MaxStreamARate: ## one lumisection causes this
136 <            write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
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 <            if NHighStreamA >1: ##Call HLT doc!
143 <                write(colored("  <<  WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
144 <                Warn = True
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      ######################################
# Line 110 | Line 167 | def MoreTableInfo(parser,LumiRange,confi
167  
168          write( colored(line,'red',attrs=['reverse','blink']) )
169          write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
170 +        
171      
114    if AvDeadTime==0:  ## For some reason the dead time in the DB is occasionally broken
115        try:
116            AvDeadTime = AvLiveLumi/AvDeliveredLumi * 100
117        except:
118            AvDeadTime = 100
172      PrescaleColumnString=''
173      PSCols = list(set(PSCols))
174      for c in PSCols:
# Line 129 | Line 182 | def MoreTableInfo(parser,LumiRange,confi
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 AvDeadTime > 5:
185 >        if deadtimebeamactive > 5:
186              write(bcolors.FAIL)
187 <        elif AvDeadTime > 10:
187 >        elif deadtimebeamactive > 10:
188              write(bcolors.WARNING)
189          else:
190              write(bcolors.OKBLUE)
191 <        write(str(round(AvDeadTime,2))+"%")
191 >        write(str(round(deadtimebeamactive,2))+"%")
192          write(bcolors.ENDC+"\n")
193 <
194 <    print "Used prescale column(s): "+str(PrescaleColumnString)    
195 <    write("Lumisections: ")
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)) )
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')
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines