File indexing completed on 2025-10-13 08:18:25
0001 from pathlib import Path
0002 from typing import Union
0003 import os
0004 import warnings
0005
0006
0007 from .ActsPythonBindings import *
0008 from .ActsPythonBindings import __version__
0009 from . import ActsPythonBindings
0010 from ._adapter import _patch_config
0011
0012 if (
0013 "ACTS_LOG_FAILURE_THRESHOLD" in os.environ
0014 and os.environ["ACTS_LOG_FAILURE_THRESHOLD"] != logging.getFailureThreshold().name
0015 ):
0016 error = (
0017 "Runtime log failure threshold is given in environment variable "
0018 f"`ACTS_LOG_FAILURE_THRESHOLD={os.environ['ACTS_LOG_FAILURE_THRESHOLD']}`"
0019 "However, a compile-time value is set via CMake, i.e. "
0020 f"`ACTS_LOG_FAILURE_THRESHOLD={logging.getFailureThreshold().name}`. "
0021 "or `ACTS_ENABLE_LOG_FAILURE_THRESHOLD=OFF`, which disables runtime thresholds."
0022 )
0023 if "PYTEST_CURRENT_TEST" in os.environ:
0024
0025 raise RuntimeError(error)
0026 else:
0027 warnings.warn(error + "\nThe compile-time threshold will be used in this case!")
0028
0029
0030 def Propagator(stepper, navigator, level=ActsPythonBindings.logging.INFO):
0031 for prefix in ("Eigen", "Atlas", "StraightLine"):
0032 _stepper = getattr(ActsPythonBindings, f"{prefix}Stepper")
0033 if isinstance(stepper, _stepper):
0034 _detectorNavigator = getattr(ActsPythonBindings, "DetectorNavigator")
0035 if isinstance(navigator, _detectorNavigator):
0036 return getattr(
0037 ActsPythonBindings._propagator, f"{prefix}DetectorPropagator"
0038 )(stepper, navigator, level)
0039 return getattr(ActsPythonBindings._propagator, f"{prefix}Propagator")(
0040 stepper, navigator, level
0041 )
0042 raise TypeError(f"Unknown stepper {type(stepper).__name__}")
0043
0044
0045 _patch_config(ActsPythonBindings)
0046
0047
0048 @staticmethod
0049 def _decoratorFromFile(file: Union[str, Path], **kwargs):
0050 if isinstance(file, str):
0051 file = Path(file)
0052
0053 kwargs.setdefault("level", ActsPythonBindings.logging.INFO)
0054
0055 if file.suffix in (".json", ".cbor"):
0056 c = ActsPythonBindings.MaterialMapJsonConverter.Config()
0057 for k in kwargs.keys():
0058 if hasattr(c, k):
0059 setattr(c, k, kwargs.pop(k))
0060
0061 return ActsPythonBindings.JsonMaterialDecorator(
0062 jFileName=str(file), rConfig=c, **kwargs
0063 )
0064 elif file.suffix == ".root":
0065 return ActsPythonBindings._examples.RootMaterialDecorator(
0066 fileName=str(file), **kwargs
0067 )
0068 else:
0069 raise ValueError(f"Unknown file type {file.suffix}")
0070
0071
0072 ActsPythonBindings.IMaterialDecorator.fromFile = _decoratorFromFile