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