ATLAS Offline Software
Loading...
Searching...
No Matches
trigbs_dumpHLTNav.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
6'''
7Dump content of the HLT navigation collections found in HLT ByteStream data
8'''
9
10import argparse
11import eformat
12from TrigByteStreamTools import hltResultMT
13
14from AthenaCommon.Logging import logging
15log = logging.getLogger('dumpHLTNav')
16
17
19 parser = argparse.ArgumentParser(usage='%(prog)s [options] FILE [FILE]',
20 description=__doc__)
21 parser.add_argument('files',
22 metavar='FILE [FILE]', nargs='+',
23 help='RAW files to inspect')
24 parser.add_argument('-n', '--events',
25 metavar='N', action='store', type=int,
26 help='Process N events')
27 parser.add_argument('-s', '--skip',
28 metavar='N', action='store', type=int,
29 help='Skip N events')
30 parser.add_argument('-m', '--module',
31 metavar='N', action='store', type=int, default=0,
32 help='HLT ROB module ID to print; negative number means all modules, default is %(default)s')
33 return parser
34
35
36def dump_nav(collections):
37
38 xaod_map = {}
39
40 # First step: loop over all collections to match interface + aux + decorations
41 for col in collections:
42 if 'HLTNav_' not in col.name():
43 continue
44
45 if col.is_xAOD_interface_container():
46 xaod_map[col.name_key] = {
47 'interface': col,
48 'aux_cont': None,
49 'decorations': []
50 }
51 elif col.is_xAOD_aux_container():
52 strip_name = col.name_key[0:-4] # Remove 'Aux.'
53 if strip_name not in xaod_map:
54 log.warning('%s not in xaod_map', strip_name)
55 continue
56 xaod_map[strip_name]['aux_cont'] = col
57 elif col.is_xAOD_decoration():
58 if not col.parent:
59 log.warning('{%s} has no parent', col.name())
60 strip_name = col.parent.name_key[0:-4] # Remove 'Aux.'
61 if strip_name not in xaod_map:
62 log.warning('%s not in xaod_map', strip_name)
63 continue
64 xaod_map[strip_name]['decorations'].append(col)
65
66 # Second step: loop over the matched collections and decode and print
67 for key, col_dict in xaod_map.items():
68 if not col_dict['interface']:
69 log.warning('%s interface collection missing', key)
70 continue
71 if not col_dict['aux_cont']:
72 log.warning('%s aux_cont collection missing', key)
73 continue
74 cont_if = col_dict['interface'].deserialise()
75 cont_aux = col_dict['aux_cont'].deserialise()
76 cont_deco = [c.deserialise() for c in col_dict['decorations']]
77
78 if not cont_if:
79 # Don't know why this happens, silence the warning for now
80 # log.warning('%s interface deserialisation failed', key)
81 continue
82 if not cont_aux:
83 log.warning('%s aux_cont deserialisation failed', key)
84 continue
85
86 cont_if.setStore(cont_aux)
87
88 print(' - %s' % key, flush=True)
89 for i in range(cont_if.size()):
90 obj = cont_if.at(i)
91 print(' - Element #%d' % i)
92 print(' - name: %s' % obj.name())
93 print(' - decisions: %s' % obj.decisions())
94 if cont_deco:
95 print(' - decorations:')
96 for i_deco, deco_vec in enumerate(cont_deco):
97 try:
98 print(' - %s = %s' % (col_dict['decorations'][i_deco].name_key, deco_vec.at(i)))
99 except Exception as ex:
100 log.warning(ex)
101 log.warning('i: %d', i)
102 log.warning('len(deco_vec): %d', len(deco_vec))
103 log.warning('i_deco: %d', i_deco)
104 log.warning('len(col_dict["decorations"]): %d', len(col_dict['decorations']))
105
106
107def dump_info(bsfile, args):
108 log.info('Opening %s', bsfile)
109 input = eformat.istream(bsfile)
110 offset = args.skip if args.skip else 0
111 max_events = min(args.events, len(input)) if args.events else len(input)
112 event_count = 0
113
114 # Loop over events
115 for event in input:
116 event_count += 1
117 if event_count <= offset:
118 continue
119 if event_count > offset+max_events:
120 break
121
122 # Print event header info
123 print('{sep:s} Event: {:d}, Run: {:d}, LB: {:d}, Global_ID: {:d} {sep:s}'.format(
124 event_count,
125 event.run_no(),
126 event.lumi_block(),
127 event.global_id(),
128 sep='='*20))
129
130 for rob in event.children():
131 if rob.source_id().subdetector_id() != eformat.helper.SubDetector.TDAQ_HLT:
132 continue
133 if args.module>=0 and rob.source_id().module_id() != args.module:
134 continue
135
136 # Print ROB header info
137 print('- ROB SourceID: {:s}'.format(rob.source_id().human()))
138
139 # Parse the raw data
140 collections = hltResultMT.get_collections(rob)
141 dump_nav(collections)
142
143
145 import ROOT
146 import os
147 for p in os.environ['DATAPATH'].split (':'):
148 fname = os.path.join (p, 'bs-streamerinfos.root')
149 if os.path.exists (fname):
150 ROOT.TFile.Open (fname)
151 break
152 else:
153 log.warning('Cannot find bs-streamerinfos.root file in DATAPATH')
154 return
155
156
157if '__main__' in __name__:
158 args = get_parser().parse_args()
160 for f in args.files:
161 dump_info(f, args)
void print(char *figname, TCanvas *c1)
#define min(a, b)
Definition cfImp.cxx:40
dump_info(bsfile, args)