Iguana 0.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 39 of file Algorithm.h.

Public Member Functions

 Algorithm (std::string_view name)
 
virtual void Start (hipo::banklist &banks)=0
 Initialize this algorithm before any events are processed, with the intent to process banks
 
void Start ()
 Initialize this algorithm before any events are processed, with the intent to process bank rows rather than full banks;.
 
virtual void Run (hipo::banklist &banks) const =0
 Run this algorithm for an event.
 
virtual void Stop ()=0
 Finalize this algorithm after all events are processed.
 
template<typename OPTION_TYPE >
OPTION_TYPE SetOption (std::string const &key, const OPTION_TYPE val)
 
template<typename OPTION_TYPE >
OPTION_TYPE GetOptionScalar (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
 
template<typename OPTION_TYPE >
std::set< OPTION_TYPE > GetOptionSet (std::string const &key, YAMLReader::node_path_t node_path={}) const
 
void SetName (std::string_view name)
 
std::unique_ptr< YAMLReader > const & GetConfig () const
 
void SetConfig (std::unique_ptr< YAMLReader > &&yaml_config)
 
void SetConfigFile (std::string const &name)
 
void SetConfigDirectory (std::string const &name)
 
- Public Member Functions inherited from iguana::Object
 Object (std::string_view name="", Logger::Level lev=Logger::DEFAULT_LEVEL)
 
std::unique_ptr< Logger > & Log ()
 
void SetName (std::string_view name)
 
std::string GetName () const
 
void SetLogLevel (std::string_view lev)
 
void SetLogLevel (Logger::Level const lev)
 
std::unique_ptr< Logger > & GetLog ()
 

Protected Member Functions

void ParseYAMLConfig ()
 Parse YAML configuration files. Sets m_yaml_config.
 
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)
 
hipo::schema CreateBank (hipo::banklist &banks, hipo::banklist::size_type &bank_idx, std::string const &bank_name, std::vector< std::string > schema_def, int group_id, int item_id) const noexcept(false)
 
void ShowBanks (hipo::banklist &banks, std::string_view message="", Logger::Level const level=Logger::trace) const
 
void ShowBank (hipo::bank &bank, std::string_view message="", Logger::Level const level=Logger::trace) const
 
template<typename OPTION_TYPE >
std::optional< OPTION_TYPE > GetCachedOption (std::string const &key) const
 

Protected Attributes

std::string m_class_name
 Class name of 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 m_default_config_file
 Default configuration file name.
 
std::string o_user_config_file
 
std::string o_user_config_dir
 
std::mutex m_mutex
 A mutex for this algorithm.
 
- Protected Attributes inherited from iguana::Object
std::string m_name
 The name of this object.
 
std::unique_ptr< Loggerm_log
 Logger instance for 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 45 of file Algorithm.h.

◆ ~Algorithm()

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

Definition at line 52 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,
std::vector< std::string > schema_def,
int group_id,
int item_id ) const
protected

Create a new bank and push it to the bank list

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
[in]schema_defa list of variables for the schema
[in]group_idthe group ID for the schema
[in]item_idthe item ID for the schema
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

◆ 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()

◆ 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 79 of file Algorithm.h.

◆ ShowBank()

void iguana::Algorithm::ShowBank ( hipo::bank & 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 & 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()

Member Data Documentation

◆ m_class_name

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

Class name of this algorithm.

Definition at line 208 of file Algorithm.h.

◆ m_default_config_file

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

Default configuration file name.

Definition at line 214 of file Algorithm.h.

◆ m_mutex

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

A mutex for this algorithm.

Definition at line 225 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 211 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 222 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 218 of file Algorithm.h.


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