DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OpMonManager.hpp
Go to the documentation of this file.
1
8
9#ifndef OPMONLIB_INCLUDE_OPMONLIB_OPMONMANAGER_HPP_
10#define OPMONLIB_INCLUDE_OPMONLIB_OPMONMANAGER_HPP_
11
12#include <cstddef>
13#include <thread>
14
16#include "opmonlib/Utils.hpp"
17
19#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
20
21namespace dunedaq {
22
24 ThreadNameTooLong,
25 "The name " << name << " is too long for a thread name",
26 ((std::string)name))
27
28ERS_DECLARE_ISSUE(opmonlib, MonitoringThreadNotSet, "Monitoring thread not set", ERS_EMPTY)
29
30ERS_DECLARE_ISSUE(opmonlib, FailedMonitoringThread, "Monitoring thread failed to start", ERS_EMPTY)
31
32ERS_DECLARE_ISSUE(opmonlib, MissingConfiguration, "Confiration is not set", ERS_EMPTY)
33}
34
35namespace dunedaq::opmonlib {
36
38{
39
40 friend class TestOpMonManager;
41
42public:
43 /*
44 * Construtor expected to be used for standard operations,
45 * yet, general developers should not concern themselves with this as the framework handles this for them
46 */
47 explicit OpMonManager(std::string session, std::string name, std::string opmon_facility_uri = "stdout")
48 : OpMonManager(session, name, makeOpMonFacility(opmon_facility_uri, make_origin(session, name)))
49 {
50 ;
51 }
52
53 virtual ~OpMonManager() = default;
54
59
60 // data collecting loop
61 void start_monitoring();
62 // The stop command is not necessary, although it is provided to facilitate complex object behaviour
63 // The stop is invoked during the destruction of the thread
64 // the method requires a valid configuration because the time period is taken from there
65
66 void stop_monitoring();
67 // on top of stopping the monitorin thread, this method will also join the thread
68
70 {
71 m_cfg.store(c);
72 set_opmon_level(m_cfg.load()->get_level());
73 }
74
75protected:
77
78 // obtain the opmon facility
79 auto get_opmon_facility() const { return m_facility.load(); }
80
81 OpMonManager(std::string session, std::string name, facility_ptr_t);
82
83 void run(std::stop_token); // function used by the jthread
84
85private:
86 std::jthread m_thread;
87 std::atomic<const confmodel::OpMonConf*> m_cfg{ nullptr };
88};
89
90} // namespace dunedaq::opmonlib
91
92#endif // OPMONLIB_INCLUDE_OPMONLIB_OPMONMANAGER_HPP_
#define ERS_EMPTY
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
opmon::MonitoringTreeInfo collect() noexcept
void set_opmon_level(OpMonLevel) noexcept
std::atomic< facility_ptr_t > m_facility
void register_node(ElementId name, NewNodePtr)
MonitorableObject(const MonitorableObject &)=delete
std::atomic< const confmodel::OpMonConf * > m_cfg
virtual ~OpMonManager()=default
OpMonManager(std::string session, std::string name, std::string opmon_facility_uri="stdout")
void set_opmon_conf(const confmodel::OpMonConf *c)
std::shared_ptr< OpMonFacility > makeOpMonFacility(std::string const &facility, OptionalOrigin=OptionalOrigin())
opmon::OpMonId make_origin(const std::string &session, const std::string &app)
Definition Utils.cpp:12
The DUNE-DAQ namespace.
ERS_DECLARE_ISSUE(cibmodules, CIBCommunicationError, " CIB Hardware Communication Error: "<< descriptor,((std::string) descriptor)) ERS_DECLARE_ISSUE(cibmodules