DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAQModule.hpp
Go to the documentation of this file.
1
16#ifndef APPFWK_INCLUDE_APPFWK_DAQMODULE_HPP_
17#define APPFWK_INCLUDE_APPFWK_DAQMODULE_HPP_
18
20
21#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
24
25#include "cetlib/BasicPluginFactory.h"
26#include "cetlib/compiler_macros.h"
27#include "ers/Issue.hpp"
28#include "nlohmann/json.hpp"
29
30#include <functional>
31#include <map>
32#include <memory>
33#include <set>
34#include <string>
35#include <utility>
36#include <vector>
37
38#ifndef EXTERN_C_FUNC_DECLARE_START
39// NOLINTNEXTLINE(build/define_used)
40#define EXTERN_C_FUNC_DECLARE_START \
41 extern "C" \
42 {
43#endif
44
49// NOLINTNEXTLINE(build/define_used)
50#define DEFINE_DUNE_DAQ_MODULE(klass) \
51 EXTERN_C_FUNC_DECLARE_START \
52 std::shared_ptr<dunedaq::appfwk::DAQModule> make(std::string n) \
53 { \
54 return std::shared_ptr<dunedaq::appfwk::DAQModule>(new klass(n)); \
55 } \
56 }
57
58namespace dunedaq {
59
60// Disable coverage collection LCOV_EXCL_START
65 DAQModuleCreationFailed,
66 "Failed to create DAQModule " << instance_name << " of type " << plugin_name,
67 ((std::string)plugin_name)((std::string)instance_name))
68
69
72ERS_DECLARE_ISSUE(appfwk, GeneralDAQModuleIssue, " DAQModule: " << name, ((std::string)name))
73
78 DAQModuleInitFailed,
80 " init failed.",
81 ((std::string)name),
83
90 " Command " << cmd,
91 ((std::string)name),
92 ((std::string)cmd))
93
98 CommandRegistrationFailed,
100 "Command registration failed.",
101 ((std::string)cmd)((std::string)name),
102 ERS_EMPTY)
103
108 UnknownCommand,
110 "Command is not recognised",
111 ((std::string)cmd)((std::string)name),
112 ERS_EMPTY)
113
118 CommandFailed,
120 "Command Failed. Reason " << reason,
121 ((std::string)cmd)((std::string)name),
122 ((std::string)reason))
123
128 MissingConnection,
130 "Required Connection Not Found. Type: " << type << ", direction: " << direction,
131 ((std::string)name),
132 ((std::string)type)((std::string)direction))
133
134// Re-enable coverage collection LCOV_EXCL_STOP
135namespace appfwk {
136
148class DAQModule
151{
152public:
153 using data_t = nlohmann::json;
154
155 explicit DAQModule(std::string name)
157 {
158 }
159
160 virtual ~DAQModule() noexcept = default;
161
168 virtual void init(std::shared_ptr<ConfigurationManager> mcfg) = 0;
169
178 void execute_command(const std::string& name, const data_t& data = {});
179
180 std::vector<std::string> get_commands() const;
181
182 bool has_command(const std::string& name) const;
183
184protected:
192 template<typename Child>
193 void register_command(const std::string& name, void (Child::*f)(const data_t&));
194
195 DAQModule(DAQModule const&) = delete;
196 DAQModule(DAQModule&&) = delete;
197 DAQModule& operator=(DAQModule const&) = delete;
198 DAQModule& operator=(DAQModule&&) = delete;
199
200private:
201 using CommandMap_t = std::map<std::string, std::function<void(const data_t&)>>;
202 CommandMap_t m_commands;
203};
204
205std::shared_ptr<DAQModule>
206make_module(std::string const& plugin_name, std::string const& instance_name);
207
208} // namespace appfwk
209
210} // namespace dunedaq
211
212#include "detail/DAQModule.hxx"
213
214#endif // APPFWK_INCLUDE_APPFWK_DAQMODULE_HPP_
#define ERS_DECLARE_ISSUE_BASE(namespace_name, class_name, base_class_name, message, base_attributes, attributes)
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
#define ERS_EMPTY
Implements the Named interface.
void init(unordered_map< std::string, std::string > params)
Including Qt Headers.
GeneralDAQModuleIssue
Definition DAQModule.hpp:72
Unsupported std::string uri Execution of command failed
Definition Issues.hpp:69
DAQModule std::string name CommandIssue
Definition DAQModule.hpp:88