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

Parameter whose value is computed from other parameters and cached lazily. More...

#include <DependentParameter.h>

Inheritance diagram for DependentParameter:
Collaboration diagram for DependentParameter:

Public Member Functions

 DependentParameter (ParamId pid, std::unordered_map< ParamId, std::shared_ptr< Parameter > > sources, DepParamUpdateFunc recalculateFunc)
 Constructs a dependent parameter from its id, sources, and recomputation rule.
 
bool dependsOn (const ParamId &pid)
 Checks whether this parameter depends on a given source parameter.
 
void init ()
 Initializes observer registration on all source parameters.
 
void update () override
 Marks the parameter as dirty and propagates the update downstream.
 
void freeze () override
 Freezes the dependent parameter.
 
void unfreeze () override
 Unfreezes the dependent parameter.
 
void clear_above () override
 Detaches this parameter from all upstream source parameters.
 
void clear_below () override
 Clears this parameter and all downstream dependent parameters.
 
std::unordered_map< ParamId, std::shared_ptr< Parameter > > get_source_parameters () const override
 Returns the source parameters this dependent parameter currently uses.
 
scalar_t get_val () const override
 Returns the current cached value, recomputing it on demand if needed.
 
void mark_dirty ()
 Marks the cached value as dirty.
 
void ensure_up_to_date ()
 Recomputes the parameter if its cached value is stale.
 
void rebind (std::unordered_map< ParamId, std::shared_ptr< Parameter > > new_sources, DepParamUpdateFunc new_lambda)
 Replaces the dependency set and recomputation rule at runtime.
 
void detach ()
 Temporarily detaches all dependencies while keeping the current cached value.
 
void reattach ()
 Restores previously detached dependencies and recomputation rule.
 
 ~DependentParameter ()
 Destructor.
 
- Public Member Functions inherited from Parameter
 Parameter ()
 Default constructor.
 
 Parameter (ParamId id, scalar_t mean, scalar_t std_stat, scalar_t std_syst)
 Constructs a parameter from its identifier, value, and uncertainties.
 
 Parameter (const Parameter &other)
 Copy constructor that copies only scalar payload/metadata.
 
void set_mode (ParameterMode mode)
 Sets the parameter mode.
 
void set_std (scalar_t stat, scalar_t syst)
 Sets the statistical and systematic uncertainties.
 
void set_scale (double scale)
 Sets the parameter scale metadata.
 
void set_bin (std::pair< double, double > bin)
 Sets the binning metadata of the parameter.
 
void set_id (ParamId id)
 Replaces the identifier of the parameter.
 
void set_expected (scalar_t val)
 Sets the expected value and notifies dependents.
 
void set_expected_silent (scalar_t val)
 Sets the expected value without notifying observers.
 
scalar_t get_combined_std () const
 Returns the combined standard deviation.
 
std::pair< scalar_t, scalar_tget_std () const
 Returns statistical and systematic uncertainties separately.
 
double get_scale ()
 Returns the parameter scale metadata.
 
std::pair< double, double > get_bin ()
 Returns the parameter bin metadata.
 
ParamId get_id () const
 Returns the identifier of the parameter.
 
void set_owner (ParameterType type)
 Changes the owner ParameterType part of the identifier.
 
void set_shift (scalar_t shift)
 Sets the additive shift of the parameter.
 
void addObserver (std::shared_ptr< Parameter > observer)
 Adds an observer parameter.
 
void removeObserver (std::shared_ptr< Parameter > observer)
 Removes an observer parameter.
 
void notifyObservers ()
 Notifies downstream parameter observers and then the owner block.
 
void notifyParamObserversOnly ()
 Notifies only parameter observers.
 
void set_owner_block (std::weak_ptr< Block > owner)
 Sets the owning block of this parameter.
 
std::weak_ptr< Blockget_owner_block () const
 Returns the owning block of this parameter.
 
void overwrite_payload_from (const Parameter &other)
 Overwrites the numerical/configuration payload from another parameter.
 
Parameteroperator= (const Parameter &other)
 Assignment operator.
 
Parameteroperator+= (const Parameter &other)
 Adds another parameter payload to this one.
 
Parameteroperator*= (const scalar_t &scale)
 Multiplies the parameter by a scalar factor.
 
virtual ~Parameter ()=default
 Virtual destructor.
 

Additional Inherited Members

- Protected Attributes inherited from Parameter
ParamId id
 Unique identifier for the parameter.
 
