Iguana 1.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
iguana::AlgorithmSequence Class Reference

#include <AlgorithmSequence.h>

Detailed Description

Algorithm: An algorithm that can run a sequence of algorithms

Input and Output Banks:
See Run function(s) for the banks that are processed by this algorithm.

This algorithm requires the use of hipo::banklist; there are neither Run functions which take individual hipo::bank parameters nor action functions. If you do not use hipo::banklist, you should use individual algorithms instead of this sequencing algorithm.

Use the Add function to add algorithms to the sequence; the order is important, since the Start, Run, and Stop methods will sequentially call the corresponding algorithms' methods, in the same order that the algorithms were added to the sequence by Add.

If an algorithm's Run function returns false, i.e., its "event-level" filter returns false, then AlgorithmSequence's Run function will stop immediately and return false.

Custom Event Filters
If an algorithm's event-level filter is not adequate for your needs, and you want to tighten or override an algorithm's event-level filter, i.e., you want more control over how that algorithm's Run function return value is used, we recommond defining two AlgorithmSequence instances. For example, suppose you want a tighter event-level filter from or after algo2 in the sequence algo1, algo2, algo3, algo4; you may implement this by using two sequences, where the first ends at algo2:
// define sequences
seq1.Add("algo1");
seq1.Add("algo2");
seq2.Add("algo3");
seq2.Add("algo4");
// start them
seq1.Start(banks);
seq2.Start(banks);
Algorithm: An algorithm that can run a sequence of algorithms
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
Then, in your event loop, call your tighter filter between the sequences' Run calls:
if(!seq1.Run(banks)) continue;
if( /*your event filter */) continue;
if(!seq2.Run(banks)) continue;

Definition at line 45 of file AlgorithmSequence.h.

Public Member Functions

void Add (algo_t &&algo)
void Add (std::string const &algo_class_name, std::string const &algo_instance_name="")
template<class ALGORITHM>
void Add (std::string_view algo_instance_name="")
void ForEachAlgorithm (std::function< void(algo_t &)> func)
 Call a function for each algorithm in the sequence.
template<class ALGORITHM>
ALGORITHM * Get (std::string const &algo_instance_name)
std::string GetCreatedBankName (std::string const &algo_instance_name) const noexcept(false)
std::vector< std::string > GetCreatedBankNames (std::string const &algo_instance_name) const noexcept(false)
void PrintSequence (Logger::Level level=Logger::info) const
bool Run (hipo::banklist &banks) const override
 Run Function: Process an event's hipo::banklist
void SetConfigDirectoryForEachAlgorithm (std::string const &name)
 Set a custom configuration file directory for each algorithm in the sequence.
void SetConfigFileForEachAlgorithm (std::string const &name)
 Set a custom configuration file for each algorithm in the sequence.
void SetName (std::string_view name)
template<typename OPTION_TYPE>
void SetOption (std::string const &algo_instance_name, std::string const &key, const OPTION_TYPE val)
void Start (hipo::banklist &banks) override
 Initialize this algorithm before any events are processed, with the intent to process banks.
void Stop () override
 Finalize this algorithm after all events are processed.
Public Member Functions inherited from iguana::Algorithm
 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
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;.
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)

Additional Inherited Members

Protected Member Functions inherited from iguana::Algorithm
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 inherited from iguana::Algorithm
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::AlgorithmSequence:
Inheritance graph

Member Function Documentation

◆ Add() [1/3]

void iguana::AlgorithmSequence::Add ( algo_t && algo)

Add an existing algorithm to the sequence. The AlgorithmSequence instance will take ownership of the algorithm (if it is an lvalue, you will have to std::move it).

Example

Add(std::make_unique<iguana::MyAlgorithm>("my_algorithm_name"));
Parameters
algothe algorithm

◆ Add() [2/3]

void iguana::AlgorithmSequence::Add ( std::string const & algo_class_name,
std::string const & algo_instance_name = "" )

Create and add an algorithm to the sequence, by name.

Example

