11#include "iguana/services/YAMLReader.h"
12#include <iguana/services/GlobalParam.h>
29 std::vector<std::string>>;
59 virtual void Start(hipo::banklist& banks) = 0;
68 virtual void Run(hipo::banklist& banks)
const = 0;
78 template <
typename OPTION_TYPE>
79 OPTION_TYPE
SetOption(std::string
const& key,
const OPTION_TYPE val)
83 if constexpr(std::disjunction<
84 std::is_same<OPTION_TYPE, std::string>,
85 std::is_same<OPTION_TYPE, char const*>,
86 std::is_same<OPTION_TYPE, Logger::Level>>::value)
89 m_log->Error(
"Option '{}' must be a string or a Logger::Level", key);
91 m_option_cache[key] = val;
99 template <
typename OPTION_TYPE>
106 template <
typename OPTION_TYPE>
113 template <
typename OPTION_TYPE>
126 void SetConfig(std::unique_ptr<YAMLReader>&& yaml_config);
148 hipo::bank&
GetBank(hipo::banklist& banks, hipo::banklist::size_type
const idx, std::string
const& expected_bank_name =
"") const noexcept(false);
154 hipo::banklist::size_type
GetBankIndex(hipo::banklist& banks, std::
string const& bank_name) const noexcept(false);
165 hipo::banklist& banks,
166 hipo::banklist::size_type& bank_idx,
167 std::
string const& bank_name,
168 std::vector<std::
string> schema_def,
170 int item_id) const noexcept(false);
176 void ShowBanks(hipo::banklist& banks, std::string_view message = "",
Logger::Level const level =
Logger::trace) const;
182 void ShowBank(hipo::bank& bank, std::string_view message = "",
Logger::Level const level =
Logger::trace) const;
187 template <typename OPTION_TYPE>
195 void CompleteOptionNodePath(std::
string const& key,
YAMLReader::node_path_t& node_path) const;
198 void PrintOptionValue(std::
string const& key,
int const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
199 void PrintOptionValue(std::
string const& key,
double const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
200 void PrintOptionValue(std::
string const& key, std::
string const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
201 void PrintOptionValue(std::
string const& key, std::vector<
int> const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
202 void PrintOptionValue(std::
string const& key, std::vector<
double> const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
203 void PrintOptionValue(std::
string const& key, std::vector<std::
string> const& val,
Logger::Level const level =
Logger::debug, std::string_view prefix = "OPTION") const;
233 std::unordered_map<std::
string,
option_t> m_option_cache;
258 static bool Register(std::string
const& name,
algo_creator_t creator, std::vector<std::string>
const new_banks = {})
noexcept;
268 static std::optional<std::vector<std::string>>
QueryNewBank(std::string
const& bank_name)
noexcept;
273 static std::unordered_map<std::string, algo_creator_t> s_creators;
276 static std::unordered_map<std::string, std::vector<std::string>> s_created_banks;
Preprocessor macros to generate standardized algorithm boilerplate code.
Factory to create an algorithm.
static algo_t Create(std::string const &name) noexcept(false)
std::function< algo_t()> algo_creator_t
Algorithm creator function type.
static bool Register(std::string const &name, algo_creator_t creator, std::vector< std::string > const new_banks={}) noexcept
static std::optional< std::vector< std::string > > QueryNewBank(std::string const &bank_name) noexcept
Base class for all algorithms to inherit from.
void SetName(std::string_view name)
void SetConfigDirectory(std::string const &name)
std::optional< OPTION_TYPE > GetCachedOption(std::string const &key) const
virtual void Start(hipo::banklist &banks)=0
Initialize this algorithm before any events are processed, with the intent to process banks
std::set< OPTION_TYPE > GetOptionSet(std::string const &key, YAMLReader::node_path_t node_path={}) const
std::unique_ptr< YAMLReader > const & GetConfig() const
void SetConfig(std::unique_ptr< YAMLReader > &&yaml_config)
std::string m_class_name
Class name of this algorithm.
OPTION_TYPE GetOptionScalar(std::string const &key, YAMLReader::node_path_t node_path={}) const
virtual void Run(hipo::banklist &banks) const =0
Run this algorithm for an event.
std::vector< OPTION_TYPE > GetOptionVector(std::string const &key, YAMLReader::node_path_t node_path={}) const
void ShowBank(hipo::bank &bank, std::string_view message="", Logger::Level const level=Logger::trace) const
hipo::bank & GetBank(hipo::banklist &banks, hipo::banklist::size_type const idx, std::string const &expected_bank_name="") const noexcept(false)
std::mutex m_mutex
A mutex for this algorithm.
void Start()
Initialize this algorithm before any events are processed, with the intent to process bank rows rathe...
void SetConfigFile(std::string const &name)
void ParseYAMLConfig()
Parse YAML configuration files. Sets m_yaml_config.
std::string o_user_config_dir
virtual void Stop()=0
Finalize this algorithm after all events are processed.
OPTION_TYPE SetOption(std::string const &key, const OPTION_TYPE val)
bool m_rows_only
If true, algorithm can only operate on bank rows; Algorithm::GetBank, and therefore Algorithm::Run,...
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)
hipo::banklist::size_type GetBankIndex(hipo::banklist &banks, std::string const &bank_name) const noexcept(false)
std::string o_user_config_file
std::string m_default_config_file
Default configuration file name.
void ShowBanks(hipo::banklist &banks, std::string_view message="", Logger::Level const level=Logger::trace) const
Algorithm(std::string_view name)
A named object with a Logger instance.
std::unique_ptr< Logger > m_log
Logger instance for this object
A YAMLReader based on yaml-cpp.
std::deque< node_id_t > node_path_t
Representation of a path of YAML::Nodes in a YAML::Node tree, e.g., in a YAML file.
General, top-level namespace for algorithms and infrastructure. For algorithms and bindings,...
std::variant< int, double, std::string, std::vector< int >, std::vector< double >, std::vector< std::string > > option_t
Option value variant type.
std::unique_ptr< Algorithm > algo_t
Algorithm pointer type.