Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
__init__.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file __init__.py
1 from pathlib import Path
2 from typing import Union
3 import os
4 import warnings
5 
6 
7 from .ActsPythonBindings import *
8 from .ActsPythonBindings import __version__
9 from . import ActsPythonBindings
10 from ._adapter import _patch_config
11 
12 if (
13  "ACTS_LOG_FAILURE_THRESHOLD" in os.environ
14  and os.environ["ACTS_LOG_FAILURE_THRESHOLD"] != logging.getFailureThreshold().name
15 ):
16  error = (
17  "Runtime log failure threshold is given in environment variable "
18  f"`ACTS_LOG_FAILURE_THRESHOLD={os.environ['ACTS_LOG_FAILURE_THRESHOLD']}`"
19  "However, a compile-time value is set via CMake, i.e. "
20  f"`ACTS_LOG_FAILURE_THRESHOLD={logging.getFailureThreshold().name}`. "
21  "or `ACTS_ENABLE_LOG_FAILURE_THRESHOLD=OFF`, which disables runtime thresholds."
22  )
23  if "PYTEST_CURRENT_TEST" in os.environ:
24  # test environment, fail hard
25  raise RuntimeError(error)
26  else:
27  warnings.warn(error + "\nThe compile-time threshold will be used in this case!")
28 
29 
30 def Propagator(stepper, navigator):
31  for prefix in ("Eigen", "Atlas", "StraightLine"):
32  _stepper = getattr(ActsPythonBindings, f"{prefix}Stepper")
33  if isinstance(stepper, _stepper):
34  _detectorNavigator = getattr(ActsPythonBindings, "DetectorNavigator")
35  if isinstance(navigator, _detectorNavigator):
36  return getattr(
37  ActsPythonBindings._propagator, f"{prefix}DetectorPropagator"
38  )(stepper, navigator)
39  return getattr(ActsPythonBindings._propagator, f"{prefix}Propagator")(
40  stepper, navigator
41  )
42  raise TypeError(f"Unknown stepper {type(stepper).__name__}")
43 
44 
45 _patch_config(ActsPythonBindings)
46 
47 
48 @staticmethod
49 def _decoratorFromFile(file: Union[str, Path], **kwargs):
50  if isinstance(file, str):
51  file = Path(file)
52 
53  kwargs.setdefault("level", ActsPythonBindings.logging.INFO)
54 
55  if file.suffix in (".json", ".cbor"):
56  c = ActsPythonBindings.MaterialMapJsonConverter.Config()
57  for k in kwargs.keys():
58  if hasattr(c, k):
59  setattr(c, k, kwargs.pop(k))
60 
61  return ActsPythonBindings.JsonMaterialDecorator(
62  jFileName=str(file), rConfig=c, **kwargs
63  )
64  elif file.suffix == ".root":
65  return ActsPythonBindings._examples.RootMaterialDecorator(
66  fileName=str(file), **kwargs
67  )
68  else:
69  raise ValueError(f"Unknown file type {file.suffix}")
70 
71 
72 ActsPythonBindings.IMaterialDecorator.fromFile = _decoratorFromFile