73class Block :
public IStorage<LhaID, Parameter>,
public std::enable_shared_from_this<Block> {
96 Block(std::shared_ptr<Block> other);
116 void store(
const LhaID&
id, std::shared_ptr<Parameter> param)
override;
133 void assign(
const LhaID& key, std::shared_ptr<Parameter> param)
override;
182 std::shared_ptr<Parameter>
retrieve(
const LhaID&
id)
override;
213 const std::map<LhaID, std::shared_ptr<Parameter>>&
getItems();
254 std::vector<std::shared_ptr<Block>>
getObservers()
const;
315 void copy(std::shared_ptr<Block> other);
383 virtual std::unordered_map<std::string, std::shared_ptr<Block>>
get_source_blocks()
const;
407 std::weak_ptr<Block> w(self);
408 for (
auto& [_, p] :
items) {
409 if (p) p->set_owner_block(w);
435 friend std::ostream&
operator<<(std::ostream&, std::shared_ptr<Block>);
438 std::map<LhaID, std::shared_ptr<Parameter>>
items;
455 try {
return shared_from_this(); }
catch (...) {
return {}; }
493 const std::unordered_map<std::string, std::shared_ptr<Block>>& sources,
495 : sourceBlocks(sources),
496 recalculateLambda(recalculateFunc),
497 saved_sourceBlocks(sources),
498 saved_recalculateLambda(recalculateFunc),
507 bool dependsOn(
const std::string& blockName);
515 void init()
override;
593 void assign(
const LhaID& key, std::shared_ptr<Parameter> param);
609 std::unordered_map<std::string, std::shared_ptr<Block>>
get_source_blocks()
const override;
664 void ensure_up_to_date_impl();
666 std::weak_ptr<DependentBlock> self;
667 std::unordered_map<std::string, std::shared_ptr<Block>> sourceBlocks;
670 bool update_at_unfreeze =
false;
679 std::unordered_map<std::string, std::shared_ptr<Block>> saved_sourceBlocks;
697 bool dependency_detached =
false;
std::function< void(const BlockSrc &, std::shared_ptr< DependentBlock >)> DepUpdateFunc
Function type used to recompute a DependentBlock from its sources.
Defines the Parameter class used to store individual physical/model parameters.
Block identifier with alias support.
Lightweight view over a set of source blocks.
virtual void freeze()
Freezes all parameters contained in the block.
double get_scale()
Returns the block-wide scale.
void addObserver(std::shared_ptr< Block > observer)
Adds a block observer if not already present.
virtual void update()
Updates the block.
std::unordered_set< LhaID > getAllIDs()
Returns the set of all parameter ids stored in the block.
std::map< LhaID, std::shared_ptr< Parameter > > items
List of observing blocks notified through notifyObservers().
virtual void unfreeze()
Unfreezes all parameters contained in the block.
void store_or_assign(const LhaID &key, std::shared_ptr< Parameter > param) override
Stores a parameter if absent, otherwise assigns into the existing one.
void removeObserver(std::shared_ptr< Block > observer)
Removes a previously registered observer block.
virtual void destroy()
Destroys the block and its downstream block dependencies.
void set_owner(ParameterType type)
Sets the owner ParameterType on all contained parameters.
void notifyObservers()
Notifies all observer blocks that this block has changed.
std::shared_ptr< Block > deep_clone_plain() const
Deep-copies this block as a plain independent block.
void erase_local(const LhaID &id)
Erases an entry from the local storage map only.
void assign(const LhaID &key, std::shared_ptr< Parameter > param) override
Replaces the payload of an existing parameter from another parameter object.
virtual void clear_below()
Clears parameter dependencies below this block.
void set_scale(double scale)
Sets the block-wide scale.
BlockName blockname
Name of the block (e.g. "SMINPUTS", "MASS", "FWCOEF"...)
std::vector< std::shared_ptr< Block > > observers
void bind_self(std::shared_ptr< Block > self)
Binds an explicit self shared_ptr to the block.
bool has_scale()
Returns whether the block has an associated scale.
Block()=default
Default constructor.
virtual void clear_above()
Clears parameter dependencies above this block.
void remove(const LhaID &key) override
Removes a parameter and clears its downstream dependency subtree.
std::optional< double > scale
Internal storage of parameters indexed by LHA id.
std::weak_ptr< Block > self_
Optional block-wide scale.
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 copy(std::shared_ptr< Block > other)
Copies the content and metadata from another block.
bool contains(const LhaID &key) const override
Checks whether the block contains a parameter with the given id.
void store(const LhaID &id, std::shared_ptr< Parameter > param) override
Stores a new parameter under the given LHA id.
std::weak_ptr< Block > self_weak()
Optional explicit self-reference used to rebind owner_block on contained parameters.
virtual void init()
Initialization hook.
friend std::ostream & operator<<(std::ostream &, std::shared_ptr< Block >)
Stream output operator for a block.
const std::map< LhaID, std::shared_ptr< Parameter > > & getItems()
Returns the internal parameter map.
std::shared_ptr< Parameter > retrieve(const LhaID &id) override
Retrieves a stored parameter by id.
std::vector< std::shared_ptr< Block > > getObservers() const
Returns the current list of observer blocks.
BlockName get_name() const
Returns the name of the block.
Block whose content is derived from one or more source blocks.
void clear_below() override
Clears downstream block dependencies.
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 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 update() override
Marks the block as dirty.
void detach()
Temporarily detaches this block from its dependency graph.
bool dependsOn(const std::string &blockName)
Checks whether this dependent block uses a given source block name.
~DependentBlock()
Destructor.
void freeze() override
Freezes the block and all contained parameters.
void unfreeze() override
Unfreezes the block and contained parameters.
void init() override
Initializes the dependency graph for this block.
void assign(const LhaID &key, std::shared_ptr< Parameter > param)
Overwrites the payload of a local parameter without triggering block-level notification.
void ensure_up_to_date() override
Ensures this dependent block is up to date.
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.
void reattach()
Reattaches a previously detached dependent block.
void clear_above() override
Clears upstream block dependencies.
Generic storage interface for key–value containers.
Represents an identifier of a LHA element, possibly containing several sub-ids.