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.14 by amott, Thu Mar 15 14:50:54 2012 UTC vs.
Revision 1.34 by grchrist, Mon Jul 16 10:02:38 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines