ATLAS Offline Software
Loading...
Searching...
No Matches
trigbs_dumpPrescaleBits.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5__doc__ = """\
6Dumping HLT chains PS bit vs the chain counter and vs the L1 event number
7"""
8
9import eformat
10import cPickle
11import optparse
12import cppyy
13from TrigByteStreamTools.hltResult import hltResult
14
15optparser = optparse.OptionParser(usage = "%prog [options] FILES",
16 description = __doc__)
17
18optparser.add_option("", "--pickle", default='l2bits.pickle',
19 help="output file for the result pickle")
20
21optparser.add_option("", "--comp", action="store_true", default=False,
22 help="Run comparison")
23
24optparser.add_option("", "--one", default='',
25 help="1st file for the comparison")
26
27optparser.add_option("", "--two", default='',
28 help="2nd file for the comparison")
29
30optparser.add_option("", "--ef", action="store_true", default=False,
31 help="Use EF result instead of L2")
32
33(opt, args) = optparser.parse_args()
34
35
36
37res = hltResult()
38
39featureSizes={}
40stats = {}
41HLTChain = cppyy.makeClass('HLT::Chain')
42
43def my_dump(bsfile):
44 """Runs the dumping routines"""
45
46 # open a file
47 print("="*100)
48 print("Opening %s" % bsfile)
49
50
51 events = {}
52
53 input = eformat.istream(bsfile)
54 subdet = eformat.helper.SubDetector.TDAQ_EVENT_FILTER if opt.ef else eformat.helper.SubDetector.TDAQ_LVL2
55
56 for event in input:
57 ev = ( event.global_id(), event.lvl1_id() )
58
59 chains = {}
60 for f in event.children():
61 if f.source_id().subdetector_id() == subdet:
62 res.load(f)
63 chains_data = list(res.getChainResult())
64 #nchains = chains_data[0]
65 for c in chains_data[1:]:
66 chain = HLTChain(c)
67 chains[chain.getChainCounter()] = chain.isPrescaled()
68 break
69
70 events[ev] = chains
71
72 output = open(opt.pickle, "wb")
73 cPickle.dump(events, output)
74 output.close()
75
76
77def my_comp(f1, f2):
78 import pprint
79
80 one = cPickle.load(open(f1, "rb"))
81 two = cPickle.load(open(f2, "rb"))
82 print('.. eventdumps read in correctly %s %s' % (f1, f2))
83
84 if one == two:
85 print(".. the prescale bits are the same")
86 else:
87 diff=False
88 kone = set(one.keys())
89 ktwo = set(two.keys())
90 if kone != ktwo:
91 print(".... the event sets are different in the two files; one has: %d two has: %d events" % (len(kone), len(ktwo)))
92 print(".... will compare only events present in both sets")
93 komon = kone & ktwo
94 for k in komon:
95 if one[k] != two[k]:
96 print(".. event difference global_id: %d l1_id: %d, fmt: chain_counter: PS bit,... " % k)
97 print(".. event in file: %s " % opt.one)
98 pprint.pprint(one[k])
99 print(".. event in file: %s" % opt.two)
100 pprint.pprint(two[k])
101 diff=True
102 if not diff:
103 print('.. prescale bits are the same in all %d common events ' % len(komon))
104 else:
105 print('.. there are differences !')
106
107
108
109if __name__ == "__main__":
110 if not opt.comp:
111 for f in args:
112 my_dump(f)
113 else:
114 my_comp(opt.one, opt.two)
115
void print(char *figname, TCanvas *c1)
STL class.