DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SNBDataHandlingModel.hpp
Go to the documentation of this file.
1
9#ifndef SNBMODULES_INCLUDE_SNBMODULES_READOUT_SNBDATAHANDLINGMODEL_HPP_
10#define SNBMODULES_INCLUDE_SNBMODULES_READOUT_SNBDATAHANDLINGMODEL_HPP_
11
19
21
24#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 snbmodules {
65
66template<class ReadoutType,
67 class RequestHandlerType,
68 class LatencyBufferType,
69 class RawDataProcessorType,
70 class InputDataType = ReadoutType>
72{
73public:
74 // Using shorter typenames
75 using RDT = ReadoutType;
76 using RHT = RequestHandlerType;
77 using LBT = LatencyBufferType;
78 using RPT = RawDataProcessorType;
79 using IDT = InputDataType;
80
81 // Using timestamp typenames
82 using timestamp_t = std::uint64_t; // NOLINT(build/unsigned)
83 static inline constexpr timestamp_t ns = 1;
84 static inline constexpr timestamp_t us = 1000 * ns;
85 static inline constexpr timestamp_t ms = 1000 * us;
86 static inline constexpr timestamp_t s = 1000 * ms;
87
88 // Explicit constructor with run marker pass-through
89 explicit SNBDataHandlingModel(std::atomic<bool>& run_marker)
91 , m_fake_trigger(false)
94 , m_latency_buffer_impl(nullptr)
95 , m_raw_processor_impl(nullptr)
96 {
97 }
98
99 virtual ~SNBDataHandlingModel() = default;
100
101 // Initializes the readoutmodel and its internals
102 void init(const appmodel::DataHandlerModule* modconf);
103
104 // Configures the readoutmodel and its internals
105 void conf(const appfwk::DAQModule::CommandData_t& args);
106
107 // Unconfigures readoutmodel's internals
108 void scrap(const appfwk::DAQModule::CommandData_t& args)
109 {
110 m_request_handler_impl->scrap(args);
111 m_latency_buffer_impl->scrap(args);
112 m_raw_processor_impl->scrap(args);
113 }
114
115 // Starts readoutmodel's internals
116 void start(const appfwk::DAQModule::CommandData_t& args);
117
118 // Stops readoutmodel's internals
119 void stop(const appfwk::DAQModule::CommandData_t& args);
120
121 // Record function: invokes request handler's record implementation
122 void record(const appfwk::DAQModule::CommandData_t& args) override { m_request_handler_impl->record(args); }
123
124 // Opmon get_info call implementation
125 // void get_info(opmonlib::InfoCollector& ci, int level);
126
127 // Consume callback
128 std::function<void(IDT&&)> m_consume_callback;
129
130protected:
131 // Perform processing operations on payload
132 void process_item(RDT&& payload);
133
134 // Transform payload if needed, then perform processing
135 void transform_and_process(IDT&& payload);
136
137 // Raw data consume callback
138 void consume_callback(IDT&& payload);
139
140 // Timesync thread's work function
141 void run_timesync();
142
143 // Noop consume function
144 void run_consume() {}
145
146 // Postprocess scheduler thread's work function
148
149 // Postprocess schedule coroutine
150 folly::coro::Task<void> postprocess_schedule();
151
152 // Dispatch data request
153 void dispatch_requests(dfmessages::DataRequest& data_request);
154
155 // Transform input data type to readout
156 virtual std::vector<RDT> transform_payload(IDT& original) const { return { reinterpret_cast<RDT&>(original) }; }
157
158 // Operational monitoring
159 virtual void generate_opmon_data() override;
160
161 // Constructor params
162 std::atomic<bool>& m_run_marker;
163
164 // CONFIGURATION
165 // appfwk::app::ModInit m_queue_config;
174
175 // STATS
177 using num_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_payloads), metric_t>::type>::type;
178 using sum_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_payloads), metric_t>::type>::type;
179 using num_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_requests), metric_t>::type>::type;
180 using sum_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_requests), metric_t>::type>::type;
182 std::remove_const<std::invoke_result<decltype(&metric_t::num_data_input_timeouts), metric_t>::type>::type;
184 std::remove_const<std::invoke_result<decltype(&metric_t::num_lb_insert_failures), metric_t>::type>::type;
185 using num_post_processing_delay_max_waits_t = std::remove_const<
186 std::invoke_result<decltype(&metric_t::num_post_processing_delay_max_waits), metric_t>::type>::type;
187
188 std::atomic<num_payload_t> m_num_payloads{ 0 };
189 std::atomic<sum_payload_t> m_sum_payloads{ 0 };
190 std::atomic<num_request_t> m_num_requests{ 0 };
191 std::atomic<sum_request_t> m_sum_requests{ 0 };
192 std::atomic<rawq_timeout_count_t> m_rawq_timeout_count{ 0 };
193 std::atomic<num_lb_insert_failures_t> m_num_lb_insert_failures{ 0 };
194 std::atomic<num_post_processing_delay_max_waits_t> m_num_post_processing_delay_max_waits{ 0 };
195 std::atomic<int> m_stats_packet_count{ 0 };
196
197 // CONSUMER
199
200 // REQUEST RECEIVERS
202 std::shared_ptr<request_receiver_ct> m_data_request_receiver;
203
204 // FRAGMENT SENDER
205 // std::chrono::milliseconds m_fragment_sender_timeout_ms;
206 // using fragment_sender_ct = iomanager::SenderConcept<std::pair<std::unique_ptr<daqdataformats::Fragment>,
207 // std::string>>; std::shared_ptr<fragment_sender_ct> m_fragment_sender;
208
209 // TIME-SYNC
211 std::shared_ptr<timesync_sender_ct> m_timesync_sender;
214
215 // POSTPROCESS SCHEDULER
217 folly::coro::Baton m_baton;
218 std::unique_ptr<folly::ThreadWheelTimekeeper> m_timekeeper;
219
220 // LATENCY BUFFER
221 std::shared_ptr<LatencyBufferType> m_latency_buffer_impl;
222
223 // RAW PROCESSING
224 std::shared_ptr<RawDataProcessorType> m_raw_processor_impl;
225
226 // REQUEST HANDLER
227 std::shared_ptr<RequestHandlerType> m_request_handler_impl;
229
230 // ERROR REGISTRY
231 std::unique_ptr<datahandlinglibs::FrameErrorRegistry> m_error_registry;
232
233 // RUN START T0
234 std::chrono::time_point<std::chrono::high_resolution_clock> m_t0;
235};
236
237} // namespace snbmodules
238} // namespace dunedaq
239
240// Declarations
242
243#endif // SNBMODULES_INCLUDE_SNBMODULES_READOUT_SNBDATAHANDLINGMODEL_HPP_
std::atomic< num_lb_insert_failures_t > m_num_lb_insert_failures
std::remove_const< std::invoke_result< decltype(&metric_t::num_lb_insert_failures), metric_t >::type >::type num_lb_insert_failures_t
void start(const appfwk::DAQModule::CommandData_t &args)
SNBDataHandlingModel(std::atomic< bool > &run_marker)
std::atomic< rawq_timeout_count_t > m_rawq_timeout_count
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::shared_ptr< RawDataProcessorType > m_raw_processor_impl
virtual std::vector< RDT > transform_payload(IDT &original) const
void init(const appmodel::DataHandlerModule *modconf)
Forward calls from the appfwk.
std::shared_ptr< timesync_sender_ct > m_timesync_sender
std::chrono::time_point< std::chrono::high_resolution_clock > m_t0
std::shared_ptr< RequestHandlerType > m_request_handler_impl
std::remove_const< std::invoke_result< decltype(&metric_t::num_payloads), metric_t >::type >::type num_payload_t
void conf(const appfwk::DAQModule::CommandData_t &args)
const appmodel::DataMoveCallbackConf * m_raw_data_callback_conf
void record(const appfwk::DAQModule::CommandData_t &args) override
std::unique_ptr< folly::ThreadWheelTimekeeper > m_timekeeper
void stop(const appfwk::DAQModule::CommandData_t &args)
std::remove_const< std::invoke_result< decltype(&metric_t::sum_requests), metric_t >::type >::type sum_request_t
std::shared_ptr< LatencyBufferType > m_latency_buffer_impl
void dispatch_requests(dfmessages::DataRequest &data_request)
std::remove_const< std::invoke_result< decltype(&metric_t::sum_payloads), metric_t >::type >::type sum_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_requests), metric_t >::type >::type num_request_t
std::shared_ptr< request_receiver_ct > m_data_request_receiver
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 ...
std::unique_ptr< datahandlinglibs::FrameErrorRegistry > m_error_registry
void run_timesync()
Function that will be run in its own thread and sends periodic timesync messages by pushing them to t...
void scrap(const appfwk::DAQModule::CommandData_t &args)
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
ReadoutType
Which type of readout to use for TriggerDecision and DataRequest.
Definition Types.hpp:57
Including Qt Headers.
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.