ATLAS Offline Software
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__ = """\
6 Dumping HLT chains PS bit vs the chain counter and vs the L1 event number
7 """
8 
9 import eformat
10 import cPickle
11 import optparse
12 import cppyy
13 from TrigByteStreamTools.hltResult import hltResult
14 
15 optparser = optparse.OptionParser(usage = "%prog [options] FILES",
16  description = __doc__)
17 
18 optparser.add_option("", "--pickle", default='l2bits.pickle',
19  help="output file for the result pickle")
20 
21 optparser.add_option("", "--comp", action="store_true", default=False,
22  help="Run comparison")
23 
24 optparser.add_option("", "--one", default='',
25  help="1st file for the comparison")
26 
27 optparser.add_option("", "--two", default='',
28  help="2nd file for the comparison")
29 
30 optparser.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 
37 res = hltResult()
38 
39 featureSizes={}
40 stats = {}
41 HLTChain = cppyy.makeClass('HLT::Chain')
42 
43 def 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 
77 def 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 
109 if __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 
trigbs_dumpPrescaleBits.my_comp
def my_comp(f1, f2)
Definition: trigbs_dumpPrescaleBits.py:77
trigbs_dumpPrescaleBits.HLTChain
HLTChain
Definition: trigbs_dumpPrescaleBits.py:41
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
trigbs_dumpPrescaleBits.my_dump
def my_dump(bsfile)
Definition: trigbs_dumpPrescaleBits.py:43
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
Trk::open
@ open
Definition: BinningType.h:40
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70