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" |
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 not len(sys.argv) == 4: |
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] |
32 |
< |
|
29 |
> |
HLT_Key = args[0] |
30 |
> |
GT_Key = args[1] |
31 |
> |
GTRS_Key = args[2] |
32 |
> |
Verbose = False |
33 |
> |
PSColsToIgnore = [] |
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 |
|
|
69 |
|
## Get the HLT seeds |
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" |
118 |
< |
print "List of triggers with non-sequential prescales:" |
119 |
< |
print formatString % ("HLT Name","L1 Name","Total","HLT","L1",) |
117 |
> |
formatString = "%-60s%-40s%90s%80s%80s" |
118 |
> |
if doPrint: |
119 |
> |
print "List of triggers with non-sequential prescales:" |
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: |
150 |
|
for hlt,l1 in zip(thisHLTPS,thisL1PS): |
151 |
|
prescales.append(hlt*l1) |
152 |
|
#print HLTName+" HLT: "+str(thisHLTPS)+" L1: "+str(thisL1PS)+" Total: "+str(prescales) |
153 |
< |
if not isSequential(prescales): |
153 |
> |
if not isSequential(prescales,PSColsToIgnore) and doPrint: |
154 |
|
print formatString % (HLTName,L1Seeds,prescales,thisHLTPS,thisL1PS,) |
155 |
|
FullPrescales[HLTName] = prescales |
156 |
+ |
return FullPrescales |
157 |
|
|
158 |
|
def GetHLTPrescaleMatrix(cursor,HLT_Key): |
159 |
|
## Get the config ID |
278 |
|
L1PrescaleTable[index].append(ps) |
279 |
|
return L1PrescaleTable |
280 |
|
|
281 |
< |
def isSequential(row): |
281 |
> |
def isSequential(row,ignore): |
282 |
|
seq = True |
283 |
< |
lastEntry=row[0] |
284 |
< |
for entry in row: |
283 |
> |
lastEntry=999999999999 |
284 |
> |
for i,entry in enumerate(row): |
285 |
> |
if i in ignore: |
286 |
> |
continue |
287 |
|
if entry > lastEntry and lastEntry!=0: |
288 |
|
seq = False |
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() |