Iguana 1.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana::Algorithm Class Referenceabstract

#include <Algorithm.h>

Detailed Description

Base class for all algorithms to inherit from.

This is the base class for all algorithms. It provides common members, such as a logger instance and options data structure. Algorithm implementations must:

See existing algorithms for examples.

Definition at line 40 of file Algorithm.h.

Public Member Functions

 Algorithm (std::string_view name)
std::unique_ptr< YAMLReader > const & GetConfig () const
hipo::bank GetCreatedBank (std::string const &bank_name="") const noexcept(false)
std::string GetCreatedBankName () const noexcept(false)
std::vector< std::string > GetCreatedBankNames () const noexcept(false)
hipo::schema GetCreatedBankSchema (std::string const &bank_name="") const noexcept(false)
template<typename OPTION_TYPE>
OPTION_TYPE GetOptionScalar (std::string const &key, YAMLReader::node_path_t node_path={}) const
template<typename OPTION_TYPE>
std::set< OPTION_TYPE > GetOptionSet (std::string const &key, YAMLReader::node_path_t node_path={}) const
template<typename OPTION_TYPE>
std::vector< OPTION_TYPE > GetOptionVector (std::string const &key, YAMLReader::node_path_t node_path={}) const
virtual bool Run (hipo::banklist &banks) const =0
 Run Function: Process an event's hipo::banklist
void SetConfig (std::unique_ptr< YAMLReader > &&yaml_config)
void SetConfigDirectory (std::string const &name)
void SetConfigFile (std::string const &name)
void SetName (std::string_view name)
template<typename OPTION_TYPE>
OPTION_TYPE SetOption (std::string const &key, const OPTION_TYPE val)
void Start ()
 Initialize this algorithm before any events are processed, with the intent to process bank rows rather than full banks;.
virtual void Start (hipo::banklist &banks)=0
 Initialize this algorithm before any events are processed, with the intent to process banks.
virtual void Stop ()=0
 Finalize this algorithm after all events are processed.
Public Member Functions inherited from iguana::Object
std::unique_ptr< Logger > & GetLog ()
std::string GetName () const
std::unique_ptr< Logger > & Log ()
 Object (std::string_view name="", Logger::Level lev=Logger::DEFAULT_LEVEL)
void SetLogLevel (Logger::Level const lev)
void SetLogLevel (std::string_view lev)
void SetName (std::string_view name)

Protected Member Functions

hipo::schema CreateBank (hipo::banklist &banks, hipo::banklist::size_type &bank_idx, std::string const &bank_name) const noexcept(false)
hipo::bank & GetBank (hipo::banklist &banks, hipo::banklist::size_type const idx, std::string const &expected_bank_name="") const noexcept(false)
hipo::banklist::size_type GetBankIndex (hipo::banklist &banks, std::string const &bank_name) const noexcept(false)
template<typename OPTION_TYPE>
std::optional< OPTION_TYPE > GetCachedOption (std::string const &key) const
void ParseYAMLConfig ()
 Parse YAML configuration files. Sets m_yaml_config.
void ShowBank (hipo::bank const &bank, std::string_view message="", Logger::Level const level=Logger::trace) const
void ShowBanks (hipo::banklist const &banks, std::string_view message="", Logger::Level const level=Logger::trace) const
void ThrowSinceRenamed (std::string const &new_name, std::string const &version) const noexcept(false)

Protected Attributes

std::string m_class_name
 Class name of this algorithm.
std::string m_default_config_file
 Default configuration file name.
std::mutex m_mutex
 A mutex for this algorithm.
bool m_rows_only
 If true, algorithm can only operate on bank rows; Algorithm::GetBank, and therefore Algorithm::Run, cannot be called.
std::string o_user_config_dir
std::string o_user_config_file
Protected Attributes inherited from iguana::Object
std::unique_ptr< Loggerm_log
 Logger instance for this object
std::string m_name
 The name of this object.
Inheritance diagram for iguana::Algorithm:
Inheritance graph

Constructor & Destructor Documentation

◆ Algorithm()

iguana::Algorithm::Algorithm ( std::string_view name)
inline
Parameters
namethe unique name for a derived class instance

Definition at line 46 of file Algorithm.h.

◆ ~Algorithm()

virtual iguana::Algorithm::~Algorithm ( )
inlinevirtual

Definition at line 53 of file Algorithm.h.

Member Function Documentation

◆ CreateBank()

hipo::schema iguana::Algorithm::CreateBank ( hipo::banklist & banks,
hipo::banklist::size_type & bank_idx,
std::string const & bank_name ) const
protected

Create a new bank and push it to the bank list. The bank must be defined in src/iguana/bankdefs/iguana.json.

Parameters
[out]banksthe hipo::banklist onto which the new bank will be pushed
[out]bank_idxwill be set to the hipo::banklist index of the new bank
[in]bank_namethe new bank name
Returns
the bank's schema

◆ GetBank()

hipo::bank & iguana::Algorithm::GetBank ( hipo::banklist & banks,
hipo::banklist::size_type const idx,
std::string const & expected_bank_name = "" ) const
protected

Get the reference to a bank from a hipo::banklist; optionally checks if the bank name matches the expectation

Parameters
banksthe hipo::banklist from which to get the specified bank
idxthe index of banks of the specified bank
expected_bank_nameif specified, checks that the specified bank has this name
Returns
a reference to the bank

◆ GetBankIndex()

hipo::banklist::size_type iguana::Algorithm::GetBankIndex ( hipo::banklist & banks,
std::string const & bank_name ) const
protected

Get the index of a bank in a hipo::banklist; throws an exception if the bank is not found

Parameters
banksthe list of banks this algorithm will use
bank_namethe name of the bank returns the hipo::banklist index of the bank

◆ GetCachedOption()

template<typename OPTION_TYPE>
std::optional< OPTION_TYPE > iguana::Algorithm::GetCachedOption ( std::string const & key) const
protected

Get an option from the option cache

Parameters
keythe key name associated with this option
Returns
the option value, if found (using std::optional)

◆ GetConfig()

std::unique_ptr< YAMLReader > const & iguana::Algorithm::GetConfig ( ) const

Get a reference to this algorithm's configuration (YAMLReader)

Returns
the configuration

◆ GetCreatedBank()

hipo::bank iguana::Algorithm::GetCreatedBank ( std::string const & bank_name = "") const

Get a bank created by a creator-type algorithm. The bank must be defined in src/iguana/bankdefs/iguana.json. Use this function if you intend to use specialized Run(hipo::bank&, ...) functions, where one of its parameters is a (reference to) a created bank.

Parameters
[in]bank_namethe created bank name, which is only needed if the algorithm creates more than one bank
Returns
the new bank

◆ GetCreatedBankName()

std::string iguana::Algorithm::GetCreatedBankName ( ) const

Get the created bank name, for creator-type algorithms which create only one new bank

See also
Algorithm::GetCreatedBankNames for algorithms which create more than one new bank
Returns
the new bank name

◆ GetCreatedBankNames()

std::vector< std::string > iguana::Algorithm::GetCreatedBankNames ( ) const

Get the list of created bank names, for creator-type algorithms

See also
Algorithm::GetCreatedBankName for algorithms which create only one bank
Returns
the list of new bank names

◆ GetCreatedBankSchema()

hipo::schema iguana::Algorithm::GetCreatedBankSchema ( std::string const & bank_name = "") const

Get a bank schema created by a creator-type algorithm. The bank must be defined in src/iguana/bankdefs/iguana.json.

See also
Algorithm::GetCreatedBank
Parameters
[in]bank_namethe created bank name, which is only needed if the algorithm creates more than one bank
Returns
the new bank schema

◆ GetOptionScalar()

template<typename OPTION_TYPE>
OPTION_TYPE iguana::Algorithm::GetOptionScalar ( std::string const & key,
YAMLReader::node_path_t node_path = {} ) const

Get the value of a scalar option

Parameters
keythe unique key name of this option, for caching; if empty, the option will not be cached
node_paththe YAML::Node identifier path to search for this option in the config files; if empty, it will just use key
Returns
the scalar option

◆ GetOptionSet()

template<typename OPTION_TYPE>
std::set< OPTION_TYPE > iguana::Algorithm::GetOptionSet ( std::string const & key,
YAMLReader::node_path_t node_path = {} ) const

Get the value of a vector option, and convert it to std::set

Parameters
keythe unique key name of this option
node_paththe YAML::Node identifier path to search for this option in the config files; if empty, it will just use key
Returns
the vector option converted to std::set

◆ GetOptionVector()

template<typename OPTION_TYPE>
std::vector< OPTION_TYPE > iguana::Algorithm::GetOptionVector ( std::string const & key,
YAMLReader::node_path_t node_path = {} ) const

Get the value of a vector option

Parameters
keythe unique key name of this option, for caching; if empty, the option will not be cached
node_paththe YAML::Node identifier path to search for this option in the config files; if empty, it will just use key
Returns
the vector option

◆ Run()

virtual bool iguana::Algorithm::Run ( hipo::banklist & banks) const
pure virtual

Run Function: Process an event's hipo::banklist

Parameters
banksthe list of banks to process
Returns
a boolean value, which is typically used to decide whether or not to continue analyzing an event, i.e., it can be used as an event-level filter; not all algorithms use or need this feature; see the algorithm's more specialized Run functions, which have hipo::bank parameters
See also
Specialized Run function(s) above/below; they take individual hipo::bank objects as parameters, and their documentation explains which banks are used by this algorithm and how.

