1"""Helpers for inspecting and logging C++ parameter blocks.
3The C++ ``BlockProvider`` gives access to HyperISO parameter blocks. It can
4check whether a block exists, log blocks through the C++ logging system, and
5retrieve block names or block contents as Python objects.
8from __future__
import annotations
10from typing
import Any, TypeAlias
12from pyhyperiso.phyperiso.pyhyperiso.core
import BlockProvider
as _CppBlockProvider
16BlockKey: TypeAlias = Any
17BlockContent: TypeAlias = dict[BlockKey, float]
21 """Diagnostic and inspection wrapper around the C++ ``BlockProvider``.
23 This class exposes block-level utilities for HyperISO parameters. It keeps
24 the original C++ logging methods available while also providing Pythonic
25 accessors for block names and block contents.
28 >>> logger = BlockLogger()
29 >>> logger.exists("SMINPUTS", ParameterType.SM)
31 >>> logger.get_all_blocks(ParameterType.SM)
32 {"SMINPUTS", "MASS", ...}
33 >>> logger.get_block(ParameterType.SM, "MASS")
38 """Create a block logger for the current C++ parameter storage."""
43 """Convert a Python ``ParameterType`` enum to its C++ value.
46 param_type: Python parameter namespace enum.
49 Integer value expected by the C++ binding.
52 TypeError: If ``param_type`` is not a ``ParameterType`` instance.
54 if not isinstance(param_type, ParameterType):
56 f
"param_type must be an instance of ParameterType, got {type(param_type).__name__}."
59 return param_type.value
61 def exists(self, blockname: str, param_type: ParameterType) -> bool:
62 """Return whether a block exists in a parameter namespace.
65 blockname: LHA-style block name, for example ``"MASS"``.
66 param_type: Parameter namespace to inspect.
69 ``True`` if the block exists, otherwise ``False``.
79 """Log all blocks from a parameter namespace through the C++ logger.
82 param_type: Parameter namespace to log.
86 def log_block(self, param_type: ParameterType, blockname: str) ->
None:
87 """Log one block through the C++ logger.
90 param_type: Parameter namespace containing the block.
91 blockname: Name of the block to log.
98 def get_block(self, param_type: ParameterType, blockname: str) -> BlockContent:
99 """Return the content of one block as a Python dictionary.
102 param_type: Parameter namespace containing the block.
103 blockname: Name of the block to retrieve.
106 Dictionary mapping LHA identifiers to scalar values.
109 >>> logger = BlockLogger()
110 >>> logger.get_block(ParameterType.SM, "MASS")
121 """Return all block names available in a parameter namespace.
124 param_type: Parameter namespace to inspect.
127 Set containing all available block names.
130 >>> logger = BlockLogger()
131 >>> logger.get_all_blocks(ParameterType.SM)
132 {"SMINPUTS", "MASS", ...}
141__all__ = [
"BlockLogger",
"BlockContent",
"BlockKey"]
int _to_cpp_param_type(ParameterType param_type)
BlockContent get_block(self, ParameterType param_type, str blockname)
set[str] get_all_blocks(self, ParameterType param_type)
None log_all_blocks(self, ParameterType param_type)
None log_block(self, ParameterType param_type, str blockname)
bool exists(self, str blockname, ParameterType param_type)