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" |
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 not len(sys.argv) == 4: |
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] |
31 |
< |
|
28 |
> |
HLT_Key = args[0] |
29 |
> |
GT_Key = args[1] |
30 |
> |
GTRS_Key = args[2] |
31 |
> |
Verbose = False |
32 |
> |
PSColsToIgnore = [] |
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 |
112 |
|
L1Prescales = GetL1AlgoPrescales(curs,GTRS_Key) |
113 |
|
|
114 |
|
FullPrescales = {} |
115 |
< |
formatString = "%60s%30s%50s%50s%50s" |
116 |
< |
print "List of triggers with non-sequential prescales:" |
117 |
< |
print formatString % ("HLT Name","L1 Name","Total","HLT","L1",) |
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",) |
119 |
|
for HLTName,L1Seeds in HLTSeed.iteritems(): |
120 |
|
if HLTName.startswith('AlCa'): ## the results don't make sense for AlCa paths |
121 |
|
continue |
147 |
|
for hlt,l1 in zip(thisHLTPS,thisL1PS): |
148 |
|
prescales.append(hlt*l1) |
149 |
|
#print HLTName+" HLT: "+str(thisHLTPS)+" L1: "+str(thisL1PS)+" Total: "+str(prescales) |
150 |
< |
if not isSequential(prescales): |
150 |
> |
if not isSequential(prescales,PSColsToIgnore) and doPrint: |
151 |
|
print formatString % (HLTName,L1Seeds,prescales,thisHLTPS,thisL1PS,) |
152 |
|
FullPrescales[HLTName] = prescales |
153 |
+ |
return FullPrescales |
154 |
|
|
155 |
|
def GetHLTPrescaleMatrix(cursor,HLT_Key): |
156 |
|
## Get the config ID |
275 |
|
L1PrescaleTable[index].append(ps) |
276 |
|
return L1PrescaleTable |
277 |
|
|
278 |
< |
def isSequential(row): |
278 |
> |
def isSequential(row,ignore): |
279 |
|
seq = True |
280 |
< |
lastEntry=row[0] |
281 |
< |
for entry in row: |
280 |
> |
lastEntry=999999999999 |
281 |
> |
for i,entry in enumerate(row): |
282 |
> |
if i in ignore: |
283 |
> |
continue |
284 |
|
if entry > lastEntry and lastEntry!=0: |
285 |
|
seq = False |
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() |