Add("iguana::MyAlgorithm", "my_algorithm_name");
Parameters
algo_class_namethe name of the algorithm class
algo_instance_namea user-specified unique name for this algorithm instance; if not specified, algo_class_name will be used

◆ Add() [3/3]

template<class ALGORITHM>
void iguana::AlgorithmSequence::Add ( std::string_view algo_instance_name = "")
inline

Create and add an algorithm to the sequence.

Example

Add<iguana::MyAlgorithm>("my_algorithm_name");
Parameters
algo_instance_namea user-specified unique name for this algorithm instance; if not specified, the class name will be used

Definition at line 76 of file AlgorithmSequence.h.

◆ ForEachAlgorithm()

void iguana::AlgorithmSequence::ForEachAlgorithm ( std::function< void(algo_t &)> func)

Call a function for each algorithm in the sequence.

Use as:

ForEachAlgorithm([](auto& algo){ algo->...; });
void ForEachAlgorithm(std::function< void(algo_t &)> func)
Call a function for each algorithm in the sequence.
Parameters
functhe function to call for each algorithm algo

◆ Get()

template<class ALGORITHM>
ALGORITHM * iguana::AlgorithmSequence::Get ( std::string const & algo_instance_name)
inline

Get an algorithm by its instance name

Example

Get<iguana::MyAlgorithm>("my_algorithm_name");
ALGORITHM * Get(std::string const &algo_instance_name)
Parameters
algo_instance_namethe instance name of the algorithm
Returns
a reference to the algorithm

Definition at line 103 of file AlgorithmSequence.h.

◆ GetCreatedBankName()

std::string iguana::AlgorithmSequence::GetCreatedBankName ( std::string const & algo_instance_name) const

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

See also
AlgorithmSequence::GetCreatedBankNames for algorithms which create more than one new bank
Parameters
algo_instance_namethe algorithm instance name
Returns
the new bank name

◆ GetCreatedBankNames()

std::vector< std::string > iguana::AlgorithmSequence::GetCreatedBankNames ( std::string const & algo_instance_name) const

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

See also
AlgorithmSequence::GetCreatedBankName for algorithms which create only one bank
Parameters
algo_instance_namethe algorithm instance name
Returns
the list of new bank names

◆ PrintSequence()

void iguana::AlgorithmSequence::PrintSequence ( Logger::Level level = Logger::info) const

Print the names of the algorithms in this sequence

Parameters
levelthe log level of the printout

◆ Run()

bool iguana::AlgorithmSequence::Run ( hipo::banklist & banks) const
overridevirtual

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.

Implements iguana::Algorithm.

◆ SetConfigDirectoryForEachAlgorithm()

void iguana::AlgorithmSequence::SetConfigDirectoryForEachAlgorithm ( std::string const & name)

Set a custom configuration file directory for each algorithm in the sequence.

Use this function if you have a single configuration file directory for all the algorithms in your sequence

Parameters
namethe directory name

◆ SetConfigFileForEachAlgorithm()

void iguana::AlgorithmSequence::SetConfigFileForEachAlgorithm ( std::string const & name)

Set a custom configuration file for each algorithm in the sequence.

Use this function if you have a single configuration file for all the algorithms in your sequence

Parameters
namethe configuration file name

◆ SetName()

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

Set the name of this sequence

Parameters
namethe new name

◆ SetOption()

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

Set an algorithm option

See also
Algorithm::SetOption
Parameters
algo_instance_namethe algorithm instance name
keythe option name
valthe option value

Definition at line 117 of file AlgorithmSequence.h.

◆ Start()

void iguana::AlgorithmSequence::Start ( hipo::banklist & banks)
overridevirtual

Initialize this algorithm before any events are processed, with the intent to process banks.

use this method if you intend to use Algorithm::Run.

Parameters
banksthe list of banks this algorithm will use, so that Algorithm::Run can cache the indices of the banks that it needs

Implements iguana::Algorithm.

◆ Stop()

void iguana::AlgorithmSequence::Stop ( )
overridevirtual

Finalize this algorithm after all events are processed.

Implements iguana::Algorithm.


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