DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TimingController.hpp
Go to the documentation of this file.
1
12#ifndef TIMINGLIBS_INCLUDE_TIMINGLIBS_TIMINGCONTROLLER_HPP_
13#define TIMINGLIBS_INCLUDE_TIMINGLIBS_TIMINGCONTROLLER_HPP_
14
17
20
21#include "appfwk/DAQModule.hpp"
22#include "ers/Issue.hpp"
23#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
24#include "iomanager/Sender.hpp"
27
30
31#include <memory>
32#include <string>
33#include <vector>
34
35namespace dunedaq {
37 TimingEndpointNotReady,
38 endpoint << " timing endpoint did not become ready in time. State 0x" << std::hex << state,
39 ((std::string)endpoint)((uint)state)
40)
41namespace timinglibs {
42
43template<typename T>
44struct MobileAtomic
45{
46 std::atomic<T> atomic;
47
48 MobileAtomic()
49 : atomic(T())
50 {}
51
52 explicit MobileAtomic(T const& v)
53 : atomic(v)
54 {}
55 explicit MobileAtomic(std::atomic<T> const& a)
56 : atomic(a.load())
57 {}
58
59 virtual ~MobileAtomic() = default;
60
61 MobileAtomic(MobileAtomic const& other)
62 : atomic(other.atomic.load())
63 {}
64
65 MobileAtomic& operator=(MobileAtomic const& other)
66 {
67 atomic.store(other.atomic.load());
68 return *this;
69 }
70
71 MobileAtomic(MobileAtomic&&) = default;
72 MobileAtomic& operator=(MobileAtomic&&) = default;
73};
74
75typedef MobileAtomic<uint64_t> AtomicUInt64; // NOLINT(build/unsigned)
76
81class TimingController : public dunedaq::appfwk::DAQModule
82{
83public:
88 explicit TimingController(const std::string& name, uint number_hw_commands);
89
90 TimingController(const TimingController&) = delete;
91 TimingController& operator=(const TimingController&) = delete;
92 TimingController(TimingController&&) = delete;
93 TimingController& operator=(TimingController&&) = delete;
94
95 void init(std::shared_ptr<appfwk::ConfigurationManager> mcfg) override;
96
97protected:
98 // DAQModule commands
99 virtual void do_configure(const nlohmann::json&);
100 virtual void do_start(const nlohmann::json&) {}
101 virtual void do_stop(const nlohmann::json&) {}
102 virtual void do_scrap(const nlohmann::json&);
103
104 template<class T, class... Vs>
105 void configure_hardware_or_recover_state(const nlohmann::json& data, std::string timing_entity_description, const Vs& ... args);
106
107 // Configuration
108 std::string m_hw_command_out_connection;
109 std::chrono::milliseconds m_hw_cmd_out_timeout;
111 std::shared_ptr<sink_t> m_hw_command_sender;
112 std::string m_timing_device;
113 std::string m_timing_session_name;
115 std::shared_ptr<source_t> m_device_info_receiver;
116
117 virtual void send_hw_cmd(timingcmd::TimingHwCmd&& hw_cmd);
118 virtual void send_configure_hardware_commands(const nlohmann::json& data) = 0;
119
120 // opmon
121 uint m_number_hw_commands;
122 std::vector<AtomicUInt64> m_sent_hw_command_counters;
123
124 // Interpert device opmon info
125 virtual void process_device_info(nlohmann::json /*message*/) = 0;
126 std::chrono::milliseconds m_device_ready_timeout;
127 std::atomic<bool> m_device_ready;
128 std::atomic<uint> m_device_infos_received_count;
129 std::atomic<bool> m_hardware_state_recovery_enabled;
130
131 //common commands
132 timingcmd::TimingHwCmd construct_hw_cmd( const std::string& cmd_id);
133 timingcmd::TimingHwCmd construct_hw_cmd( const std::string& cmd_id, const nlohmann::json& payload);
134 virtual void do_io_reset(const nlohmann::json& data);
135 virtual void do_print_status(const nlohmann::json& data);
136 const dal::TimingControllerConf* m_params;
137
138};
139} // namespace timinglibs
140} // namespace dunedaq
141
143
144#endif // TIMINGLIBS_INCLUDE_TIMINGLIBS_TIMINGCONTROLLER_HPP_
145
146// Local Variables:
147// c-basic-offset: 2
148// End:
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
void init(unordered_map< std::string, std::string > params)
Including Qt Headers.