6 @file AODEventPicking.py
7 @author Alaettin Serhan Mete
8 @brief A basic script for picking events from AOD files
11 from AthenaPython.PyAthena
import Alg, py_svc, StatusCode
17 def __init__(self, name = 'PyxAODEvtFilter', **kw):
19 super(PyxAODEvtFilter, self).
__init__(**kw)
21 self.
isMC = kw.get(
'isMC',
False)
27 return StatusCode.Success
33 if self.
sg.
contains(
'xAOD::EventInfo',
'EventInfo'):
34 ei = self.
sg.
retrieve(
'xAOD::EventInfo',
'EventInfo')
36 runNumber = ei.runNumber()
38 runNumber = ei.mcChannelNumber()
39 eventNumber = ei.eventNumber()
42 if (runNumber, eventNumber)
in self.
evtList:
43 self.setFilterPassed(
True)
45 self.setFilterPassed(
False)
48 return StatusCode.Success
51 return StatusCode.Failure
54 if '__main__' in __name__:
58 parser = argparse.ArgumentParser(description=
'Select events identified by run number (mc channel number'\
59 ' in case of Monte Carlo), event number from the input AOD file(s)')
60 parser.add_argument(
'--inputAODFiles', required=
True,
61 help=
'Input AOD file(s) separated with commas')
62 parser.add_argument(
'--outputAODFile', required=
True,
63 help=
'Output AOD file')
64 parser.add_argument(
'--eventList', required=
True,
65 help=
'Text file containing <run number> <event number> [<guid>] record(s) (one per line)')
66 args, _ = parser.parse_known_args()
69 from AthenaCommon.Logging
import logging
70 log = logging.getLogger(
'AODEventPicking')
71 log.info(
'== Picking events from AOD files w/ the CA Configuration')
75 with open(args.eventList)
as f:
77 run, evt, *guid = line.rstrip().
split()
78 evtList.append((
int(run),
int(evt)))
81 log.info(
'== Setting ConfigFlags')
82 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
84 flags.Input.Files = args.inputAODFiles.split(
',')
85 flags.Output.AODFileName = args.outputAODFile
86 flags.PerfMon.doFastMonMT =
True
87 flags.PerfMon.OutputJSON =
'perfmonmt_AODEventPicking.json'
91 log.info(
'== ConfigFlags Locked')
94 log.info(
'== Configuring Main Services')
95 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
99 log.info(
'== Configuring Input Reading')
100 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
104 cfg.addEventAlgo(
PyxAODEvtFilter(
'EventFilterAlg', evtList = evtList, isMC = flags.Input.isMC), sequenceName =
'AthAlgSeq')
107 log.info(
'== Configuring Output Stream')
108 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg, outputStreamName
112 log.info(
'== Configuring metadata for the output stream')
113 from xAODMetaDataCnv.InfileMetaDataConfig
import SetupMetaDataForStreamCfg
118 StreamAOD.ForceRead =
True
119 StreamAOD.AcceptAlgs += [
'EventFilterAlg']
122 from LArGeoAlgsNV.LArGMConfig
import LArGMCfg
124 from TileGeoModel.TileGMConfig
import TileGMCfg
128 from TrkEventCnvTools.TrkEventCnvToolsConfig
import TrkEventCnvSuperToolCfg
132 log.info(
'== Configuring PerfMon')
133 from PerfMonComps.PerfMonCompsConfig
import PerfMonMTSvcCfg
137 log.info(
'== Running...')
142 sys.exit(
not sc.isSuccess())