Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Block Class Reference

#include <Block.h>

Inheritance diagram for Block:
Collaboration diagram for Block:

Public Member Functions

 Block ()=default
 Default constructor.
 
 Block (std::shared_ptr< Block > other)
 Copy-like constructor from another block.
 
BlockName get_name () const
 Returns the name of the block.
 
void store (const LhaID &id, std::shared_ptr< Parameter > param) override
 Stores a new parameter under the given LHA id.
 
void assign (const LhaID &key, std::shared_ptr< Parameter > param) override
 Replaces the payload of an existing parameter from another parameter object.
 
void assign (const LhaID &key, scalar_t value)
 Sets the expected value of an existing parameter.
 
void store_or_assign (const LhaID &key, std::shared_ptr< Parameter > param) override
 Stores a parameter if absent, otherwise assigns into the existing one.
 
bool contains (const LhaID &key) const override
 Checks whether the block contains a parameter with the given id.
 
std::shared_ptr< Parameterretrieve (const LhaID &id) override
 Retrieves a stored parameter by id.
 
void remove (const LhaID &key) override
 Removes a parameter and clears its downstream dependency subtree.
 
std::unordered_set< LhaIDgetAllIDs ()
 Returns the set of all parameter ids stored in the block.
 
const std::map< LhaID, std::shared_ptr< Parameter > > & getItems ()
 Returns the internal parameter map.
 
void set_owner (ParameterType type)
 Sets the owner ParameterType on all contained parameters.
 
void addObserver (std::shared_ptr< Block > observer)
 Adds a block observer if not already present.
 
void removeObserver (std::shared_ptr< Block > observer)
 Removes a previously registered observer block.
 
void notifyObservers ()
 Notifies all observer blocks that this block has changed.
 
std::vector< std::shared_ptr< Block > > getObservers () const
 Returns the current list of observer blocks.
 
virtual void init ()
 Initialization hook.
 
virtual void update ()
 Updates the block.
 
virtual void destroy ()
 Destroys the block and its downstream block dependencies.
 
virtual void freeze ()
 Freezes all parameters contained in the block.
 
virtual void unfreeze ()
 Unfreezes all parameters contained in the block.
 
void copy (std::shared_ptr< Block > other)
 Copies the content and metadata from another block.
 
std::shared_ptr< Blockdeep_clone_plain () const
 Deep-copies this block as a plain independent block.
 
virtual void clear_above ()
 Clears parameter dependencies above this block.
 
virtual void clear_below ()
 Clears parameter dependencies below this block.
 
bool has_scale ()
 Returns whether the block has an associated scale.
 
void set_scale (double scale)
 Sets the block-wide scale.
 
double get_scale ()
 Returns the block-wide scale.
 
void erase_local (const LhaID &id)
 Erases an entry from the local storage map only.
 
virtual std::unordered_map< std::string, std::shared_ptr< Block > > get_source_blocks () const
 Returns the source blocks of this block.
 
virtual void ensure_up_to_date ()
 Ensures that the block content is up to date.
 
void bind_self (std::shared_ptr< Block > self)
 Binds an explicit self shared_ptr to the block.
 
 ~Block ()
 Destructor.
 
- Public Member Functions inherited from IStorage< LhaID, Parameter >
virtual ~IStorage ()=default
 

Public Attributes

BlockName blockname {""}
 Name of the block (e.g. "SMINPUTS", "MASS", "FWCOEF"...)
 

Protected Member Functions

std::weak_ptr< Blockself_weak ()
 Optional explicit self-reference used to rebind owner_block on contained parameters.
 

Protected Attributes

std::vector< std::shared_ptr< Block > > observers
 
std::map< LhaID, std::shared_ptr< Parameter > > items
 List of observing blocks notified through notifyObservers().
 
std::optional< double > scale
 Internal storage of parameters indexed by LHA id.
 
std::weak_ptr< Blockself_
 Optional block-wide scale.
 

Friends

std::ostream & operator<< (std::ostream &, std::shared_ptr< Block >)
 Stream output operator for a block.
 

Detailed Description

Definition at line 73 of file Block.h.

Constructor & Destructor Documentation

◆ Block() [1/2]

Block::Block ( )
default

Default constructor.

Constructs an empty block with no parameters, no observers, and no scale.

◆ Block() [2/2]

Block::Block ( std::shared_ptr< Block other)

Copy-like constructor from another block.

This constructor copies the content and metadata of other by delegating to copy(). Stored parameter pointers are copied as shared pointers.

After the copy, parameter owner-block links are rebound to this new block whenever a valid self reference is available.

Parameters
otherBlock to copy from.

Definition at line 50 of file Block.cpp.

◆ ~Block()

Block::~Block ( )
inline

Destructor.

The destructor itself does not perform dependency teardown. Use destroy() when graph-level destruction is required.

Definition at line 419 of file Block.h.

Member Function Documentation

◆ addObserver()

void Block::addObserver ( std::shared_ptr< Block observer)

Adds a block observer if not already present.

Observer uniqueness is checked by pointer identity.

Parameters
observerObserver block to add.

Definition at line 4 of file Block.cpp.

◆ assign() [1/2]

void Block::assign ( const LhaID key,
scalar_t  value 
)

Sets the expected value of an existing parameter.

This calls Parameter::set_expected(value) on the stored parameter.

Current notification behavior:

Parameters
keyIdentifier of the parameter to update.
valueNew value.

Definition at line 90 of file Block.cpp.

◆ assign() [2/2]

void Block::assign ( const LhaID key,
std::shared_ptr< Parameter param 
)
overridevirtual

Replaces the payload of an existing parameter from another parameter object.

This does not replace the shared pointer stored in the block. Instead, it copies the numerical/configuration payload into the already stored destination parameter using Parameter::overwrite_payload_from(...).

Current notification behavior:

  • the destination parameter notifies its own observers,
  • block-level observers are reached indirectly through the parameter/owner-block chain,
  • no extra explicit Block::notifyObservers() call is performed here.
Parameters
keyIdentifier of the parameter to overwrite.
paramSource parameter whose payload is copied.

Implements IStorage< LhaID, Parameter >.

Reimplemented in DependentBlock.

Definition at line 79 of file Block.cpp.

◆ bind_self()

void Block::bind_self ( std::shared_ptr< Block self)
inline

Binds an explicit self shared_ptr to the block.

This is used to make owner-block links available even in situations where shared_from_this() is not yet safe or convenient.

After binding, all currently stored parameters are rebound to this block as their owner block.

Parameters
selfShared pointer referring to this block instance.

Definition at line 404 of file Block.h.

◆ clear_above()

void Block::clear_above ( )
virtual

Clears parameter dependencies above this block.

Delegates clear_above() to all contained parameters.

Reimplemented in DependentBlock.

Definition at line 170 of file Block.cpp.

◆ clear_below()

void Block::clear_below ( )
virtual

Clears parameter dependencies below this block.

A snapshot of current parameter pointers is built first to avoid iterator invalidation during recursive dependency clearing.

Reimplemented in DependentBlock.

Definition at line 176 of file Block.cpp.

◆ contains()

bool Block::contains ( const LhaID key) const
overridevirtual

Checks whether the block contains a parameter with the given id.

Before the lookup, the block is forced up-to-date through ensure_up_to_date(). For a plain Block this is a no-op, but for DependentBlock this may trigger lazy recomputation.

Parameters
keyLHA identifier.
Returns
True if the parameter exists.

Implements IStorage< LhaID, Parameter >.

Definition at line 106 of file Block.cpp.

◆ copy()

void Block::copy ( std::shared_ptr< Block other)

Copies the content and metadata from another block.

Copied elements:

  • storage map,
  • block name,
  • scale if present.

Stored parameter pointers are copied as shared pointers. If this block is already self-bound, copied parameters have their owner-block link rebound to this block.

Parameters
otherSource block.

Definition at line 142 of file Block.cpp.

◆ deep_clone_plain()

std::shared_ptr< Block > Block::deep_clone_plain ( ) const

Deep-copies this block as a plain independent block.

All contained Parameter payloads are duplicated, observer links and owner-block links are not shared with the source block. Dependency graph objects are intentionally not cloned here; dependent blocks are rebuilt by the owning Parameters strategy inside each runtime context.

Definition at line 153 of file Block.cpp.

◆ destroy()

void Block::destroy ( )
virtual

Destroys the block and its downstream block dependencies.

Current behavior:

  • snapshots and detaches block observers,
  • clears parameter-side downstream dependencies,
  • clears local storage,
  • recursively destroys dependent observer blocks.
Note
This is explicit graph teardown logic; it is not automatically called by the destructor.

Reimplemented in DependentBlock.

Definition at line 205 of file Block.cpp.

◆ ensure_up_to_date()

virtual void Block::ensure_up_to_date ( )
inlinevirtual

Ensures that the block content is up to date.

For a plain Block this is a no-op. DependentBlock overrides it to implement lazy recomputation.

Reimplemented in DependentBlock.

Definition at line 391 of file Block.h.

◆ erase_local()

void Block::erase_local ( const LhaID id)

Erases an entry from the local storage map only.

Unlike remove(), this does not clear any dependency relationships and does not destroy downstream blocks. It is a pure local erase.

Parameters
idIdentifier to erase.

Definition at line 75 of file Block.cpp.

◆ freeze()

void Block::freeze ( )
virtual

Freezes all parameters contained in the block.

This delegates to Parameter::freeze() on each stored parameter.

Reimplemented in DependentBlock.

Definition at line 38 of file Block.cpp.

◆ get_name()

BlockName Block::get_name ( ) const
inline

Returns the name of the block.

Returns
Block name.

Definition at line 102 of file Block.h.

◆ get_scale()

double Block::get_scale ( )

Returns the block-wide scale.

Returns
The scale value.
Note
Accessing an unset scale is considered a logic error.

Definition at line 198 of file Block.cpp.

◆ get_source_blocks()

std::unordered_map< std::string, std::shared_ptr< Block > > Block::get_source_blocks ( ) const
virtual

Returns the source blocks of this block.

Plain blocks have no source blocks, so the default implementation returns an empty map.

Returns
Source block map.

Reimplemented in DependentBlock.

Definition at line 216 of file Block.cpp.

◆ getAllIDs()

std::unordered_set< LhaID > Block::getAllIDs ( )

Returns the set of all parameter ids stored in the block.

The block is ensured up-to-date before extracting the ids.

Returns
Set of stored ids.

Definition at line 132 of file Block.cpp.

◆ getItems()

const std::map< LhaID, std::shared_ptr< Parameter > > & Block::getItems ( )

Returns the internal parameter map.

The block is ensured up-to-date before returning the map.

Returns
Const reference to the internal storage map.

Definition at line 137 of file Block.cpp.

◆ getObservers()

std::vector< std::shared_ptr< Block > > Block::getObservers ( ) const

Returns the current list of observer blocks.

Returns
Observer list.

Definition at line 27 of file Block.cpp.

◆ has_scale()

bool Block::has_scale ( )

Returns whether the block has an associated scale.

Returns
True if a scale is set.

Definition at line 187 of file Block.cpp.

◆ init()

virtual void Block::init ( )
inlinevirtual

Initialization hook.

Plain blocks do nothing by default. Derived classes may override this to register dependencies or pre-fill content.

Reimplemented in DependentBlock.

Definition at line 262 of file Block.h.

◆ notifyObservers()

void Block::notifyObservers ( )

Notifies all observer blocks that this block has changed.

For each non-null observer, observer->update() is called. Null observer entries are cleaned afterward.

Definition at line 17 of file Block.cpp.

◆ remove()

void Block::remove ( const LhaID key)
overridevirtual

Removes a parameter and clears its downstream dependency subtree.

The parameter is first asked to clear its own downstream dependencies via Parameter::clear_below(), then removed from the block.

After that, all observer blocks currently attached to this block are destroyed recursively.

Parameters
keyIdentifier of the parameter to remove.

Implements IStorage< LhaID, Parameter >.

Definition at line 113 of file Block.cpp.

◆ removeObserver()

void Block::removeObserver ( std::shared_ptr< Block observer)

Removes a previously registered observer block.

Removal is performed by pointer identity.

Parameters
observerObserver block to remove.

Definition at line 11 of file Block.cpp.

◆ retrieve()

std::shared_ptr< Parameter > Block::retrieve ( const LhaID id)
overridevirtual

Retrieves a stored parameter by id.

The block is first ensured up-to-date. If the id is missing, an error is logged.

Parameters
idLHA identifier to retrieve.
Returns
Shared pointer to the stored parameter.

Implements IStorage< LhaID, Parameter >.

Definition at line 54 of file Block.cpp.

◆ self_weak()

std::weak_ptr< Block > Block::self_weak ( )
inlineprotected

Optional explicit self-reference used to rebind owner_block on contained parameters.

Returns the best available weak self-reference.

Priority:

  • explicit binding through bind_self(),
  • fallback to shared_from_this() when available,
  • empty weak_ptr otherwise.
Returns
Weak self-reference.

Definition at line 453 of file Block.h.

◆ set_owner()

void Block::set_owner ( ParameterType  type)

Sets the owner ParameterType on all contained parameters.

This is forwarded to each stored parameter via Parameter::set_owner(type).

Parameters
typeOwner type to apply.

Definition at line 126 of file Block.cpp.

◆ set_scale()

void Block::set_scale ( double  scale)

Sets the block-wide scale.

Parameters
scaleScale to assign.
Note
Setting the scale twice is considered a logic error.

Definition at line 191 of file Block.cpp.

◆ store()

void Block::store ( const LhaID id,
std::shared_ptr< Parameter param 
)
overridevirtual

Stores a new parameter under the given LHA id.

If the key already exists, the parameter is not overwritten and a debug message is emitted.

If the block has been bound to itself through bind_self(), the stored parameter receives this block as owner block.

Parameters
idLHA identifier of the parameter.
paramParameter object to store.

Implements IStorage< LhaID, Parameter >.

Definition at line 64 of file Block.cpp.

◆ store_or_assign()

void Block::store_or_assign ( const LhaID key,
std::shared_ptr< Parameter param 
)
overridevirtual

Stores a parameter if absent, otherwise assigns into the existing one.

This is a convenience method:

Parameters
keyIdentifier of the parameter.
paramParameter to store or assign.

Implements IStorage< LhaID, Parameter >.

Definition at line 98 of file Block.cpp.

◆ unfreeze()

void Block::unfreeze ( )
virtual

Unfreezes all parameters contained in the block.

This delegates to Parameter::unfreeze() on each stored parameter.

Reimplemented in DependentBlock.

Definition at line 44 of file Block.cpp.

◆ update()

void Block::update ( )
virtual

Updates the block.

Default behavior: calls update() on every contained parameter.

For plain blocks this is an eager propagation method. Dependent blocks override this with lazy dirty-marking semantics.

Reimplemented in DependentBlock.

Definition at line 31 of file Block.cpp.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
std::shared_ptr< Block ba 
)
friend

Stream output operator for a block.

Prints block content in a human-readable form:

6: 172.5
24: 80.379
const Prototype MASS
Definition Block.h:73
Parameters
osOutput stream.
baBlock to print.
Returns
Output stream.

Definition at line 413 of file Block.cpp.

Member Data Documentation

◆ blockname

BlockName Block::blockname {""}

Name of the block (e.g. "SMINPUTS", "MASS", "FWCOEF"...)

Definition at line 76 of file Block.h.

◆ items

std::map<LhaID, std::shared_ptr<Parameter> > Block::items
protected

List of observing blocks notified through notifyObservers().

Definition at line 438 of file Block.h.

◆ observers

std::vector<std::shared_ptr<Block> > Block::observers
protected

Definition at line 437 of file Block.h.

◆ scale

std::optional<double> Block::scale
protected

Internal storage of parameters indexed by LHA id.

Definition at line 439 of file Block.h.

◆ self_

std::weak_ptr<Block> Block::self_
protected

Optional block-wide scale.

Definition at line 441 of file Block.h.


The documentation for this class was generated from the following files: