Skip to content

Commit c724257

Browse files
Zehvogeljmcarcell
andauthored
[BREAKING] Switch to using the IOSvc (#77)
Co-authored-by: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com>
1 parent 25dbb65 commit c724257

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

CLDConfig/CLDReconstruction.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
import os
2020
from Gaudi.Configuration import INFO, WARNING, DEBUG
2121

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
2424
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
2627

2728
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"])
2931
parser_group.add_argument("--outputBasename", help="Basename of the output file(s)", default="output")
3032
parser_group.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False)
3133
parser_group.add_argument("--enableLCFIJet", action="store_true", help="Enable LCFIPlus jet clustering parts", default=False)
@@ -36,11 +38,12 @@
3638
tracking_group.add_argument("--truthTracking", action="store_true", default=False, help="Cheat tracking pattern recognition")
3739
reco_args = parser.parse_known_args()[0]
3840

39-
algList = []
40-
svcList = []
4141

42-
evtsvc = k4DataSvc("EventDataSvc")
43-
svcList.append(evtsvc)
42+
evtsvc = EventDataSvc("EventDataSvc")
43+
iosvc = IOSvc()
44+
45+
svcList = [evtsvc, iosvc]
46+
algList = []
4447

4548
CONFIG = {
4649
"CalorimeterIntegrationTimeWindow": "10ns",
@@ -55,7 +58,6 @@
5558

5659
REC_COLLECTION_CONTENTS_FILE = "collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep
5760

58-
from Configurables import GeoSvc, TrackingCellIDEncodingSvc, Lcio2EDM4hepTool
5961
geoservice = GeoSvc("GeoSvc")
6062
geoservice.detectors = [reco_args.compactFile]
6163
geoservice.OutputLevel = INFO
@@ -88,13 +90,8 @@
8890
},
8991
)
9092

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)
9895

9996
MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor")
10097
MyAIDAProcessor.OutputLevel = WARNING
@@ -149,11 +146,22 @@
149146

150147
# TODO: replace all the ugly strings by something sensible like Enum
151148
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+
}
154154

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+
}
157165

158166
if CONFIG["OutputMode"] == "EDM4Hep":
159167
# Make sure that all collections are always available by patching in missing ones on-the-fly
@@ -165,21 +173,14 @@
165173
}
166174
algList.append(collPatcherRec)
167175

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 *"])
171177
# 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>
175179

176-
# We need to convert the inputs in case we have EDM4hep input
177-
attach_edm4hep2lcio_conversion(algList, read)
178180

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()
181183

182-
from Configurables import ApplicationMgr
183184
ApplicationMgr( TopAlg = algList,
184185
EvtSel = 'NONE',
185186
EvtMax = 3, # Overridden by the --num-events switch to k4run

0 commit comments

Comments
 (0)