scalar_t expected
 Expected value of the parameter.

 
scalar_t deviation_stat
 Statistical standard deviation.
 
scalar_t deviation_syst
 Systematic standard deviation.
 
scalar_t shift
 Additive shift applied when the parameter is SHIFTABLE.
 
ParameterMode mode
 Current operating mode.
 
std::vector< std::shared_ptr< Parameter > > observers
 Observers notified when this parameter changes.
 
std::weak_ptr< Blockowner_block
 Owning Block (if any) that this parameter belongs to.

 
std::optional< double > scale
 Optional renormalization scale associated with the parameter.
 
std::optional< std::pair< double, double > > binning
 Optional energy bin [low, high] associated with the parameter.
 

Detailed Description

Parameter whose value is computed from other parameters and cached lazily.

A DependentParameter stores:

  • a map of source parameters,
  • a ParamSrc helper wrapping these sources,
  • a recomputation lambda,
  • dirty/frozen flags controlling lazy updates.

Lifecycle:

  • after construction, init() must be called once the object is managed by std::shared_ptr,
  • init() registers the parameter as observer of all its sources,
  • when a source changes, update() marks the parameter dirty and propagates,
  • actual recomputation happens later in ensure_up_to_date(), usually triggered by get_val().

Freezing:

  • while frozen, recomputation is disabled,
  • updates are deferred through update_at_unfreeze,
  • once unfrozen, a pending update is replayed.

Detach / reattach:

  • detach() removes all active dependencies while keeping the last computed value,
  • reattach() restores the saved dependencies and recomputation rule.
Warning
Unlike Parameter::get_val(), this override currently returns the cached expected value directly after ensure_up_to_date(). It does not apply mode/shift logic from the base class.

Definition at line 80 of file DependentParameter.h.

Constructor & Destructor Documentation

◆ DependentParameter()

DependentParameter::DependentParameter ( ParamId  pid,
std::unordered_map< ParamId, std::shared_ptr< Parameter > >  sources,
DepParamUpdateFunc  recalculateFunc 
)
explicit

Constructs a dependent parameter from its id, sources, and recomputation rule.

The base Parameter is initialized with:

  • expected = 0
  • statistical uncertainty = 0
  • systematic uncertainty = 0

The constructor stores:

  • the active source map,
  • a ParamSrc wrapper over that map,
  • the recomputation lambda,
  • and a saved copy of sources/lambda used by detach() / reattach().

The parameter is initially marked dirty.

Note
This constructor does not register observers. Call init() once the object is owned by a std::shared_ptr.
Parameters
pidIdentifier of the dependent parameter.
sourcesSource parameters keyed by ParamId.
recalculateFuncCallback used to recompute this parameter.

Definition at line 4 of file DependentParameter.cpp.

◆ ~DependentParameter()

DependentParameter::~DependentParameter ( )

Destructor.

If the parameter is still initialized and can lock its self-reference, it unregisters itself from all currently active source parameters.

This prevents stale observer pointers from remaining in source parameters.

Definition at line 180 of file DependentParameter.cpp.

Member Function Documentation

◆ clear_above()

void DependentParameter::clear_above ( )
overridevirtual

Detaches this parameter from all upstream source parameters.

If the parameter has been initialized, this removes this dependent parameter from each source observer list.

This does not clear local downstream observers.

Reimplemented from Parameter.

Definition at line 24 of file DependentParameter.cpp.

◆ clear_below()

void DependentParameter::clear_below ( )
overridevirtual

Clears this parameter and all downstream dependent parameters.

Current behavior:

  • moves the current observer list to a local snapshot,
  • detaches from all source parameters via clear_above(),
  • if an owning block exists, removes this parameter entry locally from that block using owner_block->erase_local(id.code),
  • recursively calls clear_below() on downstream observers.
Note
The erase is performed with id.code, consistent with block storage being keyed by LhaID inside a block.

Reimplemented from Parameter.

Definition at line 32 of file DependentParameter.cpp.

◆ dependsOn()

bool DependentParameter::dependsOn ( const ParamId pid)

Checks whether this parameter depends on a given source parameter.

Parameters
pidIdentifier of the candidate source parameter.
Returns
True if pid is present in the current source map.

Definition at line 19 of file DependentParameter.cpp.

◆ detach()

void DependentParameter::detach ( )

Temporarily detaches all dependencies while keeping the current cached value.

