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.4 by amott, Mon Mar 26 09:40:56 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 75 | Line 112 | def GetPrescaleTable(HLT_Key,GT_Key,GTRS
112      L1Prescales = GetL1AlgoPrescales(curs,GTRS_Key)
113  
114      FullPrescales = {}
115 <    formatString = "%60s%30s%50s%50s%50s"
115 >    formatString = "%55s%30s%45s%45s%45s"
116      if doPrint:
117          print "List of triggers with non-sequential prescales:"
118          print formatString % ("HLT Name","L1 Name","Total","HLT","L1",)
# Line 249 | Line 286 | def isSequential(row,ignore):
286              break
287          lastEntry = entry
288      return seq
289 <    
289 >
290 >
291 > def firstPrescaled(row,ignore):
292 >    row.reverse()
293 >    for i,val in enumerate(row):
294 >        if len(row)-1-i in ignore:
295 >            continue
296 >        if val!=1: # prescaled
297 >            return len(row)-1-i
298 >    return -1
299 >
300   if __name__=='__main__':
301      main()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines