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
46 {
47
49
50 public:
51
52 void Start(hipo::banklist& banks) override;
53 bool Run(hipo::banklist& banks) const override;
54 void Stop() override;
55
65 void Add(std::string const& algo_class_name, std::string const& algo_instance_name = "");
66
75 template <class ALGORITHM>
76 void Add(std::string_view algo_instance_name = "")
77 {
78 if(algo_instance_name == "")
79 Add(std::make_unique<ALGORITHM>());
80 else
81 Add(std::make_unique<ALGORITHM>(algo_instance_name));
82 }
83
92 void Add(algo_t&& algo);
93
102 template <class ALGORITHM>
103 ALGORITHM* Get(std::string const& algo_instance_name)
104 {
105 if(auto it{m_algo_names.find(algo_instance_name)}; it != m_algo_names.end())
106 return dynamic_cast<ALGORITHM*>(m_sequence[it->second].get());
107 m_log->Error("cannot find algorithm '{}' in sequence", algo_instance_name);
108 throw std::runtime_error("cannot Get algorithm");
109 }
110
116 template <typename OPTION_TYPE>
117 void SetOption(std::string const& algo_instance_name, std::string const& key, const OPTION_TYPE val)
118 {
119 Get<Algorithm>(algo_instance_name)->SetOption(key, val);
120 }
121
124 void SetName(std::string_view name);
125
130 std::vector<std::string> GetCreatedBankNames(std::string const& algo_instance_name) const noexcept(false);
131
136 std::string GetCreatedBankName(std::string const& algo_instance_name) const noexcept(false);
137
140 void PrintSequence(Logger::Level level = Logger::info) const;
141
147 void SetConfigFileForEachAlgorithm(std::string const& name);
148
154 void SetConfigDirectoryForEachAlgorithm(std::string const& name);
155
163 void ForEachAlgorithm(std::function<void(algo_t&)> func);
164
165 private:
166
168 std::vector<algo_t> m_sequence;
169
171 std::unordered_map<std::string, std::vector<algo_t>::size_type> m_algo_names;
172 };
173}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
Algorithm: 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