Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:21:36

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         # test environment, fail hard
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             return getattr(ActsPythonBindings, f"{prefix}Propagator")(
0035                 stepper, navigator, level
0036             )
0037     raise TypeError(f"Unknown stepper {type(stepper).__name__}")
0038 
0039 
0040 _patch_config(ActsPythonBindings)
0041 
0042 
0043 @staticmethod
0044 def _decoratorFromFile(file: Union[str, Path], **kwargs):
0045     if isinstance(file, str):
0046         file = Path(file)
0047 
0048     kwargs.setdefault("level", ActsPythonBindings.logging.INFO)
0049 
0050     from .ActsPluginsPythonBindingsJson import (
0051         MaterialMapJsonConverter,
0052         JsonMaterialDecorator,
0053     )
0054     from .ActsPluginsPythonBindingsRoot import RootMaterialDecorator
0055 
0056     if file.suffix in (".json", ".cbor"):
0057         c = MaterialMapJsonConverter.Config()
0058         for k in kwargs.keys():
0059             if hasattr(c, k):
0060                 setattr(c, k, kwargs.pop(k))
0061 
0062         return JsonMaterialDecorator(jFileName=str(file), rConfig=c, **kwargs)
0063     elif file.suffix == ".root":
0064         return RootMaterialDecorator(fileName=str(file), **kwargs)
0065     else:
0066         raise ValueError(f"Unknown file type {file.suffix}")
0067 
0068 
0069 ActsPythonBindings.IMaterialDecorator.fromFile = _decoratorFromFile