From 5e1cb3ef29372cbed6d69f7db20e2fd1823838d1 Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Wed, 30 Apr 2025 16:20:03 +0200 Subject: [PATCH 1/4] some import cleanups --- CLDConfig/CLDReconstruction.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 007cf31..65431d1 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -19,7 +19,7 @@ import os from Gaudi.Configuration import INFO, WARNING, DEBUG -from Configurables import k4DataSvc, MarlinProcessorWrapper +from Gaudi.Configurables import k4DataSvc, MarlinProcessorWrapper, GeoSvc, TrackingCellIDEncodingSvc from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion from k4FWCore.parseArgs import parser from py_utils import SequenceLoader, attach_lcio2edm4hep_conversion, create_writer, parse_collection_patch_file @@ -55,7 +55,6 @@ REC_COLLECTION_CONTENTS_FILE = "collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep -from Configurables import GeoSvc, TrackingCellIDEncodingSvc, Lcio2EDM4hepTool geoservice = GeoSvc("GeoSvc") geoservice.detectors = [reco_args.compactFile] geoservice.OutputLevel = INFO From 3b15b6a430d087fc92c999b2434de52eff27348b Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Wed, 30 Apr 2025 16:40:19 +0200 Subject: [PATCH 2/4] switch to io_handler --- CLDConfig/CLDReconstruction.py | 59 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 65431d1..40d1e9a 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -19,10 +19,11 @@ import os from Gaudi.Configuration import INFO, WARNING, DEBUG -from Gaudi.Configurables import k4DataSvc, MarlinProcessorWrapper, GeoSvc, TrackingCellIDEncodingSvc -from k4MarlinWrapper.inputReader import create_reader, attach_edm4hep2lcio_conversion +from Gaudi.Configurables import EventDataSvc, MarlinProcessorWrapper, GeoSvc, TrackingCellIDEncodingSvc +from k4FWCore import ApplicationMgr, IOSvc from k4FWCore.parseArgs import parser -from py_utils import SequenceLoader, attach_lcio2edm4hep_conversion, create_writer, parse_collection_patch_file +from py_utils import SequenceLoader, parse_collection_patch_file +from k4MarlinWrapper.io_helpers import IOHandlerHelper parser_group = parser.add_argument_group("CLDReconstruction.py custom options") parser_group.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files") @@ -36,11 +37,12 @@ tracking_group.add_argument("--truthTracking", action="store_true", default=False, help="Cheat tracking pattern recognition") reco_args = parser.parse_known_args()[0] -algList = [] -svcList = [] -evtsvc = k4DataSvc("EventDataSvc") -svcList.append(evtsvc) +evtsvc = EventDataSvc("EventDataSvc") +iosvc = IOSvc() + +svcList = [evtsvc, iosvc] +algList = [] CONFIG = { "CalorimeterIntegrationTimeWindow": "10ns", @@ -87,13 +89,9 @@ }, ) -if reco_args.inputFiles: - read = create_reader(reco_args.inputFiles, evtsvc) - read.OutputLevel = INFO - algList.append(read) -else: - print('WARNING: No input files specified, the CLD Reconstruction will fail') - read = None +io_handler = IOHandlerHelper(algList, iosvc) +# FIXME: breaks --help as inputFiles are empty +io_handler.add_reader(reco_args.inputFiles) MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor") MyAIDAProcessor.OutputLevel = WARNING @@ -148,10 +146,22 @@ # TODO: replace all the ugly strings by something sensible like Enum if CONFIG["OutputMode"] == "LCIO": - Output_REC = create_writer("lcio", "Output_REC", f"{reco_args.outputBasename}_REC") - algList.append(Output_REC) + Output_REC = io_handler.add_lcio_writer("Output_REC") + Output_REC.Parameters = { + "LCIOOutputFile": [f"{reco_args.outputBasename}_REC.slcio"], + "LCIOWriteMode": ["WRITE_NEW"], + } - Output_DST = create_writer("lcio", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST, DST_SUBSETLIST) + Output_DST = io_handler.add_lcio_writer("Output_DST") + dropped_types = ["MCParticle", "LCRelation", "SimCalorimeterHit", "CalorimeterHit", "SimTrackerHit", "TrackerHit", "TrackerHitPlane", "Track", "ReconstructedParticle", "LCFloatVec"] + Output_DST.Parameters = { + "LCIOOutputFile": [f"{reco_args.outputBasename}_DST.slcio"], + "LCIOWriteMode": ["WRITE_NEW"], + "DropCollectionNames": [], + "DropCollectionTypes": dropped_types, + "FullSubsetCollections": DST_SUBSETLIST, + "KeepCollectionNames": DST_KEEPLIST, + } algList.append(Output_DST) if CONFIG["OutputMode"] == "EDM4Hep": @@ -164,21 +174,14 @@ } algList.append(collPatcherRec) - Output_REC = create_writer("edm4hep", "Output_REC", f"{reco_args.outputBasename}_REC") - algList.append(Output_REC) - + io_handler.add_edm4hep_writer(f"{reco_args.outputBasename}_REC.edm4hep.root", ["keep *"]) # FIXME: needs https://github.com/key4hep/k4FWCore/issues/226 - # Output_DST = create_writer("edm4hep", "Output_DST", f"{reco_args.outputBasename}_DST", DST_KEEPLIST) - # algList.append(Output_DST) - + # -# We need to convert the inputs in case we have EDM4hep input -attach_edm4hep2lcio_conversion(algList, read) -# We need to convert the outputs in case we have EDM4hep output -attach_lcio2edm4hep_conversion(algList) +# We need to attach all the necessary converters +io_handler.finalize_converters() -from Configurables import ApplicationMgr ApplicationMgr( TopAlg = algList, EvtSel = 'NONE', EvtMax = 3, # Overridden by the --num-events switch to k4run From ed910ee47b963c95ab457b82f91eb3ea27bcd738 Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Fri, 2 May 2025 08:44:07 +0200 Subject: [PATCH 3/4] add dummy input file name to make --help work again --- CLDConfig/CLDReconstruction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 40d1e9a..5f84f75 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -26,7 +26,8 @@ from k4MarlinWrapper.io_helpers import IOHandlerHelper parser_group = parser.add_argument_group("CLDReconstruction.py custom options") -parser_group.add_argument("--inputFiles", action="extend", nargs="+", metavar=("file1", "file2"), help="One or multiple input files") +# Need the dummy input such that the IOHandlerHelper.add_reader call below does not crash when called with --help +parser_group.add_argument("--inputFiles", action="store", nargs="+", metavar=("file1", "file2"), help="One or multiple input files", default=["dummy_input.edm4hep.root"]) parser_group.add_argument("--outputBasename", help="Basename of the output file(s)", default="output") parser_group.add_argument("--trackingOnly", action="store_true", help="Run only track reconstruction", default=False) parser_group.add_argument("--enableLCFIJet", action="store_true", help="Enable LCFIPlus jet clustering parts", default=False) @@ -90,7 +91,6 @@ ) io_handler = IOHandlerHelper(algList, iosvc) -# FIXME: breaks --help as inputFiles are empty io_handler.add_reader(reco_args.inputFiles) MyAIDAProcessor = MarlinProcessorWrapper("MyAIDAProcessor") From f57ef9c3baf4aec1da264e1701ba53c570b70674 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:45:25 +0200 Subject: [PATCH 4/4] Delete unneeded line --- CLDConfig/CLDReconstruction.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index 5f84f75..bff1191 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -162,7 +162,6 @@ "FullSubsetCollections": DST_SUBSETLIST, "KeepCollectionNames": DST_KEEPLIST, } - algList.append(Output_DST) if CONFIG["OutputMode"] == "EDM4Hep": # Make sure that all collections are always available by patching in missing ones on-the-fly