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.19 by grchrist, Thu Apr 5 05:03:24 2012 UTC vs.
Revision 1.36 by awoodard, Thu Aug 9 12:03:48 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
12 < NHighStreamA=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)
17 <    deadtimebeamactive=parser.GetDeadTimeBeamActive(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 >    
29 >    try:
30 >        #print "trying v3"
31 >        lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v3")
32 >        #print lograte
33 >        if not len(lograte):
34 >            #print "trying v4"
35 >            lograte=parser.GetTriggerRatesByLS("HLT_LogMonitor_v4")
36 >            
37 >        #print lograte
38 >        for lumi in lograte.iterkeys():
39 >            #print lumi, lograte[lumi]
40 >            if lograte[lumi]>config.MaxLogMonRate:
41 >                write(bcolors.WARNING)
42 >                print lograte[lumi], "post to elog. LogMonitor rate is high."
43 >                write(bcolors.ENDC+"\n")
44 >    except:
45 >        write(bcolors.WARNING)
46 >        print "problem getting log monitor rates"
47 >        write(bcolors.ENDC+"\n")
48 >
49      try:
50          LastPSCol = PSCols[-1]
51      except:
52          LastPSCol = -1
18    if isCol:
19        
20        aRates = parser.GetTriggerRatesByLS("AOutput")
21    else:
22        if len(parser.GetTriggerRatesByLS("AOutput"))>0:
23            aRates = parser.GetTriggerRatesByLS("AOutput")
24        else:
25            aRates = parser.GetTriggerRatesByLS("AForPPOutput")
26            
53      
54      expressRates = {}
55      if isCol:
56          expressRates = parser.GetTriggerRatesByLS("ExpressOutput")
57      else:
58          if len(parser.GetTriggerRatesByLS("ExpressOutput"))>0:
59 <            expressRates=parser.GetTriggerRatesByLS("ExpressOutput")
59 >            expressRates=parser.GetTriggerRatesByLS("else")
60          else:
61              expressRates = parser.GetTriggerRatesByLS("ExpressForCosmicsOutput")
62 +
63      ExpRate=0
64      PeakRate=0
65      AvgExpRate=0
66      
40    ARate=0
41    PeakRateA=0
42    AvgRateA=0
43    
67      if len(expressRates.values()) > 20:
68          AvgExpRate = sum(expressRates.values())/len(expressRates.values())
69 +    counter=0    
70  
71      for ls in LumiRange:  ## Find the sum and peak express stream rates
72          thisR = expressRates.get(ls,0)
# Line 50 | Line 74 | def MoreTableInfo(parser,LumiRange,confi
74          if thisR>PeakRate:
75              PeakRate=thisR
76  
77 <        thisRateA=aRates.get(ls,0)
54 <        ARate+=thisRateA
55 <        if thisRateA>PeakRateA:
56 <            PeakRateA=thisRateA
57 <        
58 <        #ARate+=aRates.get(ls,0)
77 >
78      ## Print Stream A Rate --moved see below
79      ##print "Current Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
80  
81      Warn = False
82  
83      ##########################################
84 <    ## Check if the express stream is too high
84 >    ## Check if the express stream is too high or low
85      ##########################################
86 <    global NHighExpress
68 <    badExpress = ExpRate/len(LumiRange) > config.MaxExpressRate ## avg express stream rate too high?
86 >    badExpress = ((ExpRate/len(LumiRange) > config.MaxExpressRate) or (ExpRate/len(LumiRange)<0.1 and isCol)) ## avg express stream rate too high?
87      baseText = "\nCurrent Express Stream rate is: %0.1f Hz" % (ExpRate/len(LumiRange),) ## text to display
88      if badExpress:
89          text = colored(baseText,'red',attrs=['reverse'])  ## bad, make the text white on red
# Line 76 | Line 94 | def MoreTableInfo(parser,LumiRange,confi
94          
95      write(text)
96      if badExpress:
97 <        if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
98 <            write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
99 <        else:
100 <            if NHighExpress > 1:  # big problem, call HLT DOC
101 <                write(colored("  <<  WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
102 <                Warn = True
97 >        if len(LumiRange)>1:
98 >            if (ExpRate-PeakRate)/(len(LumiRange)-1) <=config.MaxExpressRate: ## one lumisection causes this
99 >                write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
100 >            else:
101 >                if NHighExpress > 1:  # big problem, call HLT DOC
102 >                    write(colored("  <<  WARNING: Current Express rate is too high!",'red',attrs=['reverse']) )
103 >                    Warn = True
104  
105                  #    if AvgExpRate > config.MaxExpressRate:
106                  #        write( colored("\n\nWARNING: Average Express Stream Rate is too high (%0.1f Hz)  << CALL HLT DOC" % AvgExpRate,'red',attrs=['reverse']) )
107                  #        Warn = True
108 <    
108 >        
109 >            
110  
111  
112      #########################################
113      ##Check if Stream A is too high
114      #########################################
115      global NHighStreamA
116 <    badStreamA =ARate/len(LumiRange) > config.MaxStreamARate ##Cosmics Express Rate 300 Hz max
117 <    baseTextA= "\nCurrent Steam A Rate is: %0.1f Hz" % (ARate/len(LumiRange),)
118 <    if badStreamA:
119 <        textA=colored(baseTextA,'red',attrs=['reverse'])  ## bad, make the text white on red
120 <        NHighStreamA+=1
121 <    else:
122 <        textA=baseTextA
123 <        NHighStreamA=0
124 <
125 <    write(textA)
126 <    if badStreamA:
127 <        if (ARate-PeakRateA)/(len(LumiRange)-1) <=config.MaxStreamARate: ## one lumisection causes this
128 <            write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
116 >    stream_mon = StreamMonitor()
117 >    core_a_rates = stream_mon.getStreamACoreRatesByLS(parser,LumiRange,config,isCol).values()
118 >    a_rates = stream_mon.getStreamARatesByLS(parser,LumiRange).values()
119 >    peak_core_a_rate = max(core_a_rates)
120 >
121 >    if len(LumiRange) > 0:
122 >        avg_core_a_rate = sum(core_a_rates)/len(LumiRange)
123 >        avg_a_rate = sum(a_rates)/len(LumiRange)
124 >        badStreamA = stream_mon.compareStreamARate(config, avg_core_a_rate, LumiRange,AvInstLumi,isCol)
125 >
126 >        baseTextA= "\nCurrent Stream A Rate is: %0.1f Hz" % (avg_a_rate)
127 >        baseTextRealA= "\nCurrent PROMPT Stream A Rate is: %0.1f Hz" % (avg_core_a_rate)
128 >
129 >        if badStreamA:
130 >            textA=colored(baseTextA,'red',attrs=['reverse'])  ## bad, make the text white on red
131 >            textRealA=colored(baseTextRealA,'red',attrs=['reverse'])  ## bad, make the text white on red
132 >            NHighStreamA+=1
133          else:
134 <            if NHighStreamA >1: ##Call HLT doc!
135 <                write(colored("  <<  WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
136 <                Warn = True
134 >            textA=baseTextA
135 >            textRealA=baseTextRealA
136 >
137 >        write(textA)
138 >        write(textRealA)
139 >    
140 >        if badStreamA and len(LumiRange) > 1:
141 >            trimmed_core_a_rates = core_a_rates
142 >            trimmed_core_a_rates.remove(peak_core_a_rate)
143 >            if sum(trimmed_core_a_rates)/(len(LumiRange)-1) <= config.MaxStreamARate: ## one lumisection causes this
144 >                write("  <<  This appears to be due to a 1 lumisection spike, please monitor\n")
145 >            else:
146 >                if NHighStreamA > 1: ##Call HLT doc!
147 >                    write(colored("  <<  WARNING: Current Stream A rate is too high!",'red',attrs=['reverse']) )
148 >                    Warn = True
149      write("\n\n")
150              
151      ######################################
# Line 123 | Line 159 | def MoreTableInfo(parser,LumiRange,confi
159  
160          write( colored(line,'red',attrs=['reverse','blink']) )
161          write( colored("*"*cols+"\n",'red',attrs=['reverse','blink']) )
162 <    
162 >        
163      
164      PrescaleColumnString=''
165      PSCols = list(set(PSCols))
# Line 146 | Line 182 | def MoreTableInfo(parser,LumiRange,confi
182              write(bcolors.OKBLUE)
183          write(str(round(deadtimebeamactive,2))+"%")
184          write(bcolors.ENDC+"\n")
185 <
186 <    print "Used prescale column(s): "+str(PrescaleColumnString)    
187 <    write("Lumisections: ")
185 >    write("Used prescale column(s): %s  " % (str(PrescaleColumnString),) )
186 >    if LastPSCol in config.ForbiddenCols and isCol:
187 >        write( colored("<< Using column %d! Please check in the documentation that this is the correct column" % (LastPSCol),'red',attrs=['reverse']) )
188 >    write("\nLumisections: ")
189      if not isSequential(LumiRange):
190          write(str(LumiRange)+"   Lumisections are not sequential (bad LS skipped)\n")
191      else:
192          write("%d - %d\n" % (min(LumiRange),max(LumiRange),))
193 <    print "\nLast Lumisection of the run is:        "+str(parser.GetLastLS())
194 <    write(  "Last Lumisection good where DAQ is active is:  "+str(parser.GetLastLS(isCol)) )
193 >    ##print "\nLast Lumisection of the run is:        "+str(parser.GetLastLS())
194 >    write(  "\nLast Lumisection good where DAQ is active is:  "+str(parser.GetLastLS(isCol)) )
195      ##write(  "Last Lumisection where DAQ is active is:  "+str(parser.GetLastLS(True)) )
196      write("\n\n\n")
197  
198 <    if isCol:
199 <        L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
200 <        if len(L1RatePredictions):
201 <            print "Expected Level 1 Rates:"
202 <        for key,val in L1RatePredictions.iteritems():
203 <            write("Prescale Column "+str(key)+":  "+str(round(val/1000,1))+" kHz")
204 <            if key == LastPSCol:
205 <                write(' << taking data in this column')
206 <            write('\n')
198 >    ## if isCol:
199 > ##         L1RatePredictions = config.GetExpectedL1Rates(AvInstLumi)
200 > ##         if len(L1RatePredictions):
201 > ##             print "Expected Level 1 Rates:"
202 > ##         for key,val in L1RatePredictions.iteritems():
203 > ##             write("Prescale Column "+str(key)+":  "+str(round(val/1000,1))+" kHz")
204 > ##             if key == LastPSCol:
205 > ##                 write(' << taking data in this column')
206 > ##             write('\n')
207          
208      
209  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines