From 308b3afea403800a57cb2d276b9f65aa95cd94b6 Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Thu, 21 May 2026 14:46:04 +0200 Subject: [PATCH 1/3] make all paths relative --- CLDConfig/CLDReconstruction.py | 6 ++++-- CLDConfig/ParticleFlow/Pandora.py | 6 ++++-- CLDConfig/py_utils.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index f9321319..85157775 100644 --- a/CLDConfig/CLDReconstruction.py +++ b/CLDConfig/CLDReconstruction.py @@ -23,7 +23,8 @@ from k4FWCore import ApplicationMgr, IOSvc from k4FWCore.parseArgs import parser import sys -sys.path.append('.') +base_dir = os.path.dirname(__file__) +sys.path.append(base_dir) from py_utils import SequenceLoader, parse_collection_patch_file from k4MarlinWrapper.io_helpers import IOHandlerHelper @@ -58,7 +59,7 @@ "OutputModeChoices": ["LCIO", "EDM4hep"] #, "both"] FIXME: both is not implemented yet } -REC_COLLECTION_CONTENTS_FILE = "collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep +REC_COLLECTION_CONTENTS_FILE = f"{base_dir}/collections_rec_level.txt" # file with the collections to be patched in when writing from LCIO to EDM4hep geoservice = GeoSvc("GeoSvc") geoservice.detectors = [reco_args.compactFile] @@ -90,6 +91,7 @@ global_vars={"CONFIG": CONFIG, "geoservice": geoservice, "reco_args": reco_args, "BEAM_SPOT_SIZES": BEAM_SPOT_SIZES, }, + base_dir=base_dir, ) io_handler = IOHandlerHelper(algList, iosvc) diff --git a/CLDConfig/ParticleFlow/Pandora.py b/CLDConfig/ParticleFlow/Pandora.py index 1a4a556e..80214bed 100644 --- a/CLDConfig/ParticleFlow/Pandora.py +++ b/CLDConfig/ParticleFlow/Pandora.py @@ -20,7 +20,9 @@ from Configurables import MarlinProcessorWrapper import sys +import os +dir_path = os.path.dirname(__file__) MyDDMarlinPandoraParameters = { "FinalEnergyDensityBin": ["110."], @@ -112,7 +114,7 @@ if CONFIG["CalorimeterIntegrationTimeWindow"] == "10ns": MyDDMarlinPandora.Parameters |= { - "PandoraSettingsXmlFile": ["PandoraSettingsCLD/PandoraSettingsDefault.xml"], + "PandoraSettingsXmlFile": [f"{dir_path}/../PandoraSettingsCLD/PandoraSettingsDefault.xml"], "SoftwareCompensationWeights": ["2.40821", "-0.0515852", "0.000711414", "-0.0254891", "-0.0121505", "-1.63084e-05", "0.062149", "0.0690735", "-0.223064"], "ECalToMipCalibration": ["175.439"], "HCalToMipCalibration": ["45.6621"], @@ -131,7 +133,7 @@ elif CONFIG["CalorimeterIntegrationTimeWindow"] == "400ns": MyDDMarlinPandora.Parameters |= { - "PandoraSettingsXmlFile": ["PandoraSettingsCLD/PandoraSettingsDefault_400nsCalTimeWindow.xml"], + "PandoraSettingsXmlFile": [f"{dir_path}/../PandoraSettingsCLD/PandoraSettingsDefault_400nsCalTimeWindow.xml"], "SoftwareCompensationWeights": ["2.43375", "-0.0430951", "0.000244914", "-0.145478", "-0.00044577", "-8.37222e-05", "0.237484", "0.243491", "-0.0713701"], "ECalToMipCalibration": ["175.439"], "HCalToMipCalibration": ["49.7512"], diff --git a/CLDConfig/py_utils.py b/CLDConfig/py_utils.py index a5db106b..0d5c857a 100644 --- a/CLDConfig/py_utils.py +++ b/CLDConfig/py_utils.py @@ -78,7 +78,7 @@ class SequenceLoader: """ def __init__( - self, alg_list: list, global_vars: Optional[Dict[str, Any]] = None + self, alg_list: list, global_vars: Optional[Dict[str, Any]] = None, base_dir: Optional[str] = None ) -> None: """Initialize the SequenceLoader @@ -93,9 +93,11 @@ def __init__( variables for the sequences. Defaults to None. The keys in this dictionary will be the available variables in the imported module and the values will be the values of these variables. + base_dir (Optional[str]): path from which the sequences will be loaded. """ self.alg_list = alg_list self.global_vars = global_vars + self.base_dir = base_dir or "." def load(self, sequence: str) -> None: """Loads a sequence algorithm from a specified Python file and appends @@ -118,7 +120,7 @@ def load(self, sequence: str) -> None: sequence of algorithms that is defined in `TrackingDigiSequence` in that file to the alg_list """ - filename = f"{sequence}.py" + filename = f"{self.base_dir}/{sequence}.py" seq_name = f"{sequence.split('/')[-1]}Sequence" seq_module = import_from( From cae1b3b76cb857694353f0bfd5b1c2741cfb236e Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Thu, 21 May 2026 14:46:23 +0200 Subject: [PATCH 2/3] cleanup py_utils --- CLDConfig/py_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CLDConfig/py_utils.py b/CLDConfig/py_utils.py index 0d5c857a..17e5e201 100644 --- a/CLDConfig/py_utils.py +++ b/CLDConfig/py_utils.py @@ -19,7 +19,6 @@ import os from typing import Union, Optional, Dict, Any, List import importlib.util -import importlib.abc from importlib.machinery import SourceFileLoader @@ -78,7 +77,10 @@ class SequenceLoader: """ def __init__( - self, alg_list: list, global_vars: Optional[Dict[str, Any]] = None, base_dir: Optional[str] = None + self, + alg_list: list, + global_vars: Optional[Dict[str, Any]] = None, + base_dir: Optional[str] = None, ) -> None: """Initialize the SequenceLoader @@ -132,7 +134,6 @@ def load(self, sequence: str) -> None: self.alg_list.extend(seq) - def parse_collection_patch_file(patch_file: Union[str, os.PathLike]) -> List[str]: """Parse a collection patch file such that it can be used by the PatchCollections processor. From a8deec4d061dc19e8e63f5290a7f31ac18709b5f Mon Sep 17 00:00:00 2001 From: Leonhard Reichenbach Date: Fri, 22 May 2026 09:58:07 +0200 Subject: [PATCH 3/3] Warn in case Pandora is run from the wrong directory without breaking the help message --- CLDConfig/ParticleFlow/Pandora.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CLDConfig/ParticleFlow/Pandora.py b/CLDConfig/ParticleFlow/Pandora.py index 80214bed..9639a75a 100644 --- a/CLDConfig/ParticleFlow/Pandora.py +++ b/CLDConfig/ParticleFlow/Pandora.py @@ -21,8 +21,17 @@ import sys import os +from pathlib import Path + + +dir_path = Path(os.path.dirname(__file__)) +cwd = Path.cwd() + +help_only = "-h" in sys.argv or "--help" in sys.argv +if cwd != dir_path.parent and not help_only: + print(f"Running Pandora is only possible when k4run is called from the directory: {dir_path.parent}") + sys.exit(1) -dir_path = os.path.dirname(__file__) MyDDMarlinPandoraParameters = { "FinalEnergyDensityBin": ["110."],