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

Block whose content is derived from one or more source blocks. More...

#include <Block.h>

Inheritance diagram for DependentBlock:
Collaboration diagram for DependentBlock:

Public Member Functions

 DependentBlock (const std::unordered_map< std::string, std::shared_ptr< Block > > &sources, DepUpdateFunc recalculateFunc)
 Constructs a dependent block from source blocks and a recomputation callback.
 
bool dependsOn (const std::string &blockName)
 Checks whether this dependent block uses a given source block name.
 
void init () override
 Initializes the dependency graph for this block.
 
void update () override
 Marks the block as dirty.
 
void freeze () override
 Freezes the block and all contained parameters.
 
void unfreeze () override
 Unfreezes the block and contained parameters.
 
void detach ()
 Temporarily detaches this block from its dependency graph.
 
void reattach ()
 Reattaches a previously detached dependent block.
 
 ~DependentBlock ()
 Destructor.
 
void assign (const LhaID &key, std::shared_ptr< Parameter > param)
 Overwrites the payload of a local parameter without triggering block-level notification.
 
void assign (const LhaID &key, double value)
 Assigns a new scalar value to a local parameter.
 
std::unordered_map< std::string, std::shared_ptr< Block > > get_source_blocks () const override
 Returns the map of source blocks for this dependent block.
 
void clear_above () override
 Clears upstream block dependencies.
 
void clear_below () override
 Clears downstream block dependencies.
 
void destroy () override
 Destroys this dependent block and its downstream block dependencies.
 
void mark_dirty ()
 Marks this block dirty and propagates the dirty state downstream.
 
void ensure_up_to_date () override
 Ensures this dependent block is up to date.
 
- Public Member Functions inherited from Block
 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, 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.
 
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.
 
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.
 
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
 

Additional Inherited Members

- Public Attributes inherited from Block
BlockName blockname {""}
 Name of the block (e.g. "SMINPUTS", "MASS", "FWCOEF"...)
 
- Protected Member Functions inherited from Block
std::weak_ptr< Blockself_weak ()
 Optional explicit self-reference used to rebind owner_block on contained parameters.
 
- Protected Attributes inherited from Block
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.
 

Detailed Description

Block whose content is derived from one or more source blocks.

A DependentBlock is a lazily recomputed block:

The actual recomputation logic is provided by a user callback of type DepUpdateFunc.

Additional features:

  • freeze/unfreeze support with deferred update,
  • detach/reattach support to temporarily disable the dependency graph,
  • recursive dirty propagation to downstream dependent blocks and parameters.
See also
Block
DepUpdateFunc
BlockSrc

Definition at line 481 of file Block.h.

Constructor & Destructor Documentation

◆ DependentBlock()

DependentBlock::DependentBlock ( const std::unordered_map< std::string, std::shared_ptr< Block > > &  sources,
DepUpdateFunc  recalculateFunc 
)
inlineexplicit

Constructs a dependent block from source blocks and a recomputation callback.

The constructor only stores the dependency data. Actual observer registration is performed later by init().

Parameters
sourcesSource blocks used as inputs.
recalculateFuncCallback used to rebuild/update this block.

Definition at line 492 of file Block.h.

◆ ~DependentBlock()

DependentBlock::~DependentBlock ( )

Destructor.

Unregisters this dependent block from its source blocks when still attached.

Definition at line 245 of file Block.cpp.

Member Function Documentation

◆ assign() [1/2]

void DependentBlock::assign ( const LhaID key,
double  value 
)

Assigns a new scalar value to a local parameter.

This is the dependent-block-local variant used during recomputation.

Parameters
keyIdentifier to update.
valueNew value.

Definition at line 269 of file Block.cpp.

◆ assign() [2/2]

void DependentBlock::assign ( const LhaID key,
std::shared_ptr< Parameter param 
)
virtual

Overwrites the payload of a local parameter without triggering block-level notification.

This is a lighter-weight internal assign than Block::assign(...): the destination parameter payload is overwritten, but this method does not explicitly notify downstream blocks.

Parameters
keyIdentifier to overwrite.
paramSource parameter payload.

Reimplemented from Block.

Definition at line 256 of file Block.cpp.

◆ clear_above()

void DependentBlock::clear_above ( )
overridevirtual

Clears upstream block dependencies.

Unregisters this block from all current source blocks.

Reimplemented from Block.

Definition at line 280 of file Block.cpp.

◆ clear_below()

void DependentBlock::clear_below ( )
overridevirtual

Clears downstream block dependencies.

This first detaches from sources, then recursively asks observing blocks to clear their own downstream dependencies.

Reimplemented from Block.

Definition at line 288 of file Block.cpp.

◆ dependsOn()

bool DependentBlock::dependsOn ( const std::string &  blockName)

Checks whether this dependent block uses a given source block name.

Parameters
blockNameSource block name.
Returns
True if the source exists and is non-null.

Definition at line 299 of file Block.cpp.

◆ destroy()

void DependentBlock::destroy ( )
overridevirtual

Destroys this dependent block and its downstream block dependencies.

Current behavior:

  • detaches from sources,
  • clears downstream parameter dependencies,
  • clears local items,
  • recursively destroys observing blocks.

Reimplemented from Block.

Definition at line 303 of file Block.cpp.

◆ detach()

void DependentBlock::detach ( )

Temporarily detaches this block from its dependency graph.

Current behavior:

  • ensures the block is up to date before detaching,
  • unregisters this block from its source observers,
  • detaches dependent parameters when applicable,
  • clears source/recalculation state from the active dependency graph,
  • preserves a saved copy of the original dependency definition,
  • notifies downstream observers.

After detachment, the block behaves like a frozen snapshot of its current content.

See also
reattach

Definition at line 320 of file Block.cpp.

◆ ensure_up_to_date()

void DependentBlock::ensure_up_to_date ( )
inlineoverridevirtual

Ensures this dependent block is up to date.

If the block is dirty and not frozen, upstream dependent blocks are first ensured up to date, then the recomputation callback is executed, and finally downstream parameter/block observers are notified in a controlled way.

Reimplemented from Block.

Definition at line 656 of file Block.h.

◆ freeze()

void DependentBlock::freeze ( )
overridevirtual

Freezes the block and all contained parameters.

While frozen, updates are deferred.

Reimplemented from Block.

Definition at line 228 of file Block.cpp.

◆ get_source_blocks()

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

Returns the map of source blocks for this dependent block.

Returns
Source block map.

Reimplemented from Block.

Definition at line 276 of file Block.cpp.

◆ init()

void DependentBlock::init ( )
overridevirtual

Initializes the dependency graph for this block.

Registers this block as observer of all current source blocks. Must be called before the dependency graph is expected to function.

Reimplemented from Block.

Definition at line 220 of file Block.cpp.

◆ mark_dirty()

void DependentBlock::mark_dirty ( )

Marks this block dirty and propagates the dirty state downstream.

If the block is already dirty, nothing is done.

Propagation rules:

Definition at line 369 of file Block.cpp.

◆ reattach()

void DependentBlock::reattach ( )

Reattaches a previously detached dependent block.

Restores:

  • source blocks,
  • recomputation callback,
  • parameter dependency state,
  • observer registration to sources.

The block is then marked dirty again so that future accesses recompute from restored sources.

See also
detach

Definition at line 343 of file Block.cpp.

◆ unfreeze()

void DependentBlock::unfreeze ( )
overridevirtual

Unfreezes the block and contained parameters.

If an update was requested while frozen, the block is marked dirty again upon unfreeze.

Reimplemented from Block.

Definition at line 234 of file Block.cpp.

◆ update()

void DependentBlock::update ( )
overridevirtual

Marks the block as dirty.

Current behavior:

  • if frozen, records that an update must happen upon unfreeze,
  • otherwise propagates dirtiness downstream using mark_dirty().

This method does not recompute immediately.

Reimplemented from Block.

Definition at line 384 of file Block.cpp.


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