7 @brief A basic script to output run number, event number of events in the input AOD file(s)
10 from AthenaPython.PyAthena
import Alg, py_svc, StatusCode
16 def __init__(self, name = 'PyxAODEventInfo', **kwds):
19 self.
isMC = kwds.get(
'isMC',
False)
25 from collections
import defaultdict
26 self.
info = defaultdict(list)
27 return StatusCode.Success
32 key_name =
'run_number'
34 key_name =
'mc_channel_number'
35 for run, event
in zip(self.
info[key_name], self.
info[
'event_number']):
36 print(f
"{'' if self.prefix is None else self.prefix}{run:d} {event:d}")
37 return StatusCode.Success
43 if self.
sg.
contains(
'xAOD::EventInfo',
'EventInfo'):
44 ei = self.
sg.
retrieve(
'xAOD::EventInfo',
'EventInfo')
45 runNumber = ei.runNumber()
46 eventNumber = ei.eventNumber()
47 mcChannelNumber = ei.mcChannelNumber()
50 self.
info[
'mc_channel_number'].
append(mcChannelNumber)
54 return StatusCode.Success
57 return StatusCode.Failure
60 if '__main__' in __name__:
64 parser = argparse.ArgumentParser(description=
'Output run number (mc channel number in case of Monte Carlo),'\
65 ' event number of events in the input AOD file(s)')
66 parser.add_argument(
'--inputAODFiles', required=
True,
67 help=
'Input AOD file(s) separated with commas')
68 parser.add_argument(
'--prefix',
69 help=
'Prefix to print in front of each line of output')
70 args = parser.parse_args()
73 from AthenaCommon.Logging
import logging
74 log = logging.getLogger(
'AodEventInfo')
75 log.info(
'== Listing EventInfo for events from AOD files (the CA Configuration)')
78 log.info(
'== Setting ConfigFlags')
79 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
81 flags.Input.Files = args.inputAODFiles.split(
',')
85 log.info(
'== ConfigFlags Locked')
88 log.info(
'== Configuring Main Services')
89 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
93 log.info(
'== Configuring Input Reading')
94 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
98 cfg.addEventAlgo(
PyxAODEventInfo(
'xAodEventInfoAlg', isMC = flags.Input.isMC, prefix = args.prefix),
99 sequenceName =
'AthAlgSeq')
102 from LArGeoAlgsNV.LArGMConfig
import LArGMCfg
104 from TileGeoModel.TileGMConfig
import TileGMCfg
108 from TrkEventCnvTools.TrkEventCnvToolsConfig
import TrkEventCnvSuperToolCfg
112 log.info(
'== Running...')
117 sys.exit(
not sc.isSuccess())