|
19 | 19 | import os |
20 | 20 | from Gaudi.Configuration import INFO, WARNING, DEBUG |
21 | 21 |
|
22 | | -from Configurables import k4DataSvc, MarlinProcessorWrapper |
23 | | -from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion |
| 22 | +from Gaudi.Configurables import EventDataSvc, MarlinProcessorWrapper, GeoSvc, TrackingCellIDEncodingSvc |
| 23 | +from k4FWCore import ApplicationMgr, IOSvc |
24 | 24 | from k4FWCore.parseArgs import parser |
25 | | -from py_utils import SequenceLoader, attach_lcio2edm4hep_conversion, create_writer, parse_collection_patch_file |
| 25 | +from py_utils import SequenceLoader, parse_collection_patch_file |
| 26 | +from k4MarlinWrapper.io_helpers import IOHandlerHelper |
26 | 27 |
|
27 | 28 | parser_group = parser.add_argument_group("CLDReconstruction.py custom options") |
28 | | -parser_group.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files") |
| 29 | +# Need the dummy input such that the IOHandlerHelper.add_reader call below does not crash when called with --help |
| 30 | +parser_group.add_argument("--inputFiles", action="store", nargs="+", metavar=("file1", "file2"), help="One or multiple input files", default=["dummy_input.edm4hep.root"]) |
29 | 31 | parser_group.add_argument("--outputBasename", help="Basename of the output file(s)", default="output") |
30 | 32 | parser_group.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False) |
31 | 33 | parser_group.add_argument("--enableLCFIJet", action="store_true", help="Enable LCFIPlus jet clustering parts", default=False) |
|
36 | 38 | tracking_group.add_argument("--truthTracking", action="store_true", default=False, help="Cheat tracking pattern recognition") |
37 | 39 | reco_args = parser.parse_known_args()[0] |
38 | 40 |
|
39 | | -algList = [] |
40 | | -svcList = [] |
41 | 41 |
|
42 | | -evtsvc = k4DataSvc("EventDataSvc") |
43 | | -svcList.append(evtsvc) |
| 42 | +evtsvc = EventDataSvc("EventDataSvc") |
| 43 | +iosvc = IOSvc() |
| 44 | + |
| 45 | +svcList = [evtsvc, iosvc] |
| 46 | +algList = [] |
44 | 47 |
|
45 | 48 | CONFIG = { |
46 | 49 | "CalorimeterIntegrationTimeWindow": "10ns", |
|
55 | 58 |
|
56 | 59 | REC_COLLECTION_CONTENTS_FILE = "collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep |
57 | 60 |
|
58 | | -from Configurables import GeoSvc, TrackingCellIDEncodingSvc, Lcio2EDM4hepTool |
59 | 61 | geoservice = GeoSvc("GeoSvc") |
60 | 62 | geoservice.detectors = [reco_args.compactFile] |
61 | 63 | geoservice.OutputLevel = INFO |
|
88 | 90 | }, |
89 | 91 | ) |
90 | 92 |
|
91 | | -if reco_args.inputFiles: |
92 | | - read = create_reader(reco_args.inputFiles, evtsvc) |
93 | | - read.OutputLevel = INFO |
94 | | - algList.append(read) |
95 | | -else: |
96 | | - print('WARNING: No input files specified, the CLD Reconstruction will fail') |
97 | | - read = None |
| 93 | +io_handler = IOHandlerHelper(algList, iosvc) |
| 94 | +io_handler.add_reader(reco_args.inputFiles) |
98 | 95 |
|
99 | 96 | MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor") |
100 | 97 | MyAIDAProcessor.OutputLevel = WARNING |
|
149 | 146 |
|
150 | 147 | # TODO: replace all the ugly strings by something sensible like Enum |
151 | 148 | if CONFIG["OutputMode"] == "LCIO": |
152 | | - Output_REC = create_writer("lcio", "Output_REC", f"{reco_args.outputBasename}_REC") |
153 | | - algList.append(Output_REC) |
| 149 | + Output_REC = io_handler.add_lcio_writer("Output_REC") |
| 150 | + Output_REC.Parameters = { |
| 151 | + "LCIOOutputFile": [f"{reco_args.outputBasename}_REC.slcio"], |
| 152 | + "LCIOWriteMode": ["WRITE_NEW"], |
| 153 | + } |
154 | 154 |
|
155 | | - Output_DST = create_writer("lcio", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST, DST_SUBSETLIST) |
156 | | - algList.append(Output_DST) |
| 155 | + Output_DST = io_handler.add_lcio_writer("Output_DST") |
| 156 | + dropped_types = ["MCParticle", "LCRelation", "SimCalorimeterHit", "CalorimeterHit", "SimTrackerHit", "TrackerHit", "TrackerHitPlane", "Track", "ReconstructedParticle", "LCFloatVec"] |
| 157 | + Output_DST.Parameters = { |
| 158 | + "LCIOOutputFile": [f"{reco_args.outputBasename}_DST.slcio"], |
| 159 | + "LCIOWriteMode": ["WRITE_NEW"], |
| 160 | + "DropCollectionNames": [], |
| 161 | + "DropCollectionTypes": dropped_types, |
| 162 | + "FullSubsetCollections": DST_SUBSETLIST, |
| 163 | + "KeepCollectionNames": DST_KEEPLIST, |
| 164 | + } |
157 | 165 |
|
158 | 166 | if CONFIG["OutputMode"] == "EDM4Hep": |
159 | 167 | # Make sure that all collections are always available by patching in missing ones on-the-fly |
|
165 | 173 | } |
166 | 174 | algList.append(collPatcherRec) |
167 | 175 |
|
168 | | - Output_REC = create_writer("edm4hep", "Output_REC", f"{reco_args.outputBasename}_REC") |
169 | | - algList.append(Output_REC) |
170 | | - |
| 176 | + io_handler.add_edm4hep_writer(f"{reco_args.outputBasename}_REC.edm4hep.root", ["keep *"]) |
171 | 177 | # FIXME: needs https://github.com/key4hep/k4FWCore/issues/226 |
172 | | - # Output_DST = create_writer("edm4hep", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST) |
173 | | - # algList.append(Output_DST) |
174 | | - |
| 178 | + # <DST output for edm4hep> |
175 | 179 |
|
176 | | -# We need to convert the inputs in case we have EDM4hep input |
177 | | -attach_edm4hep2lcio_conversion(algList, read) |
178 | 180 |
|
179 | | -# We need to convert the outputs in case we have EDM4hep output |
180 | | -attach_lcio2edm4hep_conversion(algList) |
| 181 | +# We need to attach all the necessary converters |
| 182 | +io_handler.finalize_converters() |
181 | 183 |
|
182 | | -from Configurables import ApplicationMgr |
183 | 184 | ApplicationMgr( TopAlg = algList, |
184 | 185 | EvtSel = 'NONE', |
185 | 186 | EvtMax = 3, # Overridden by the --num-events switch to k4run |
|
0 commit comments