Iguana 0.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
12 {
13
15
16 public:
17
18 void Start(hipo::banklist& banks) override;
19 void Run(hipo::banklist& banks) const override;
20 void Stop() override;
21
31 void Add(std::string const& class_name, std::string const& instance_name = "");
32
41 template <class ALGORITHM>
42 void Add(std::string_view instance_name = "")
43 {
44 if(instance_name == "")
45 Add(std::make_unique<ALGORITHM>());
46 else
47 Add(std::make_unique<ALGORITHM>(instance_name));
48 }
49
58 void Add(algo_t&& algo);
59
68 template <class ALGORITHM>
69 ALGORITHM* Get(std::string const& instance_name)
70 {
71 if(auto it{m_algo_names.find(instance_name)}; it != m_algo_names.end())
72 return dynamic_cast<ALGORITHM*>(m_sequence[it->second].get());
73 m_log->Error("cannot find algorithm '{}' in sequence", instance_name);
74 throw std::runtime_error("cannot Get algorithm");
75 }
76
82 template <typename OPTION_TYPE>
83 void SetOption(std::string const& algo_name, std::string const& key, const OPTION_TYPE val)
84 {
85 Get<Algorithm>(algo_name)->SetOption(key, val);
86 }
87
90 void SetName(std::string_view name);
91
94 void PrintSequence(Logger::Level level = Logger::info) const;
95
101 void SetConfigFileForEachAlgorithm(std::string const& name);
102
108 void SetConfigDirectoryForEachAlgorithm(std::string const& name);
109
117 void ForEachAlgorithm(std::function<void(algo_t&)> func);
118
119 private:
120
122 std::vector<algo_t> m_sequence;
123
125 std::unordered_map<std::string, std::vector<algo_t>::size_type> m_algo_names;
126 };
127}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
User-level class for running a sequence of algorithms.
void SetConfigDirectoryForEachAlgorithm(std::string const &name)
Set a custom configuration file directory for each algorithm in the sequence.
void SetOption(std::string const &algo_name, std::string const &key, const OPTION_TYPE val)
void Stop() override
Finalize this algorithm after all events are processed.
void Add(algo_t &&algo)
void Run(hipo::banklist &banks) const override
Run this algorithm for an event.
ALGORITHM * Get(std::string const &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.
void Add(std::string const &class_name, std::string const &instance_name="")
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
void Add(std::string_view instance_name="")
Base class for all algorithms to inherit from.
Definition Algorithm.h:40
std::unique_ptr< Logger > m_log
Logger instance for this object
Definition Object.h:52
General, top-level namespace for algorithms and infrastructure. For algorithms and bindings,...
Definition Algorithm.h:14
std::unique_ptr< Algorithm > algo_t
Algorithm pointer type.
Definition Algorithm.h:240