|
Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
|
Alias-aware container / façade over several parameter blocks. More...
#include <BlockAccessor.h>


Public Types | |
| using | base_t = std::unordered_map< std::string, std::shared_ptr< Block > > |
| Underlying associative container type. | |
Public Member Functions | |
| bool | has_param (const BlockName &blockName, LhaID pdgCode) const |
| Checks whether a given parameter exists inside a named block. | |
| void | setValue (const BlockName &blockName, LhaID pdgCode, scalar_t value) |
| Sets the value of a parameter inside an existing block. | |
| scalar_t | getValue (const BlockName &blockName, LhaID pdgCode) const |
| Retrieves the current value of a parameter from a block. | |
| std::shared_ptr< Parameter > | getParameter (const BlockName &blockName, LhaID id) const |
| Retrieves the full Parameter object stored in a block. | |
| void | setParameter (const BlockName &blockName, LhaID id, std::shared_ptr< Parameter > source) |
| Inserts or updates a full Parameter object in a block. | |
| std::map< LhaID, scalar_t > | getAllValues (BlockName blockName) |
| Returns all current scalar values stored in a block. | |
| std::unordered_set< BlockName > | get_block_names () const |
| Returns the set of all known block names. | |
| void | remove_item (const BlockName &block_name, LhaID id) |
| Removes one parameter from a block. | |
| bool | contains (const BlockName &block_name) const |
| Checks whether a block exists (alias-aware). | |
| double | get_scale (const BlockName &block_name) const |
| Returns the scale attached to a given block. | |
| bool | has_scale (const BlockName &block_name) const |
| Checks whether a given block has a scale attached. | |
| std::unordered_map< std::string, std::shared_ptr< Block > > | get_block_sources (const BlockName &block_name) const |
| Returns the source blocks of a given block. | |
| std::unordered_map< ParamId, std::shared_ptr< Parameter > > | get_parameter_sources (const BlockName &block_name, LhaID id) const |
| Returns the source parameters of a given parameter. | |
| std::unordered_set< ParamId > | get_all_source_parameters (const std::unordered_set< ParamId > ¶m_ids) const |
| Recursively finds all leaf source parameters behind a set of parameters. | |
| bool | is_dependent_block (const BlockName &block_name) const |
| Checks whether a block is implemented as a DependentBlock. | |
| std::vector< std::string > | get_source_block_names (const BlockName &block_name) const |
| Returns the direct source block names of a block. | |
| std::vector< std::string > | get_dependent_block_names (const BlockName &block_name) const |
| Returns the direct dependent block names observing a block. | |
| std::vector< std::string > | get_all_source_block_names (const BlockName &block_name) const |
| Returns all transitive source block names of a block. | |
| std::vector< std::string > | get_all_dependent_block_names (const BlockName &block_name) const |
| Returns all transitive dependent block names observing a block. | |
| std::shared_ptr< Block > & | at (const BlockName &block_name) |
| Alias-aware mutable access to a block. | |
| const std::shared_ptr< Block > & | at (const BlockName &block_name) const |
| Alias-aware const access to a block. | |
| std::shared_ptr< BlockAccessor > | operator[] (std::unordered_set< BlockName > block_names) |
| Extracts a subset of blocks into a new accessor. | |
| void | emplace (const BlockName &name, std::shared_ptr< Block > blk) |
| Inserts or replaces a block, updating alias metadata. | |
| std::shared_ptr< BlockAccessor > | deep_clone_plain () const |
| Deep-copy all stored blocks as independent plain blocks. | |
| void | detach_block (const BlockName &block_name) |
| Detaches a dependent block from its upstream dependencies. | |
| void | reattach_block (const BlockName &block_name) |
| Reattaches a previously detached dependent block to its saved sources. | |
| void | detach_parameter (const BlockName &block_name, LhaID id) |
| Detaches a dependent parameter from its upstream dependencies. | |
| void | reattach_parameter (const BlockName &block_name, LhaID id) |
| Reattaches a previously detached dependent parameter. | |
| void | erase_block (const BlockName &name) |
| Erases a block and removes all associated aliases from metadata. | |
Convenience overloads (std::string / const char*) | |
Thin wrappers around the std::string_view / BlockName API. These overloads exist purely for ergonomics so callers can pass
| |
| void | erase_block (const std::string &name) |
| Erase by name/alias (std::string overload). | |
| void | erase_block (const char *name) |
| Erase by name/alias (C-string overload). | |
| bool | contains (const std::string &name) const |
| Alias-aware existence check (std::string overload). | |
| bool | contains (const char *name) const |
| Alias-aware existence check (C-string overload). | |
| std::shared_ptr< Block > & | at (const std::string &name) |
| Alias-aware block access (std::string overload). | |
| const std::shared_ptr< Block > & | at (const std::string &name) const |
| Alias-aware block access (std::string overload, const). | |
| std::shared_ptr< Block > & | at (const char *name) |
| Alias-aware block access (C-string overload). | |
| const std::shared_ptr< Block > & | at (const char *name) const |
| Alias-aware block access (C-string overload, const). | |
| void | emplace (const std::string &name, std::shared_ptr< Block > blk) |
| Insert/replace a block using a raw string name (converted to BlockName). | |
| void | emplace (const char *name, std::shared_ptr< Block > blk) |
| Insert/replace a block using a C-string name (converted to BlockName). | |
| bool | has_param (const std::string &block, const LhaID &id) const |
| Parameter existence check (std::string overload). | |
| bool | has_param (const char *block, const LhaID &id) const |
| Parameter existence check (C-string overload). | |
| scalar_t | getValue (const std::string &block, const LhaID &id) const |
| Value getter (std::string overload). | |
| scalar_t | getValue (const char *block, const LhaID &id) const |
| Value getter (C-string overload). | |
| void | setValue (const std::string &block, const LhaID &id, scalar_t v) |
| Value setter (std::string overload). | |
| void | setValue (const char *block, const LhaID &id, scalar_t v) |
| Value setter (C-string overload). | |
| void | remove_item (const std::string &block, const LhaID &id) |
| Remove parameter (std::string overload). | |
| void | remove_item (const char *block, const LhaID &id) |
| Remove parameter (C-string overload). | |
| bool | has_scale (const std::string &block) const |
| Scale existence check (std::string overload). | |
| bool | has_scale (const char *block) const |
| Scale existence check (C-string overload). | |
| double | get_scale (const std::string &block) const |
| Scale getter (std::string overload). | |
| double | get_scale (const char *block) const |
| Scale getter (C-string overload). | |
Friends | |
| std::shared_ptr< BlockAccessor > | operator+ (std::shared_ptr< BlockAccessor > lhs, std::shared_ptr< BlockAccessor > rhs) |
| Merges two block accessors with no conflict allowed. | |
| std::shared_ptr< BlockAccessor > | operator>> (std::shared_ptr< BlockAccessor > lhs, std::shared_ptr< BlockAccessor > rhs) |
Merges two accessors with priority given to lhs. | |
| std::ostream & | operator<< (std::ostream &, std::shared_ptr< BlockAccessor >) |
| Stream output operator for BlockAccessor. | |
Alias-aware container / façade over several parameter blocks.
A BlockAccessor stores blocks under canonical internal keys while exposing a more user-friendly interface based on BlockName aliases.
Main features:
std::unordered_map, direct manipulation of the base map may desynchronize alias metadata (alias_to_key_, key_to_name_). Prefer the dedicated API. Definition at line 61 of file BlockAccessor.h.
| using BlockAccessor::base_t = std::unordered_map<std::string, std::shared_ptr<Block> > |
Underlying associative container type.
Definition at line 65 of file BlockAccessor.h.
Alias-aware mutable access to a block.
| block_name | Name or alias of the block. |
| std::invalid_argument | if the block cannot be resolved. |
Definition at line 517 of file BlockAccessor.cpp.
Alias-aware const access to a block.
| block_name | Name or alias of the block. |
| std::invalid_argument | if the block cannot be resolved. |
Definition at line 524 of file BlockAccessor.cpp.
|
inline |
Alias-aware block access (C-string overload).
Definition at line 534 of file BlockAccessor.h.
|
inline |
Alias-aware block access (C-string overload, const).
Definition at line 536 of file BlockAccessor.h.
|
inline |
Alias-aware block access (std::string overload).
Definition at line 530 of file BlockAccessor.h.
|
inline |
Alias-aware block access (std::string overload, const).
Definition at line 532 of file BlockAccessor.h.
| bool BlockAccessor::contains | ( | const BlockName & | block_name | ) | const |
Checks whether a block exists (alias-aware).
This method resolves aliases through the internal alias map instead of using the raw underlying map lookup.
| block_name | Name (or aliases) of the block. |
Definition at line 513 of file BlockAccessor.cpp.
|
inline |
Alias-aware existence check (C-string overload).
Definition at line 527 of file BlockAccessor.h.
|
inline |
Alias-aware existence check (std::string overload).
Definition at line 525 of file BlockAccessor.h.
| std::shared_ptr< BlockAccessor > BlockAccessor::deep_clone_plain | ( | ) | const |
Deep-copy all stored blocks as independent plain blocks.
The clone duplicates Parameter payloads and preserves block names/aliases and scales. It deliberately does not share observer/dependency links.
Definition at line 386 of file BlockAccessor.cpp.
| void BlockAccessor::detach_block | ( | const BlockName & | block_name | ) |
Detaches a dependent block from its upstream dependencies.
This method resolves the block, checks that it is actually a DependentBlock, and then calls DependentBlock::detach().
Detaching keeps the current cached contents of the block but removes the active dependency links to source blocks until reattachment.
| block_name | Name of the block to detach. If the resolved block is not a DependentBlock, do nothing. |
Definition at line 398 of file BlockAccessor.cpp.
Detaches a dependent parameter from its upstream dependencies.
The target parameter is retrieved from the given block, dynamically cast to DependentParameter, and then DependentParameter::detach() is called.
| block_name | Name of the block containing the parameter. |
| id | LHA identifier of the parameter to detach. If the resolved parameter is not a DependentParameter, do nothing. |
Definition at line 420 of file BlockAccessor.cpp.
Inserts or replaces a block, updating alias metadata.
The block is stored under a canonical internal key chosen from its aliases (or merged into an existing key if one alias is already known).
After insertion, Block::bind_self() is called on the stored block so it can later retrieve a valid weak self reference.
| name | Logical block name (possibly with several aliases). |
| blk | Block instance to store. |
Definition at line 361 of file BlockAccessor.cpp.
|
inline |
Insert/replace a block using a C-string name (converted to BlockName).
Definition at line 541 of file BlockAccessor.h.
|
inline |
Insert/replace a block using a raw string name (converted to BlockName).
Definition at line 539 of file BlockAccessor.h.
| void BlockAccessor::erase_block | ( | const BlockName & | name | ) |
Erases a block and removes all associated aliases from metadata.
If the name cannot be resolved, this is a no-op.
| name | Block name or alias. |
Definition at line 594 of file BlockAccessor.cpp.
|
inline |
Erase by name/alias (C-string overload).
Definition at line 522 of file BlockAccessor.h.
|
inline |
Erase by name/alias (std::string overload).
Definition at line 520 of file BlockAccessor.h.
| std::vector< std::string > BlockAccessor::get_all_dependent_block_names | ( | const BlockName & | block_name | ) | const |
Returns all transitive dependent block names observing a block.
Starting from block_name, this recursively follows block observers in the downstream direction. The returned list contains each dependent block name at most once.
| block_name | Name or alias of the block to inspect. |
| std::invalid_argument | if block_name cannot be resolved. |
Definition at line 353 of file BlockAccessor.cpp.
| std::vector< std::string > BlockAccessor::get_all_source_block_names | ( | const BlockName & | block_name | ) | const |
Returns all transitive source block names of a block.
Starting from block_name, this recursively follows source-block links through every reachable DependentBlock. The returned list contains each upstream block name at most once.
| block_name | Name or alias of the block to inspect. |
| std::invalid_argument | if block_name cannot be resolved. |
Definition at line 346 of file BlockAccessor.cpp.
| std::unordered_set< ParamId > BlockAccessor::get_all_source_parameters | ( | const std::unordered_set< ParamId > & | param_ids | ) | const |
Recursively finds all leaf source parameters behind a set of parameters.
Starting from each input ParamId, this method recursively explores:
Parameter::get_source_parameters(),Block::get_source_blocks().A parameter is considered a leaf if:
| param_ids | Initial set of parameters to inspect. |
Definition at line 187 of file BlockAccessor.cpp.
| std::unordered_set< BlockName > BlockAccessor::get_block_names | ( | ) | const |
Returns the set of all known block names.
This returns the values stored in the alias metadata table key_to_name_, not the raw keys of the underlying unordered_map.
Definition at line 48 of file BlockAccessor.cpp.
| std::unordered_map< std::string, std::shared_ptr< Block > > BlockAccessor::get_block_sources | ( | const BlockName & | block_name | ) | const |
Returns the source blocks of a given block.
For plain Block objects, this is usually an empty map. For DependentBlock objects, this returns the actual dependency map.
| block_name | Name of the block. |
| If | the block does not exist. |
Definition at line 177 of file BlockAccessor.cpp.
| std::vector< std::string > BlockAccessor::get_dependent_block_names | ( | const BlockName & | block_name | ) | const |
Returns the direct dependent block names observing a block.
This method follows the block-observer graph in the downstream direction. It returns the blocks that are directly notified when block_name changes. In practice, these are the direct dependent blocks built on top of the inspected block.
| block_name | Name or alias of the block to inspect. |
| std::invalid_argument | if block_name cannot be resolved. |
Definition at line 336 of file BlockAccessor.cpp.
| std::unordered_map< ParamId, std::shared_ptr< Parameter > > BlockAccessor::get_parameter_sources | ( | const BlockName & | block_name, |
| LhaID | id | ||
| ) | const |
Returns the source parameters of a given parameter.
For plain Parameter objects, this is usually an empty map. For DependentParameter objects, this returns the actual source parameters.
| block_name | Name of the block containing the parameter. |
| id | LHA identifier of the parameter. |
| If | the block or parameter does not exist. |
Definition at line 182 of file BlockAccessor.cpp.
| double BlockAccessor::get_scale | ( | const BlockName & | block_name | ) | const |
Returns the scale attached to a given block.
Delegates to Block::get_scale() after resolving the block.
| block_name | Name of the block. |
| If | the block does not exist or if the block has no scale set. |
Definition at line 98 of file BlockAccessor.cpp.
|
inline |
Scale getter (C-string overload).
Definition at line 571 of file BlockAccessor.h.
|
inline |
Scale getter (std::string overload).
Definition at line 569 of file BlockAccessor.h.
| std::vector< std::string > BlockAccessor::get_source_block_names | ( | const BlockName & | block_name | ) | const |
Returns the direct source block names of a block.
For a plain Block this returns an empty vector. For a DependentBlock this returns the direct upstream blocks currently used by its active dependency graph, converted to display names.
| block_name | Name or alias of the block to inspect. |
| std::invalid_argument | if block_name cannot be resolved. |
Definition at line 326 of file BlockAccessor.cpp.
Returns all current scalar values stored in a block.
Each stored parameter is converted to its current scalar value through Parameter::get_val().
| blockName | Name of the block. |
| std::invalid_argument | if the block does not exist. |
Definition at line 36 of file BlockAccessor.cpp.
| std::shared_ptr< Parameter > BlockAccessor::getParameter | ( | const BlockName & | blockName, |
| LhaID | id | ||
| ) | const |
Retrieves the full Parameter object stored in a block.
| blockName | Name of the block. |
| id | LHA identifier of the parameter. |
| std::invalid_argument | if the block cannot be resolved. If the block exists but the parameter does not, the underlying Block::retrieve() may log and/or throw. |
Definition at line 7 of file BlockAccessor.cpp.
Retrieves the current value of a parameter from a block.
This is equivalent to:
| blockName | Name of the block. |
| pdgCode | LHA identifier of the parameter. |
| std::invalid_argument | if the block cannot be resolved. If the block exists but the parameter does not, the underlying Block::retrieve() may log and/or throw. |
Definition at line 3 of file BlockAccessor.cpp.
Value getter (C-string overload).
Definition at line 551 of file BlockAccessor.h.
Value getter (std::string overload).
Definition at line 549 of file BlockAccessor.h.
Checks whether a given parameter exists inside a named block.
This method first resolves the block name through the alias system, then delegates to Block::contains(id).
| blockName | Name (or alias set) of the block. |
| pdgCode | LHA identifier of the parameter inside the block. |
Definition at line 11 of file BlockAccessor.cpp.
|
inline |
Parameter existence check (C-string overload).
Definition at line 546 of file BlockAccessor.h.
|
inline |
Parameter existence check (std::string overload).
Definition at line 544 of file BlockAccessor.h.
| bool BlockAccessor::has_scale | ( | const BlockName & | block_name | ) | const |
Checks whether a given block has a scale attached.
| block_name | Name of the block. |
| If | the block does not exist. |
Definition at line 106 of file BlockAccessor.cpp.
|
inline |
Scale existence check (C-string overload).
Definition at line 566 of file BlockAccessor.h.
|
inline |
Scale existence check (std::string overload).
Definition at line 564 of file BlockAccessor.h.
| bool BlockAccessor::is_dependent_block | ( | const BlockName & | block_name | ) | const |
Checks whether a block is implemented as a DependentBlock.
This method only inspects the block object itself. It does not force a recomputation and it does not infer dependency status from the presence of observers. A block is considered dependent exactly when the stored block can be dynamically cast to DependentBlock.
| block_name | Name or alias of the block to inspect. |
| std::invalid_argument | if block_name cannot be resolved. |
Definition at line 322 of file BlockAccessor.cpp.
| std::shared_ptr< BlockAccessor > BlockAccessor::operator[] | ( | std::unordered_set< BlockName > | block_names | ) |
Extracts a subset of blocks into a new accessor.
This operation performs a shallow copy of block shared pointers: the returned accessor points to the same underlying Block objects.
| block_names | Set of block names to extract. |
| If | one requested block does not exist. |
Definition at line 65 of file BlockAccessor.cpp.
| void BlockAccessor::reattach_block | ( | const BlockName & | block_name | ) |
Reattaches a previously detached dependent block to its saved sources.
This method resolves the block, checks that it is a DependentBlock, and then calls DependentBlock::reattach().
| block_name | Name of the block to reattach. If the resolved block is not a DependentBlock, do nothing. |
Definition at line 409 of file BlockAccessor.cpp.
Reattaches a previously detached dependent parameter.
The target parameter is retrieved from the given block, dynamically cast to DependentParameter, and then DependentParameter::reattach() is called.
| block_name | Name of the block containing the parameter. |
| id | LHA identifier of the parameter to reattach. If the resolved parameter is not a DependentParameter, do nothing. |
Definition at line 431 of file BlockAccessor.cpp.
Removes one parameter from a block.
Delegates to Block::remove(id) which performs proper dependency cleanup.
Behavior of this overload:
| block_name | Name of the block. |
| id | LHA identifier of the parameter to remove. |
Definition at line 56 of file BlockAccessor.cpp.
|
inline |
Remove parameter (C-string overload).
Definition at line 561 of file BlockAccessor.h.
|
inline |
Remove parameter (std::string overload).
Definition at line 559 of file BlockAccessor.h.
| void BlockAccessor::setParameter | ( | const BlockName & | blockName, |
| LhaID | id, | ||
| std::shared_ptr< Parameter > | source | ||
| ) |
Inserts or updates a full Parameter object in a block.
Delegates to Block::store_or_assign(id, source) on the resolved block.
| blockName | Name of the block. |
| id | LHA identifier of the parameter. |
| source | Shared pointer to the source parameter object. |
| std::invalid_argument | if the block does not exist. |
Definition at line 28 of file BlockAccessor.cpp.
Sets the value of a parameter inside an existing block.
Behavior:
Block::assign(id, value),std::invalid_argument.| blockName | Name of the target block. |
| pdgCode | LHA identifier of the parameter. |
| value | New scalar value. |
Definition at line 16 of file BlockAccessor.cpp.
Value setter (C-string overload).
Definition at line 556 of file BlockAccessor.h.
Value setter (std::string overload).
Definition at line 554 of file BlockAccessor.h.
|
friend |
Merges two block accessors with no conflict allowed.
All blocks from lhs and rhs are deep-copied into a new accessor using the Block(std::shared_ptr<Block>) constructor.
If both accessors contain a block with the same resolved name, this is considered an error.
| lhs | Left-hand accessor. |
| rhs | Right-hand accessor. |
| Via | logging/error handling if overlapping block names are found. |
Definition at line 82 of file BlockAccessor.cpp.
|
friend |
Stream output operator for BlockAccessor.
Prints all block names and their parameter values using BlockAccessor::getAllValues:
| os | Output stream. |
| ba | Shared pointer to the BlockAccessor to print. |
Definition at line 165 of file BlockAccessor.cpp.
|
friend |
Merges two accessors with priority given to lhs.
Semantics:
| lhs | Priority accessor. |
| rhs | Secondary accessor. |
Definition at line 110 of file BlockAccessor.cpp.