The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::ParameterTree Class Reference

Virtual Parameter Tree. This represents a tree of parameters read from some source but does not necessarily correspond to the parameters in the simulation itself or even to the simulation tree. This is meant to provide a hierarchical view into simulation parameters before they are actually applied to a real TreeNode tree. More...

#include <ParameterTree.hpp>

Classes

class  Node
 Node containing a Parameter and value to apply. Can be used to describes a value extracted from the tree when using get or tryGet. This is a copy of the value and is not in any way synchronized with the tree. More...
 

Public Member Functions

 ParameterTree ()
 Default Constructor.
 
 ParameterTree (const ParameterTree &rhp)
 
ParameterTreeoperator= (const ParameterTree &rhp)
 
virtual ~ParameterTree ()
 Destructor.
 
void clear ()
 Clear all content from this tree.
 
bool set (const std::string &path, const std::string &value, bool required, const std::string &origin="")
 Add a parameter to the tree, replacing any existing parameter.
 
Nodecreate (const std::string &path, bool required=false)
 Add a node to the tree, with proper priority.
 
const Nodeget (const std::string &path) const
 Gets a node from the parameter tree while respecting parameter application order. In other words, getting through this method returns the latest value set for the parameter at the location described by path.
 
const Nodeoperator[] (const std::string &name) const
 Gets a node form the parameter tree.
 
bool hasValue (const std::string &path, const bool must_be_leaf=true) const
 Try to check if a node has value.
 
bool exists (const std::string &path, const bool must_be_leaf=true) const
 Try to check if a node exists.
 
uint32_t getUnreadValueNodes (std::vector< const Node * > *nodes) const
 Counts the number of values attached to the parameter tree which have values but have not been read. This is a smart system which looks at historical parameter values as well as the latest to be sure that all have been touched.
 
uint32_t getUnreadValueNodes (std::vector< Node * > *nodes)
 Counts the number of values attached to the parameter tree which have values but have not been read. This is a smart system which looks at historical parameter values as well as the latest to be sure that all have been touched. non-const version.
 
const NodetryGet (const std::string &path, const bool must_be_leaf=true) const
 Try to get a node if it exists. Returns nullptr it it does not.
 
NodetryGet (const std::string &path, const bool must_be_leaf=true)
 tryGet non-const version
 
bool isRequired (const std::string &path) const
 Recursively find first leaf node matching this pattern and decide if any node matching that node's pattern is required to exist in the SPARTA tree.
 
bool unrequire (const std::string &path)
 Unrequire a node in the tree.
 
bool isRead (const std::string &path) const
 Has a node with a given path been read.
 
Node const * getRoot () const
 
NodegetRoot ()
 
void merge (const ParameterTree &rhp)
 Merge this tree with another by applying all of its parameters to this tree. Parameters in the right tree will override this tree's parameters if there are duplicate paths or overlapping patterns.
 
void recursePrint (std::ostream &o) const
 Recursively print.
 

Detailed Description

Virtual Parameter Tree. This represents a tree of parameters read from some source but does not necessarily correspond to the parameters in the simulation itself or even to the simulation tree. This is meant to provide a hierarchical view into simulation parameters before they are actually applied to a real TreeNode tree.

Eventually, this structure will automatically share data with sparta::ParameterSet instances as they are created. For now, it is limited.

Typical use is to subclass this object for each simulator component/model which has a set of parameters it must consume. sparta::ParameterSet provides a generic interface through which config-file parsers or command-line parsers can populate the parameters from strings. Models that expose the ParameterSet full of sparta::Parameter instances should dynamic_cast a sparta::ParameterSet supplied to them at runtime back to a known type and operate through Parameters directly instead of through this generic interface.

Definition at line 37 of file ParameterTree.hpp.

Constructor & Destructor Documentation

◆ ParameterTree() [1/2]

sparta::ParameterTree::ParameterTree ( )
inline

Default Constructor.

Definition at line 809 of file ParameterTree.hpp.

◆ ParameterTree() [2/2]

sparta::ParameterTree::ParameterTree ( const ParameterTree rhp)
inline

Definition at line 813 of file ParameterTree.hpp.

◆ ~ParameterTree()

virtual sparta::ParameterTree::~ParameterTree ( )
inlinevirtual

Destructor.

Definition at line 831 of file ParameterTree.hpp.

Member Function Documentation

◆ clear()

void sparta::ParameterTree::clear ( )
inline

Clear all content from this tree.

Definition at line 836 of file ParameterTree.hpp.

◆ create()

Node * sparta::ParameterTree::create ( const std::string &  path,
bool  required = false 
)
inline

Add a node to the tree, with proper priority.

Parameters
pathPath to create. TEMPORARY: Must not contain parent references (i.e. extra dots)
Arethe nodes added by this call required to exist?
Returns
TEMPORARY: Returns a Node if one is created or found, nullptr if not. May return nullptr if parameter path contains parent reference (any '.' character whicih is proceded by another '.' or the beginnign of the string). This will be fixed eventually. Nothing else should cause this to return nullptr

Setting is fundamentally different than getting in a virtual parameter tree. It cannot fail and (when setting with patterns [paths containing wildcards]), new nodes are almost always created.

Definition at line 878 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ exists()

bool sparta::ParameterTree::exists ( const std::string &  path,
const bool  must_be_leaf = true 
) const
inline

Try to check if a node exists.

Parameters
pathPath of the node to check
must_be_leafCheck only if leaf node
Returns
Bool

Definition at line 930 of file ParameterTree.hpp.

