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.3 by amott, Sat Mar 24 21:24:55 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 = []
20    if len(sys.argv)==5:
21        for c in sys.argv[4].split(','):
22            try:
23                PSColsToIgnore.append(int(c))
24            except:
25                print "ERROR: %s is not a valid prescale column" % c
26    GetPrescaleTable(HLT_Key,GT_Key,GTRS_Key,PSColsToIgnore,True)
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  
# Line 59 | Line 96 | def GetPrescaleTable(HLT_Key,GT_Key,GTRS
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 75 | Line 113 | def GetPrescaleTable(HLT_Key,GT_Key,GTRS
113      L1Prescales = GetL1AlgoPrescales(curs,GTRS_Key)
114  
115      FullPrescales = {}
116 <    formatString = "%60s%30s%50s%50s%50s"
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",)
# Line 86 | Line 124 | def GetPrescaleTable(HLT_Key,GT_Key,GTRS
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 249 | 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