diff --git a/CLDConfig/CLDReconstruction.py b/CLDConfig/CLDReconstruction.py index f932131..8515777 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 1a4a556..9639a75 100644 --- a/CLDConfig/ParticleFlow/Pandora.py +++ b/CLDConfig/ParticleFlow/Pandora.py @@ -20,6 +20,17 @@ from Configurables import MarlinProcessorWrapper 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) MyDDMarlinPandoraParameters = { @@ -112,7 +123,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 +142,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 a5db106..17e5e20 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 + self, + alg_list: list, + global_vars: Optional[Dict[str, Any]] = None, + base_dir: Optional[str] = None, ) -> None: """Initialize the SequenceLoader @@ -93,9 +95,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 +122,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( @@ -130,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.