◆ get()

const Node & sparta::ParameterTree::get ( const std::string &  path) const
inline

Gets a node from the parameter tree while respecting parameter application order. In other words, getting through this method returns the latest value set for the parameter at the location described by path.

Parameters
pathPath of node to retrieve
Exceptions
SpartaExceptionif node with given path does not exist (see exists)
Returns
Node at the given location. This node is temporary and becomes stale on any modification to this ParameterTree. Reading this node later may result in an incorrect value
Warning
The returned node should be considered stale when this ParameterTree is modified

Definition at line 897 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ getRoot() [1/2]

Node * sparta::ParameterTree::getRoot ( )
inline

Definition at line 1055 of file ParameterTree.hpp.

◆ getRoot() [2/2]

Node const * sparta::ParameterTree::getRoot ( ) const
inline

Definition at line 1053 of file ParameterTree.hpp.

◆ getUnreadValueNodes() [1/2]

uint32_t sparta::ParameterTree::getUnreadValueNodes ( std::vector< const Node * > *  nodes) const
inline

Counts the number of values attached to the parameter tree which have values but have not been read. This is a smart system which looks at historical parameter values as well as the latest to be sure that all have been touched.

Parameters
[out]nodesNodes with unread values. This is not cleared

The implementation of this method is highly coupled with the tryGet() which marks read parameters (including historically set parameters) as read to satify this method

Definition at line 945 of file ParameterTree.hpp.

◆ getUnreadValueNodes() [2/2]

uint32_t sparta::ParameterTree::getUnreadValueNodes ( std::vector< Node * > *  nodes)
inline

Counts the number of values attached to the parameter tree which have values but have not been read. This is a smart system which looks at historical parameter values as well as the latest to be sure that all have been touched. non-const version.

Parameters
[out]nodesNodes with unread values. This is not cleared

The implementation of this method is highly coupled with the tryGet() which marks read parameters (including historically set parameters) as read to satify this method

Definition at line 960 of file ParameterTree.hpp.

◆ hasValue()

bool sparta::ParameterTree::hasValue ( const std::string &  path,
const bool  must_be_leaf = true 
) const
inline

Try to check if a node has value.

Parameters
pathPath of the node to check
must_be_leafCheck only if leaf node
Returns
Bool

Definition at line 919 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ isRead()

bool sparta::ParameterTree::isRead ( const std::string &  path) const
inline

Has a node with a given path been read.

Parameters
[in]pathPath to check

Resolves a path to any matching nodes (which may include any number of wildcard nodes) and checks that at least one of those nodes have been read 1 or more times.

Definition at line 1034 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ isRequired()

bool sparta::ParameterTree::isRequired ( const std::string &  path) const
inline

Recursively find first leaf node matching this pattern and decide if any node matching that node's pattern is required to exist in the SPARTA tree.

Definition at line 987 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ merge()

void sparta::ParameterTree::merge ( const ParameterTree rhp)
inline

Merge this tree with another by applying all of its parameters to this tree. Parameters in the right tree will override this tree's parameters if there are duplicate paths or overlapping patterns.

Definition at line 1062 of file ParameterTree.hpp.

◆ operator=()

ParameterTree & sparta::ParameterTree::operator= ( const ParameterTree rhp)
inline

Definition at line 819 of file ParameterTree.hpp.

◆ operator[]()

const Node & sparta::ParameterTree::operator[] ( const std::string &  name) const
inline

Gets a node form the parameter tree.

Parameters
nameName of parameter to retrieve

Definition at line 909 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ recursePrint()

void sparta::ParameterTree::recursePrint ( std::ostream &  o) const
inline

Recursively print.

Definition at line 1069 of file ParameterTree.hpp.

◆ set()

bool sparta::ParameterTree::set ( const std::string &  path,
const std::string &  value,
bool  required,
const std::string &  origin = "" 
)
inline

Add a parameter to the tree, replacing any existing parameter.

Parameters
pathPath (from root) to assign value
valueValue to assign to a path in this tree
requiredMust this parameter exist?
originOrigin of the value (e.g. "foo.yaml line:50 col:23")
Returns
TEMPORARY: Returns true of parameter is set, false if not. May return false if parameter path contains parent reference (any '.' character whicih is proceded by another '.' or the beginnign of the string). This will be fixed eventually.

Setting is fundamentally different than getting in a virtual parameter tree. It cannot fail and (when setting with patterns [paths containing wildcards]), new nodes are almost always created.

Definition at line 854 of file ParameterTree.hpp.

Here is the call graph for this function:

◆ tryGet() [1/2]

Node * sparta::ParameterTree::tryGet ( const std::string &  path,
const bool  must_be_leaf = true 
)
inline

tryGet non-const version

Parameters
pathPath of the node to retrieve
Returns
The node at the given path

Definition at line 978 of file ParameterTree.hpp.

◆ tryGet() [2/2]

const Node * sparta::ParameterTree::tryGet ( const std::string &  path,
const bool  must_be_leaf = true 
) const
inline

Try to get a node if it exists. Returns nullptr it it does not.

Parameters
pathPath of the node to retrieve
Returns
The node at the given path

Definition at line 969 of file ParameterTree.hpp.

◆ unrequire()

bool sparta::ParameterTree::unrequire ( const std::string &  path)
inline

Unrequire a node in the tree.

Parameters
pathThe path to the node to unrequire (set ignore)
Returns
true if the node was found and set; false otherwise

Definition at line 1017 of file ParameterTree.hpp.

Here is the call graph for this function:

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