ATLAS Offline Software
Loading...
Searching...
No Matches
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
5import eformat
6import argparse
7import operator
8from functools import cache
9
10__doc__ = """\
11Dump content of the HLT result and HLT related details from the event header.
12"""
13
14
15parser = argparse.ArgumentParser(description = __doc__)
16
17parser.add_argument("files", metavar="FILE", nargs='+',
18 help="RAW file to inspect")
19
20parser.add_argument("-n", "--events", metavar="N", action="store", type=int,
21 help="Process N events")
22
23parser.add_argument("-s", "--skip", metavar="N", action="store", type=int,
24 help="Skip N events")
25
26parser.add_argument("--l1", action="store_true", default=False,
27 help="L1 trigger bits (from event header)")
28
29parser.add_argument("--decodeItems", action="store_true", default=False,
30 help="Decode trigger item names")
31
32parser.add_argument("--smk", action="store", type=int, default=0,
33 help="Specify SMK for trigger item decoding if not available in HLT result")
34
35parser.add_argument("--l2", action="store_true", default=False,
36 help="L2 trigger bits (from event header)")
37
38parser.add_argument("--ef", "--hlt", action="store_true", default=False,
39 help="EF/HLT trigger bits (from event header)")
40
41parser.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
44parser.add_argument("--stag", action="store_true", default=False,
45 help="stream tag")
46
47parser.add_argument("--l2res", action="store_true", default=False,
48 help="details of L2 ROB payload")
49
50parser.add_argument("--efres", "--hltres", action="store_true", default=False,
51 help="details of EF/HLT ROB payload")
52
53parser.add_argument("--chains", action="store_true", default=False,
54 help="details about chains")
55
56parser.add_argument("--features", action="store_true", default=False,
57 help="details about features")
58
59parser.add_argument("--tes", action="store_true", default=False,
60 help="details about TriggerElements")
61
62parser.add_argument("--conf", action="store_true", default=False,
63 help="configuration keys")
64
65parser.add_argument("--sizes", action="store_true", default=False,
66 help="dump info about sizes")
67
68parser.add_argument("--stats", action="store_true", default=False,
69 help="dump counts at the end only")
70
71parser.add_argument("--sizeSummary", action="store_true", default=False,
72 help="dump info about sizes at the end")
73
74parser.add_argument("--interactive", action="store_true", default=False,
75 help="after opening the file enter interactive prompt")
76
77
78
79args = parser.parse_args()
80
81from TrigByteStreamTools.hltResult import hltResult, print_HLTResult, collect_feature_sizes
82from TrigByteStreamTools import CTPfragment
83
84res = hltResult()
85#if args.interactive:
86# import code
87# code.interact(local=locals());
88
89
90featureSizes={}
91stats = {}
92smk = None
93
94def 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
100def 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
131def getL1Menu(smk):
132 from CoolRunQuery.utils.AtlRunQueryTriggerUtils import getL1Menu
133 return getL1Menu(str(smk))
134
135def 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
144def 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
262if __name__ == "__main__":
263 for f in args.files:
264 my_dump(f)
void print(char *figname, TCanvas *c1)
#define max(a, b)
Definition cfImp.cxx:41
std::map< const FolderIndex, FolderEntry > getFolderUpdates(const CTPfragment::ExtraPayload &x)