DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DataHandlingModel.hpp
Go to the documentation of this file.
1
9#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_READOUTMODEL_HPP_
10#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_READOUTMODEL_HPP_
11
19
21
23#include "iomanager/Sender.hpp"
25
26#include "logging/Logging.hpp"
27
30
33
37
40
44
47
48#include <folly/coro/Baton.h>
49#include <folly/coro/Task.h>
50#include <folly/futures/ThreadWheelTimekeeper.h>
51
52#include <functional>
53#include <memory>
54#include <string>
55#include <utility>
56#include <vector>
57
62
63namespace dunedaq {
64namespace datahandlinglibs {
65
66template<class ReadoutType, class RequestHandlerType, class LatencyBufferType, class RawDataProcessorType, class InputDataType = ReadoutType>
68{
69public:
70 // Using shorter typenames
71 using RDT = ReadoutType;
72 using RHT = RequestHandlerType;
73 using LBT = LatencyBufferType;
74 using RPT = RawDataProcessorType;
75 using IDT = InputDataType;
76
77 // Using timestamp typenames
78 using timestamp_t = std::uint64_t; // NOLINT(build/unsigned)
79 static inline constexpr timestamp_t ns = 1;
80 static inline constexpr timestamp_t us = 1000 * ns;
81 static inline constexpr timestamp_t ms = 1000 * us;
82 static inline constexpr timestamp_t s = 1000 * ms;
83
84 // Explicit constructor with run marker pass-through
85 explicit DataHandlingModel(std::atomic<bool>& run_marker)
87 , m_callback_mode(false)
88 , m_fake_trigger(false)
93 , m_raw_data_receiver(nullptr)
95 , m_latency_buffer_impl(nullptr)
96 , m_raw_processor_impl(nullptr)
97 {
98 }
99
100 virtual ~DataHandlingModel() = default;
101
102 // Initializes the readoutmodel and its internals
103 void init(const appmodel::DataHandlerModule* modconf);
104
105 // Configures the readoutmodel and its internals
106 void conf(const appfwk::DAQModule::CommandData_t& args);
107
108 // Unconfigures readoutmodel's internals
109 void scrap(const appfwk::DAQModule::CommandData_t& args)
110 {
111 m_request_handler_impl->scrap(args);
112 m_latency_buffer_impl->scrap(args);
113 m_raw_processor_impl->scrap(args);
114 }
115
116 // Starts readoutmodel's internals
117 void start(const appfwk::DAQModule::CommandData_t& args);
118
119 // Stops readoutmodel's internals
120 void stop(const appfwk::DAQModule::CommandData_t& args);
121
122 // Record function: invokes request handler's record implementation
123 void record(const appfwk::DAQModule::CommandData_t& args) override
124 {
125 m_request_handler_impl->record(args);
126 }
127
128 // Opmon get_info call implementation
129 //void get_info(opmonlib::InfoCollector& ci, int level);
130
131 // Consume callback
132 std::function<void(IDT&&)> m_consume_callback;
133
134protected:
135
136 // Perform processing operations on payload
137 void process_item(RDT&& payload);
138
139 // Transform payload if needed, then perform processing
140 void transform_and_process(IDT&& payload);
141
142 // Raw data consume callback
143 void consume_callback(IDT&& payload);
144
145 // Raw data consumer's work function
146 void run_consume();
147
148 // Timesync thread's work function
149 void run_timesync();
150
151 // Postprocess scheduler thread's work function
153
154 // Postprocess schedule coroutine
155 folly::coro::Task<void> postprocess_schedule();
156
157 // Dispatch data request
158 void dispatch_requests(dfmessages::DataRequest& data_request);
159
160 // Transform input data type to readout
161 virtual std::vector<RDT> transform_payload(IDT& original) const
162 {
163 return { reinterpret_cast<RDT&>(original) };
164 }
165
166 // Operational monitoring
167 virtual void generate_opmon_data() override;
168
169 // Constructor params
170 std::atomic<bool>& m_run_marker;
171
172 // CONFIGURATION
173 //appfwk::app::ModInit m_queue_config;
183
184 // STATS
186 using num_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_payloads),metric_t>::type>::type;
187 using sum_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_payloads),metric_t>::type>::type;
188 using num_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_requests),metric_t>::type>::type;
189 using sum_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_requests),metric_t>::type>::type;
190 using rawq_timeout_count_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_data_input_timeouts),metric_t>::type>::type;
191 using num_lb_insert_failures_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_lb_insert_failures),metric_t>::type>::type;
192 using num_post_processing_delay_max_waits_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_post_processing_delay_max_waits),metric_t>::type>::type;
193
194 std::atomic<num_payload_t> m_num_payloads{ 0 };
195 std::atomic<sum_payload_t> m_sum_payloads{ 0 };
196 std::atomic<num_request_t> m_num_requests{ 0 };
197 std::atomic<sum_request_t> m_sum_requests{ 0 };
198 std::atomic<rawq_timeout_count_t> m_rawq_timeout_count{ 0 };
199 std::atomic<num_lb_insert_failures_t> m_num_lb_insert_failures{ 0 };
200 std::atomic<num_post_processing_delay_max_waits_t> m_num_post_processing_delay_max_waits{ 0 };
201 std::atomic<int> m_stats_packet_count{ 0 };
202
203 // CONSUMER
205
206 // RAW RECEIVER
207 std::chrono::milliseconds m_raw_receiver_timeout_ms;
208 std::chrono::microseconds m_raw_receiver_sleep_us;
210 std::shared_ptr<raw_receiver_ct> m_raw_data_receiver;
212
213 // REQUEST RECEIVERS
215 std::shared_ptr<request_receiver_ct> m_data_request_receiver;
216
217 // FRAGMENT SENDER
218 //std::chrono::milliseconds m_fragment_sender_timeout_ms;
219 //using fragment_sender_ct = iomanager::SenderConcept<std::pair<std::unique_ptr<daqdataformats::Fragment>, std::string>>;
220 //std::shared_ptr<fragment_sender_ct> m_fragment_sender;
221
222 // TIME-SYNC
224 std::shared_ptr<timesync_sender_ct> m_timesync_sender;
227
228 // POSTPROCESS SCHEDULER
230 folly::coro::Baton m_baton;
231 std::unique_ptr<folly::ThreadWheelTimekeeper> m_timekeeper;
232
233 // LATENCY BUFFER
234 std::shared_ptr<LatencyBufferType> m_latency_buffer_impl;
235
236 // RAW PROCESSING
237 std::shared_ptr<RawDataProcessorType> m_raw_processor_impl;
238
239 // REQUEST HANDLER
240 std::shared_ptr<RequestHandlerType> m_request_handler_impl;
242
243 // ERROR REGISTRY
244 std::unique_ptr<FrameErrorRegistry> m_error_registry;
245
246 // RUN START T0
247 std::chrono::time_point<std::chrono::high_resolution_clock> m_t0;
248};
249
250} // namespace datahandlinglibs
251} // namespace dunedaq
252
253// Declarations
255
256#endif // DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_READOUTMODEL_HPP_
std::atomic< num_lb_insert_failures_t > m_num_lb_insert_failures
std::unique_ptr< FrameErrorRegistry > m_error_registry
DataHandlingModel(std::atomic< bool > &run_marker)
void record(const appfwk::DAQModule::CommandData_t &args) override
std::shared_ptr< RequestHandlerType > m_request_handler_impl
void init(const appmodel::DataHandlerModule *modconf)
Forward calls from the appfwk.
std::remove_const< std::invoke_result< decltype(&metric_t::num_post_processing_delay_max_waits), metric_t >::type >::type num_post_processing_delay_max_waits_t
std::unique_ptr< folly::ThreadWheelTimekeeper > m_timekeeper
std::shared_ptr< timesync_sender_ct > m_timesync_sender
void stop(const appfwk::DAQModule::CommandData_t &args)
virtual std::vector< RDT > transform_payload(IDT &original) const
void start(const appfwk::DAQModule::CommandData_t &args)
std::remove_const< std::invoke_result< decltype(&metric_t::sum_payloads), metric_t >::type >::type sum_payload_t
void scrap(const appfwk::DAQModule::CommandData_t &args)
std::remove_const< std::invoke_result< decltype(&metric_t::num_requests), metric_t >::type >::type num_request_t
std::remove_const< std::invoke_result< decltype(&metric_t::sum_requests), metric_t >::type >::type sum_request_t
std::chrono::time_point< std::chrono::high_resolution_clock > m_t0
std::shared_ptr< raw_receiver_ct > m_raw_data_receiver
void conf(const appfwk::DAQModule::CommandData_t &args)
void dispatch_requests(dfmessages::DataRequest &data_request)
std::remove_const< std::invoke_result< decltype(&metric_t::num_data_input_timeouts), metric_t >::type >::type rawq_timeout_count_t
void run_consume()
Function that will be run in its own thread to read the raw packets from the connection and add them ...
void run_timesync()
Function that will be run in its own thread and sends periodic timesync messages by pushing them to t...
std::remove_const< std::invoke_result< decltype(&metric_t::num_payloads), metric_t >::type >::type num_payload_t
std::atomic< num_post_processing_delay_max_waits_t > m_num_post_processing_delay_max_waits
std::remove_const< std::invoke_result< decltype(&metric_t::num_lb_insert_failures), metric_t >::type >::type num_lb_insert_failures_t
std::atomic< rawq_timeout_count_t > m_rawq_timeout_count
std::shared_ptr< LatencyBufferType > m_latency_buffer_impl
std::shared_ptr< request_receiver_ct > m_data_request_receiver
std::shared_ptr< RawDataProcessorType > m_raw_processor_impl
std::atomic< bool > run_marker
Global atomic for process lifetime.
uint32_t run_number_t
Type used to represent run number.
Definition Types.hpp:20
The DUNE-DAQ namespace.
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
This message represents a request for data sent to a single component of the DAQ.