ATLAS Offline Software
trigbs_dumpHLTContentInBS.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 
5 import eformat
6 import argparse
7 import operator
8 from functools import cache
9 
10 __doc__ = """\
11 Dump content of the HLT result and HLT related details from the event header.
12 """
13 
14 
15 parser = argparse.ArgumentParser(description = __doc__)
16 
17 parser.add_argument("files", metavar="FILE", nargs='+',
18  help="RAW file to inspect")
19 
20 parser.add_argument("-n", "--events", metavar="N", action="store", type=int,
21  help="Process N events")
22 
23 parser.add_argument("-s", "--skip", metavar="N", action="store", type=int,
24  help="Skip N events")
25 
26 parser.add_argument("--l1", action="store_true", default=False,
27  help="L1 trigger bits (from event header)")
28 
29 parser.add_argument("--decodeItems", action="store_true", default=False,
30  help="Decode trigger item names")
31 
32 parser.add_argument("--smk", action="store", type=int, default=0,
33  help="Specify SMK for trigger item decoding if not available in HLT result")
34 
35 parser.add_argument("--l2", action="store_true", default=False,
36  help="L2 trigger bits (from event header)")
37 
38 parser.add_argument("--ef", "--hlt", action="store_true", default=False,
39  help="EF/HLT trigger bits (from event header)")
40 
41 parser.add_argument("--ctp", nargs="?", metavar="MID", default=False, const=1,
42  help="CTP ROB details of ROB with module_id MID [default=%(const)s]")
43 
44 parser.add_argument("--stag", action="store_true", default=False,
45  help="stream tag")
46 
47 parser.add_argument("--l2res", action="store_true", default=False,
48  help="details of L2 ROB payload")
49 
50 parser.add_argument("--efres", "--hltres", action="store_true", default=False,
51  help="details of EF/HLT ROB payload")
52 
53 parser.add_argument("--chains", action="store_true", default=False,
54  help="details about chains")
55 
56 parser.add_argument("--features", action="store_true", default=False,
57  help="details about features")
58 
59 parser.add_argument("--tes", action="store_true", default=False,
60  help="details about TriggerElements")
61 
62 parser.add_argument("--conf", action="store_true", default=False,
63  help="configuration keys")
64 
65 parser.add_argument("--sizes", action="store_true", default=False,
66  help="dump info about sizes")
67 
68 parser.add_argument("--stats", action="store_true", default=False,
69  help="dump counts at the end only")
70 
71 parser.add_argument("--sizeSummary", action="store_true", default=False,
72  help="dump info about sizes at the end")
73 
74 parser.add_argument("--interactive", action="store_true", default=False,
75  help="after opening the file enter interactive prompt")
76 
77 
78 
79 args = parser.parse_args()
80 
81 from TrigByteStreamTools.hltResult import hltResult, print_HLTResult, collect_feature_sizes
82 from TrigByteStreamTools import CTPfragment
83 
84 res = hltResult()
85 #if args.interactive:
86 # import code
87 # code.interact(local=locals());
88 
89 
90 featureSizes={}
91 stats = {}
92 smk = None
93 
94 def Lvl1_Info(event):
95  info = event.lvl1_trigger_info()
96  nwords = len(info)/3 # TBP,TAP,TAV
97  return [CTPfragment.decodeTriggerBits(info[i*nwords:(i+1)*nwords]) for i in range(3)]
98 
99 
100 def CTP_Info(event, module_id=1):
101  ctp_robs = [rob for rob in event.children() \
102  if rob.source_id().subdetector_id() == eformat.helper.SubDetector.TDAQ_CTP \
103  and rob.source_id().module_id()==module_id]
104 
105  if len(ctp_robs)==0:
106  print("No CTP ROB found")
107 
108  for rob in ctp_robs:
109  x = CTPfragment.getExtraPayloadObject(rob)
110  folderUpdates = CTPfragment.getFolderUpdates(x)
111  upd = ''.join(['[%d,%d]' % (f.second.folderIndex,f.second.lumiBlock) for f in folderUpdates])
112  print("ROB 0x%0x, L1ID %10d, LB %4d, Version %d, Bunch %d, HLT counter: %3d, Payload #%d %s L1PSK %d BGK %d COOLUPD %s" % (
113  rob.source_id().code(),
114  event.lvl1_id(),
115  event.lumi_block(),
116  CTPfragment.ctpFormatVersion(rob),
117  CTPfragment.lvl1AcceptBunch(rob),
118  CTPfragment.hltCounter(rob),
119  CTPfragment.numberHltExtraPayloadWords(rob),
120  CTPfragment.hltExtraPayloadWords(rob),
121  x.getL1PSK(),
122  x.getBGK(),
123  upd
124  ))
125  for w in ['TBP','TAP','TAV']:
126  items = CTPfragment.decodeTriggerBits(CTPfragment.getTriggerWords(rob,w))
127  print("ROB 0x%0x, %s: %s" % (rob.source_id().code(), w, printL1Items(items,smk)))
128 
129 
130 @cache
131 def getL1Menu(smk):
132  from CoolRunQuery.utils.AtlRunQueryTriggerUtils import getL1Menu
133  return getL1Menu(str(smk))
134 
135 def printL1Items(items,smk):
136  if not args.decodeItems:
137  return items
138 
139  l1menu = getL1Menu(smk)
140  names = [l1menu[i].name for i in items]
141  return names
142 
143 
144 def my_dump(bsfile):
145  """Runs the dumping routines"""
146 
147  global smk
148 
149  # open a file
150  print("="*100)
151  print("Opening", bsfile)
152 
153  input = eformat.istream(bsfile)
154 
155  if args.interactive:
156  import code
157  code.interact(local=locals())
158 
159  event_count = 0
160  l2_event_count = 0
161  ef_event_count = 0
162  offset = args.skip if args.skip else 0
163  for event in input:
164  if offset>0:
165  offset -= 1
166  continue
167 
168  event_count += 1
169 
170  if args.events is not None and event_count>args.events:
171  break
172 
173  print("======================= RunNumber : %d , Event: %d, LB: %d, LVL1_ID: %d, Global_ID: %d bunch-x: %d TT: x%x =========================="
174  % ( event.run_no(), event_count, event.lumi_block(), event.lvl1_id(), event.global_id(), event.bc_id(), event.lvl1_trigger_type()))
175 
176  smk = args.smk
177  if args.decodeItems and args.smk==0: # Need to get SMK from HLT result
178  hltrob = [f for f in event.children() if f.source_id().subdetector_id() in [eformat.helper.SubDetector.TDAQ_LVL2,eformat.helper.SubDetector.TDAQ_EVENT_FILTER] ]
179  if len(hltrob)==0:
180  print("ERROR: Cannot find HLT result. Will not decode trigger item names.")
181  args.decodeItems = False
182  else:
183  res.load(hltrob[0])
184  smk = res.getConfigSuperMasterKey()
185  if smk==0:
186  print("ERROR: No SMK stored in HLT result. Will not decode trigger item names.")
187  args.decodeItems = False
188 
189  if args.l1:
190  #print "L1 TriggerInfo: ", ["0x%x"%i for i in event.lvl1_trigger_info() ]
191  words = Lvl1_Info(event)
192  print("L1 CTP IDs - TBP: ", printL1Items(words[0],smk))
193  print("L1 CTP IDs - TAP: ", printL1Items(words[1],smk))
194  print("L1 CTP IDs - TAV: ", printL1Items(words[2],smk))
195 
196  if args.ctp:
197  CTP_Info(event,int(args.ctp))
198 
199  if args.l2:
200  print("L2 TriggerInfo: ", ["0x%x"%i for i in event.lvl2_trigger_info() ])
201 
202  # loop over the SubDetFragments and find LVL2
203  if args.l2res or args.sizeSummary:
204  found=False
205  for f in event.children():
206  if f.source_id().subdetector_id() == eformat.helper.SubDetector.TDAQ_LVL2:
207  print('.. %s %s %s bytes' % (f.__class__.__name__, f.source_id(), f.fragment_size_word()*4))
208  res.load(f)
209  found=True
210  l2_event_count += 1
211 
212  if args.l2res:
213  print_HLTResult(res, args)
214  if args.sizeSummary:
215  collect_feature_sizes(featureSizes, res)
216  print(".. EOF HLTResult for L2")
217  if not found:
218  print(".. No HLTResult for L2")
219 
220 
221  if args.ef:
222  print("EF TriggerInfo: ", ["0x%x"%i for i in event.event_filter_info()])
223 
224 
225  # loop over the SubDetFragments and find EF
226  if args.efres or args.sizeSummary:
227  found=False
228  for f in event.children():
229  if f.source_id().subdetector_id() == eformat.helper.SubDetector.TDAQ_EVENT_FILTER:
230  print('.. %s %s %s bytes' % (f.__class__.__name__, f.source_id(), f.fragment_size_word()*4))
231  try:
232  res.load(f)
233  found = True
234  ef_event_count += 1
235 
236  if args.efres:
237  print_HLTResult(res, args)
238  if args.sizeSummary:
239  collect_feature_sizes(featureSizes, res)
240  except Exception as ex:
241  print('... **** problems in analyzing payload', ex)
242  print('... **** raw data[:10]', list(f.rod_data())[:10])
243  print(".. EOF HLTResult for EF")
244  if not found:
245  print(".. No HLTResult for EF")
246 
247  if args.stag:
248  print("StreamTag: ", [(s.name, s.type) for s in event.stream_tag()])
249 
250  event_count = max(l2_event_count, ef_event_count)
251  if args.sizeSummary:
252  print('... '+20*'-'+'sizes by type')
253  for f,s in sorted(featureSizes.items(),key=operator.itemgetter(1),reverse=True):
254  if '#' not in f:
255  print(".... %-70s %6d B %6d B/ev" %(f, s, (1.*s)/event_count))
256  print('... '+20*'-'+'sizes by type#key')
257  for f,s in sorted(featureSizes.items(),key=operator.itemgetter(1),reverse=True):
258  if '#' in f:
259  print(".... %-70s %6d B %6d B/ev" %(f, s, (1.*s)/event_count))
260 
261 
262 if __name__ == "__main__":
263  for f in args.files:
264  my_dump(f)
trigbs_dumpHLTContentInBS.int
int
Definition: trigbs_dumpHLTContentInBS.py:32
trigbs_dumpHLTContentInBS.Lvl1_Info
def Lvl1_Info(event)
Definition: trigbs_dumpHLTContentInBS.py:94
max
#define max(a, b)
Definition: cfImp.cxx:41
trigbs_dumpHLTContentInBS.CTP_Info
def CTP_Info(event, module_id=1)
Definition: trigbs_dumpHLTContentInBS.py:100
trigbs_dumpHLTContentInBS.printL1Items
def printL1Items(items, smk)
Definition: trigbs_dumpHLTContentInBS.py:135
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
trigbs_dumpHLTContentInBS.my_dump
def my_dump(bsfile)
Definition: trigbs_dumpHLTContentInBS.py:144
pmontree.code
code
Definition: pmontree.py:443
CTPfragment::getFolderUpdates
std::map< const FolderIndex, FolderEntry > getFolderUpdates(const CTPfragment::ExtraPayload &x)
Definition: TrigByteStreamToolsDict.h:26
python.hltResult.collect_feature_sizes
def collect_feature_sizes(dest, result)
collect the sizes
Definition: hltResult.py:173
python.hltResult.print_HLTResult
def print_HLTResult(result, opt)
Definition: hltResult.py:113
trigbs_dumpHLTContentInBS.getL1Menu
def getL1Menu(smk)
Definition: trigbs_dumpHLTContentInBS.py:131
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
str
Definition: BTagTrackIpAccessor.cxx:11