Implemented in iguana::AlgorithmSequence, iguana::clas12::CalorimeterLinker, iguana::clas12::EventBuilderFilter, iguana::clas12::FiducialFilter, iguana::clas12::FTEnergyCorrection, iguana::clas12::MomentumCorrection, iguana::clas12::PhotonGBTFilter, iguana::clas12::PhotonGBTFilterValidator, iguana::clas12::rga::FiducialFilterPass1, iguana::clas12::rga::FiducialFilterPass1Validator, iguana::clas12::rga::FiducialFilterPass2, iguana::clas12::rga::FiducialFilterPass2Validator, iguana::clas12::rga::FTEnergyCorrection, iguana::clas12::rga::MomentumCorrection, iguana::clas12::rga::MomentumCorrectionValidator, iguana::clas12::RGAFiducialFilter, iguana::clas12::SectorFinder, iguana::clas12::SectorFinderValidator, iguana::clas12::TrajLinker, iguana::clas12::ZVertexFilter, iguana::clas12::ZVertexFilterValidator, iguana::example::ExampleAlgorithm, iguana::physics::Depolarization, iguana::physics::DepolarizationValidator, iguana::physics::DihadronKinematics, iguana::physics::DihadronKinematicsValidator, iguana::physics::InclusiveKinematics, iguana::physics::InclusiveKinematicsValidator, iguana::physics::SingleHadronKinematics, iguana::physics::SingleHadronKinematicsValidator, and iguana::Validator.

◆ SetConfig()

void iguana::Algorithm::SetConfig ( std::unique_ptr< YAMLReader > && yaml_config)

Set a custom YAMLReader to use for this algorithm

Parameters
yaml_configthe custom YAMLReader instance

◆ SetConfigDirectory()

void iguana::Algorithm::SetConfigDirectory ( std::string const & name)

Set a custom configuration file directory for this algorithm

See also
Algorithm::SetConfigFile
Parameters
namethe directory name

◆ SetConfigFile()

void iguana::Algorithm::SetConfigFile ( std::string const & name)

Set a custom configuration file for this algorithm

See also
Algorithm::SetConfigDirectory
Parameters
namethe configuration file name

◆ SetName()

void iguana::Algorithm::SetName ( std::string_view name)

Set the name of this algorithm

Parameters
namethe new name

◆ SetOption()

template<typename OPTION_TYPE>
OPTION_TYPE iguana::Algorithm::SetOption ( std::string const & key,
const OPTION_TYPE val )
inline

Set an option specified by the user. If the option name is "log", the log level of the Logger owned by this algorithm will be changed to the specified value.

Parameters
keythe name of the option
valthe value to set
Returns
the value that has been set (if needed, e.g., when val is an rvalue)

Definition at line 84 of file Algorithm.h.

◆ ShowBank()

void iguana::Algorithm::ShowBank ( hipo::bank const & bank,
std::string_view message = "",
Logger::Level const level = Logger::trace ) const
protected

Dump a single bank

Parameters
bankthe bank to show
messageif specified, print a header message
levelthe log level

◆ ShowBanks()

void iguana::Algorithm::ShowBanks ( hipo::banklist const & banks,
std::string_view message = "",
Logger::Level const level = Logger::trace ) const
protected

Dump all banks in a hipo::banklist

Parameters
banksthe banks to show
messageif specified, print a header message
levelthe log level

◆ Start() [1/2]

void iguana::Algorithm::Start ( )

Initialize this algorithm before any events are processed, with the intent to process bank rows rather than full banks;.

use this method if you intend to use "action functions" instead of Algorithm::Run.

◆ Start() [2/2]

◆ Stop()

◆ ThrowSinceRenamed()

void iguana::Algorithm::ThrowSinceRenamed ( std::string const & new_name,
std::string const & version ) const
protected

Throw a runtime exception since this algorithm has been renamed. Guidance will be printed for the user.

Parameters
new_namethe new name of the algorithm
versionthe first software version where this change applies

Member Data Documentation

◆ m_class_name

std::string iguana::Algorithm::m_class_name
protected

Class name of this algorithm.

Definition at line 236 of file Algorithm.h.

◆ m_default_config_file

std::string iguana::Algorithm::m_default_config_file
protected

Default configuration file name.

Definition at line 242 of file Algorithm.h.

◆ m_mutex

std::mutex iguana::Algorithm::m_mutex
mutableprotected

A mutex for this algorithm.

Definition at line 253 of file Algorithm.h.

◆ m_rows_only

bool iguana::Algorithm::m_rows_only
protected

If true, algorithm can only operate on bank rows; Algorithm::GetBank, and therefore Algorithm::Run, cannot be called.

Definition at line 239 of file Algorithm.h.

◆ o_user_config_dir

std::string iguana::Algorithm::o_user_config_dir
protected

User's configuration file directory. Set it with Algorithm::SetConfigDirectory

Definition at line 250 of file Algorithm.h.

◆ o_user_config_file

std::string iguana::Algorithm::o_user_config_file
protected

User's configuration file name, which may override the default configuration file, m_default_config_file. Set it with Algorithm::SetConfigFile

Definition at line 246 of file Algorithm.h.


The documentation for this class was generated from the following file:
  • /__w/iguana/iguana/iguana_src/src/iguana/algorithms/Algorithm.h