7@author Alaettin Serhan Mete
8@brief A basic script for picking events from POOL files
11from AthenaPython.PyAthena
import Alg, py_svc, StatusCode
17 def __init__(self, name='PyEvtFilter', **kwargs):
20 self.
evtList = kwargs.get(
'evtList',
None)
21 self.
isMC = kwargs.get(
'isMC',
False)
25 self.
sg = py_svc(
'StoreGateSvc')
26 return StatusCode.Success
32 if self.
sg.
contains(
'xAOD::EventInfo',
'EventInfo'):
33 ei = self.
sg.retrieve(
'xAOD::EventInfo',
'EventInfo')
35 runNumber = ei.runNumber()
37 runNumber = ei.mcChannelNumber()
38 eventNumber = ei.eventNumber()
41 if (runNumber, eventNumber)
in self.
evtList:
42 self.setFilterPassed(
True)
44 self.setFilterPassed(
False)
47 return StatusCode.Success
50 return StatusCode.Failure
53if __name__ ==
"__main__":
57 parser = argparse.ArgumentParser(description=
'Select events identified by run number (mc channel number'
58 ' in case of Monte Carlo), event number from the input POOL file(s)')
59 parser.add_argument(
'--inputFiles', required=
True,
60 help=
'Input POOL file(s) separated with commas')
61 parser.add_argument(
'--outputFile', required=
True,
62 help=
'Output POOL file')
63 parser.add_argument(
'--eventList', required=
True,
64 help=
'Text file containing <run number> <event number> [<guid>] record(s) (one per line)')
65 args, _ = parser.parse_known_args()
68 from AthenaCommon.Logging
import logging
69 log = logging.getLogger(
'EventPicking')
70 log.info(
'== Picking events from POOL files w/ the CA Configuration')
74 with open(args.eventList)
as f:
76 run, evt, *guid = line.rstrip().
split()
77 evtList.append((int(run), int(evt)))
80 log.info(
'== Setting ConfigFlags')
81 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
82 flags = initConfigFlags()
83 flags.Input.Files = args.inputFiles.split(
',')
86 streamToOutput = flags.Input.ProcessingTags[0].removeprefix(
'Stream')
87 except Exception
as e:
88 raise RuntimeError(
'Could not determine the stream type')
from e
90 for name, value
in ((f
'Output.{streamToOutput}FileName', args.outputFile),
91 (f
'Output.doWrite{streamToOutput}',
True)):
92 if flags.hasFlag(name):
93 setattr(flags, name, value)
95 flags.addFlag(name, value)
96 if 'DAOD' in streamToOutput:
97 flags.Output.doWriteDAOD =
True
101 log.info(
'== ConfigFlags Locked')
104 log.info(
'== Configuring Main Services')
105 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
106 cfg = MainServicesCfg(flags)
109 log.info(
'== Configuring Input Reading')
110 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
111 cfg.merge(PoolReadCfg(flags))
114 cfg.addEventAlgo(
PyEvtFilter(
'EventFilterAlg', evtList=evtList, isMC=flags.Input.isMC), sequenceName=
'AthAlgSeq')
117 log.info(f
'== Configuring Output Stream {streamToOutput!r}')
118 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg, outputStreamName
119 cfg.merge(OutputStreamCfg(flags, streamToOutput, takeItemsFromInput=
True, extendProvenanceRecord=
False))
122 log.info(
'== Configuring metadata for the output stream')
123 from xAODMetaDataCnv.InfileMetaDataConfig
import SetupMetaDataForStreamCfg
124 from AthenaConfiguration.Enums
import MetadataCategory
126 cfg.merge(SetupMetaDataForStreamCfg(flags, streamToOutput,
127 createMetadata=[MetadataCategory.IOVMetaData]))
130 Stream = cfg.getEventAlgo(outputStreamName(streamToOutput))
131 Stream.ForceRead =
True
132 Stream.AcceptAlgs += [
'EventFilterAlg']
134 log.info(f
'== Configured {streamToOutput!r} writing')
136 for item
in flags.Input.TypedCollections:
137 ctype, cname = item.split(
'#')
138 if ctype.startswith(
'Trk')
or ctype.startswith(
'InDet'):
139 from TrkEventCnvTools.TrkEventCnvToolsConfig
import TrkEventCnvSuperToolCfg
140 cfg.merge(TrkEventCnvSuperToolCfg(flags))
141 if ctype.startswith(
'Calo')
or ctype.startswith(
'LAr'):
142 from LArGeoAlgsNV.LArGMConfig
import LArGMCfg
143 cfg.merge(LArGMCfg(flags))
144 if ctype.startswith(
'Calo')
or ctype.startswith(
'Tile'):
145 from TileGeoModel.TileGMConfig
import TileGMCfg
146 cfg.merge(TileGMCfg(flags))
147 if ctype.startswith(
'Muon'):
148 from MuonConfig.MuonGeometryConfig
import MuonGeoModelCfg
149 cfg.merge(MuonGeoModelCfg(flags))
152 if 'ESD' in streamToOutput:
153 Stream.ExtraInputs.add(
154 (
'MuonGM::MuonDetectorManager',
155 'ConditionStore+MuonDetectorManager' ) )
156 Stream.ExtraInputs.add(
157 (
'InDetDD::SiDetectorElementCollection',
158 'ConditionStore+PixelDetectorElementCollection' ) )
159 Stream.ExtraInputs.add(
160 (
'InDetDD::SiDetectorElementCollection',
161 'ConditionStore+SCT_DetectorElementCollection' ) )
162 Stream.ExtraInputs.add(
163 (
'InDetDD::TRT_DetElementContainer',
164 'ConditionStore+TRT_DetElementContainer' ) )
167 log.info(
'== Configuring PerfMon')
168 from PerfMonComps.PerfMonCompsConfig
import PerfMonMTSvcCfg
169 cfg.merge(PerfMonMTSvcCfg(flags))
172 log.info(
'== Running...')
177 sys.exit(
not sc.isSuccess())
__init__(self, name='PyEvtFilter', **kwargs)
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
std::vector< std::string > split(const std::string &s, const std::string &t=":")