1"""Read-only access to parameters stored in the C++ core.
3The filename keeps the historical spelling ``ParamaterProvider.py`` for import
4compatibility. The public class is :class:`ParameterProvider`.
7from __future__
import annotations
9from typing
import Optional, Union
11from pyhyperiso.phyperiso.pyhyperiso.core
import ParameterProvider
as _CppParameterProvider
15from pyhyperiso.core.Math.Scalar
import Scalar
19 """Read parameter values and metadata from a C++ parameter namespace.
21 A provider can be bound to a specific :class:`ParameterType`, or left
22 unfiltered to use the C++ provider default. Parameters can be addressed by
23 a full ``ParamId`` or by the pair ``(block, code)``.
26 >>> provider = ParameterProvider(ParameterType.SM)
27 >>> pid = ParamId(type=ParameterType.SM, block="MASS", code=24)
28 >>> provider.exists_by_pid(pid)
30 >>> provider.get_by_block("MASS", 24)
34 def __init__(self, param_type: Optional[ParameterType] =
None) ->
None:
38 param_type: Optional parameter namespace. When omitted, the C++
39 default provider constructor is used.
43 _CppParameterProvider(param_type.value)
44 if param_type
is not None
45 else _CppParameterProvider()
48 def get_by_pid(self, pid: ParamId, dtype: DataType = DataType.VALUE) -> Scalar:
49 """Return a parameter component addressed by ``ParamId``.
52 pid: Parameter identifier.
53 dtype: Component to read, for example central value or uncertainty.
56 Requested parameter component as a Scalar (real,complex).
58 return Scalar.from_cpp(self.
_cpp_obj(pid._cpp_obj, dtype.value))
63 code: Union[int, str, list, LhaID],
64 dtype: DataType = DataType.VALUE,
66 """Return a parameter component addressed by block and LHA code.
69 block: LHA-style block name.
70 code: LHA code. Integers, strings, lists and ``LhaID`` are accepted.
71 dtype: Component to read.
74 Requested parameter component as a Scalar (real,complex).
76 if not isinstance(code, LhaID):
78 return Scalar.from_cpp(self.
_cpp_obj(block, code._cpp_obj, dtype.value))
81 """Return whether a parameter exists for a full ``ParamId``."""
82 return bool(self.
_cpp_obj.exists(pid._cpp_obj))
84 def exists_by_block(self, block: str, code: Union[int, str, list, LhaID]) -> bool:
85 """Return whether a parameter exists for ``(block, code)``."""
86 if not isinstance(code, LhaID):
88 return bool(self.
_cpp_obj.exists(block, code._cpp_obj))
91 """Return the full parameter object for ``pid``.
94 pid: Parameter identifier to retrieve.
97 Python ``Parameter`` wrapper around the bound C++ object.
100 return Parameter.from_cpp(cpp_param)
103 """Return the namespace served by this provider."""
107 """Return a compact representation including the provider type."""
108 return f
"<PyParameterProvider type={self.get_type().name}>"
111__all__ = [
"ParameterProvider"]
Scalar get_by_block(self, str block, Union[int, str, list, LhaID] code, DataType dtype=DataType.VALUE)
Parameter get_parameter(self, ParamId pid)
bool exists_by_pid(self, ParamId pid)
ParameterType get_type(self)
bool exists_by_block(self, str block, Union[int, str, list, LhaID] code)
None __init__(self, Optional[ParameterType] param_type=None)
Scalar get_by_pid(self, ParamId pid, DataType dtype=DataType.VALUE)