Iguana 1.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
AlgorithmSequence.h
1#pragma once
2
3#include "Algorithm.h"
4
5namespace iguana {
6
17 {
18
20
21 public:
22
23 void Start(hipo::banklist& banks) override;
24 bool Run(hipo::banklist& banks) const override;
25 void Stop() override;
26
36 void Add(std::string const& algo_class_name, std::string const& algo_instance_name = "");
37
46 template <class ALGORITHM>
47 void Add(std::string_view algo_instance_name = "")
48 {
49 if(algo_instance_name == "")
50 Add(std::make_unique<ALGORITHM>());
51 else
52 Add(std::make_unique<ALGORITHM>(algo_instance_name));
53 }
54
63 void Add(algo_t&& algo);
64
73 template <class ALGORITHM>
74 ALGORITHM* Get(std::string const& algo_instance_name)
75 {
76 if(auto it{m_algo_names.find(algo_instance_name)}; it != m_algo_names.end())
77 return dynamic_cast<ALGORITHM*>(m_sequence[it->second].get());
78 m_log->Error("cannot find algorithm '{}' in sequence", algo_instance_name);
79 throw std::runtime_error("cannot Get algorithm");
80 }
81
87 template <typename OPTION_TYPE>
88 void SetOption(std::string const& algo_instance_name, std::string const& key, const OPTION_TYPE val)
89 {
90 Get<Algorithm>(algo_instance_name)->SetOption(key, val);
91 }
92
95 void SetName(std::string_view name);
96
101 std::vector<std::string> GetCreatedBankNames(std::string const& algo_instance_name) const noexcept(false);
102
107 std::string GetCreatedBankName(std::string const& algo_instance_name) const noexcept(false);
108
111 void PrintSequence(Logger::Level level = Logger::info) const;
112
118 void SetConfigFileForEachAlgorithm(std::string const& name);
119
125 void SetConfigDirectoryForEachAlgorithm(std::string const& name);
126
134 void ForEachAlgorithm(std::function<void(algo_t&)> func);
135
136 private:
137
139 std::vector<algo_t> m_sequence;
140
142 std::unordered_map<std::string, std::vector<algo_t>::size_type> m_algo_names;
143 };
144}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
An algorithm that can run a sequence of algorithms.
void SetConfigDirectoryForEachAlgorithm(std::string const &name)
Set a custom configuration file directory for each algorithm in the sequence.
void Add(std::string_view algo_instance_name="")
void Stop() override
Finalize this algorithm after all events are processed.
std::vector< std::string > GetCreatedBankNames(std::string const &algo_instance_name) const noexcept(false)
void Add(algo_t &&algo)
void Add(std::string const &algo_class_name, std::string const &algo_instance_name="")
ALGORITHM * Get(std::string const &algo_instance_name)
void ForEachAlgorithm(std::function< void(algo_t &)> func)
Call a function for each algorithm in the sequence.
void SetConfigFileForEachAlgorithm(std::string const &name)
Set a custom configuration file for each algorithm in the sequence.
std::string GetCreatedBankName(std::string const &algo_instance_name) const noexcept(false)
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 SetName(std::string_view name)
void PrintSequence(Logger::Level level=Logger::info) const
bool Run(hipo::banklist &banks) const override
Run Function: Process an event's hipo::banklist
Algorithm(std::string_view name)
Definition Algorithm.h:46
std::unique_ptr< Logger > m_log
Logger instance for this object
Definition Object.h:52