Current behavior:

  • returns immediately if already detached,
  • forces one last recomputation via ensure_up_to_date(),
  • unregisters from all current sources,
  • clears the active source map,
  • rebuilds an empty ParamSrc wrapper,
  • resets the active recomputation lambda,
  • clears the dirty flag,
  • marks the dependency state as detached,
  • notifies downstream observers.

This is useful when one wants to “freeze” the dependency graph structure while preserving the last computed numeric value.

See also
reattach()

Definition at line 138 of file DependentParameter.cpp.

◆ ensure_up_to_date()

void DependentParameter::ensure_up_to_date ( )

Recomputes the parameter if its cached value is stale.

Behavior:

  • if not dirty: returns immediately,
  • if frozen: returns immediately,
  • otherwise:
    • forces all source parameters to be up to date by calling src->get_val(),
    • checks that the recomputation lambda exists,
    • clears the dirty flag,
    • calls the recomputation lambda on this parameter.
Note
The lambda is expected to update this parameter in-place.
Errors are logged if a source is null or if the lambda is missing.

Definition at line 80 of file DependentParameter.cpp.

◆ freeze()

void DependentParameter::freeze ( )
overridevirtual

Freezes the dependent parameter.

While frozen:

Reimplemented from Parameter.

Definition at line 99 of file DependentParameter.cpp.

◆ get_source_parameters()

std::unordered_map< ParamId, std::shared_ptr< Parameter > > DependentParameter::get_source_parameters ( ) const
inlineoverridevirtual

Returns the source parameters this dependent parameter currently uses.

Returns
Map of source ParamId to source Parameter shared pointers.

Reimplemented from Parameter.

Definition at line 190 of file DependentParameter.h.

◆ get_val()

scalar_t DependentParameter::get_val ( ) const
overridevirtual

Returns the current cached value, recomputing it on demand if needed.

This method:

Note
In the current implementation, this override does not apply ParameterMode::SHIFTABLE / shift. It returns expected only.
Returns
Current cached dependent value.

Reimplemented from Parameter.

Definition at line 75 of file DependentParameter.cpp.

◆ init()

void DependentParameter::init ( )

Initializes observer registration on all source parameters.

This method:

  • stores a weak self-reference,
  • registers this parameter as observer of each source parameter.
Warning
Must only be called when this object is already managed by std::shared_ptr, because it uses shared_from_this().

Definition at line 46 of file DependentParameter.cpp.

◆ mark_dirty()

void DependentParameter::mark_dirty ( )

Marks the cached value as dirty.

This only sets the internal dirty flag to true. No notification is emitted here.

Definition at line 56 of file DependentParameter.cpp.

◆ reattach()

void DependentParameter::reattach ( )

Restores previously detached dependencies and recomputation rule.

Current behavior:

  • returns immediately if not detached,
  • restores the saved source map,
  • rebuilds the ParamSrc wrapper,
  • restores the saved recomputation lambda,
  • re-registers this parameter as observer of restored sources,
  • marks the parameter dirty,
  • clears detached state,
  • notifies downstream observers.

After reattachment, the value will be recomputed lazily on the next access.

See also
detach()

Definition at line 158 of file DependentParameter.cpp.

◆ rebind()

void DependentParameter::rebind ( std::unordered_map< ParamId, std::shared_ptr< Parameter > >  new_sources,
DepParamUpdateFunc  new_lambda 
)

Replaces the dependency set and recomputation rule at runtime.

This method:

  • detaches from current sources,
  • replaces active and saved sources,
  • rebuilds the ParamSrc helper,
  • replaces the recomputation lambda,
  • re-registers this parameter as observer of the new sources if already initialized,
  • marks the parameter dirty,
  • resets detached state,
  • notifies downstream observers.
Parameters
new_sourcesNew source parameter map.
new_lambdaNew recomputation lambda.

Definition at line 111 of file DependentParameter.cpp.

◆ unfreeze()

void DependentParameter::unfreeze ( )
overridevirtual

Unfreezes the dependent parameter.

If an update was requested while frozen, this method triggers one call to update() after unfreezing.

Reimplemented from Parameter.

Definition at line 103 of file DependentParameter.cpp.

◆ update()

void DependentParameter::update ( )
overridevirtual

Marks the parameter as dirty and propagates the update downstream.

Current behavior:

Actual recomputation is deferred to ensure_up_to_date().

Reimplemented from Parameter.

Definition at line 60 of file DependentParameter.cpp.


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