ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/CheckPrescales.py
(Generate patch)

Comparing UserCode/RateMonShiftTool_dev/CheckPrescales.py (file contents):
Revision 1.2 by amott, Thu Mar 22 18:02:11 2012 UTC vs.
Revision 1.5 by amott, Fri Apr 6 15:09:18 2012 UTC

# Line 2 | Line 2
2  
3   import sys
4   import os
5 + import getopt
6 +
7   from DatabaseParser import ConnectDB
8  
9   def usage():
10 <    print sys.argv[0] + " HLTKey GTKey GTRS Key [PSColsToIgnore]"
10 >    print sys.argv[0] + " [options] HLTKey GTKey GTRS Key"
11 >    print "options:"
12 >    print "-v                 Verbose Mode"
13 >    print "--ignore=<cols>    list (comma-separated) of prescale columns to ignore"
14  
15   def main():
16 +    try:
17 +        opt, args = getopt.getopt(sys.argv[1:],"v",["ignore="])
18 +        
19 +    except getopt.GetoptError, err:
20 +        print str(err)
21 +        usage()
22 +        sys.exit(2)
23  
24 <    if len(sys.argv) < 4 or len(sys.argv)>5:
24 >    if len(args)!=3:
25          usage()
26          sys.exit(0)
27  
28 <    HLT_Key  = sys.argv[1]
29 <    GT_Key   = sys.argv[2]
30 <    GTRS_Key = sys.argv[3]
28 >    HLT_Key  = args[0]
29 >    GT_Key   = args[1]
30 >    GTRS_Key = args[2]
31 >    Verbose = False
32      PSColsToIgnore = []
33 <    if len(sys.argv)==5:
34 <        for c in sys.argv[4].split(','):
35 <            try:
36 <                PSColsToIgnore.append(int(c))
37 <            except:
38 <                print "ERROR: %s is not a valid prescale column" % c
39 <    
33 >
34 >    for o,a in opt:
35 >        if o=="-v":
36 >            Verbose = True
37 >        elif o=="--ignore":            
38 >            for c in a.split(','):
39 >                try:
40 >                    PSColsToIgnore.append(int(c))
41 >                except:
42 >                    print "\nERROR: %s is not a valid prescale column\n" % c
43 >                    usage()
44 >                    sys.exit(0)
45 >    psTable = GetPrescaleTable(HLT_Key,GT_Key,GTRS_Key,PSColsToIgnore,True)
46 >
47 >    if Verbose:
48 >        firstPS = {}
49 >        for trigger,prescales in psTable.iteritems():
50 >            firstPed = firstPrescaled(prescales,PSColsToIgnore)
51 >            if not firstPS.has_key(firstPed):
52 >                firstPS[firstPed] = []
53 >            firstPS[firstPed].append(trigger)
54 >
55 >          
56 >        for col,triggers in firstPS.iteritems():
57 >            if col == -1:
58 >                print "The following triggers are never prescaled:"
59 >            else:
60 >                print "The following triggers are first prescaled in col %d" % (col,)
61 >            for trig in triggers: print "\t%s" % (trig,)
62 >              
63 >            
64 >            
65 > def GetPrescaleTable(HLT_Key,GT_Key,GTRS_Key,PSColsToIgnore,doPrint):
66      curs = ConnectDB('hlt')
67  
68      ## Get the HLT seeds
# Line 57 | Line 96 | def main():
96      HLTSeed = {}
97      for HLTPath,L1Seed in curs.fetchall():
98          if not HLTSeed.has_key(HLTPath): ## this should protect us from L1_SingleMuOpen
99 <            HLTSeed[HLTPath] = L1Seed.lstrip('"').rstrip('"')
99 >            tmp = L1Seed.lstrip('"').rstrip('"')
100 >            HLTSeed[HLTPath] = tmp.rstrip(' ')
101              
102      HLTPrescales = GetHLTPrescaleMatrix(curs,HLT_Key)
103  
# Line 73 | Line 113 | def main():
113      L1Prescales = GetL1AlgoPrescales(curs,GTRS_Key)
114  
115      FullPrescales = {}
116 <    formatString = "%60s%30s%50s%50s%50s"
117 <    print "List of triggers with non-sequential prescales:"
118 <    print formatString % ("HLT Name","L1 Name","Total","HLT","L1",)
116 >    formatString = "%55s%30s%45s%45s%45s"
117 >    if doPrint:
118 >        print "List of triggers with non-sequential prescales:"
119 >        print formatString % ("HLT Name","L1 Name","Total","HLT","L1",)
120      for HLTName,L1Seeds in HLTSeed.iteritems():
121          if HLTName.startswith('AlCa'): ## the results don't make sense for AlCa paths
122              continue
# Line 83 | Line 124 | def main():
124              continue
125          thisL1PS = []
126          for seed in L1Seeds.split(' OR '): ## unwind the OR of multiple seeds
127 +            seed = seed.lstrip(' ').rstrip(' ')
128              if seed.isdigit():
129                  continue
130              if not L1Names.has_key(seed):
# Line 107 | Line 149 | def main():
149          for hlt,l1 in zip(thisHLTPS,thisL1PS):
150              prescales.append(hlt*l1)
151          #print HLTName+" HLT: "+str(thisHLTPS)+" L1: "+str(thisL1PS)+" Total: "+str(prescales)
152 <        if not isSequential(prescales,PSColsToIgnore):
152 >        if not isSequential(prescales,PSColsToIgnore) and doPrint:
153              print formatString % (HLTName,L1Seeds,prescales,thisHLTPS,thisL1PS,)
154          FullPrescales[HLTName] = prescales
155 +    return FullPrescales
156              
157   def GetHLTPrescaleMatrix(cursor,HLT_Key):
158      ## Get the config ID
# Line 245 | Line 288 | def isSequential(row,ignore):
288              break
289          lastEntry = entry
290      return seq
291 <    
291 >
292 >
293 > def firstPrescaled(row,ignore):
294 >    row.reverse()
295 >    for i,val in enumerate(row):
296 >        if len(row)-1-i in ignore:
297 >            continue
298 >        if val!=1: # prescaled
299 >            return len(row)-1-i
300 >    return -1
301 >
302   if __name__=='__main__':
303      main()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines