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 m_pid_of_current_process = getpid();
99 }
100
101 virtual ~DataHandlingModel() = default;
102
103 // Initializes the readoutmodel and its internals
104 void init(const appmodel::DataHandlerModule* modconf);
105
106 // Configures the readoutmodel and its internals
107 void conf(const nlohmann::json& args);
108
109 // Unconfigures readoutmodel's internals
110 void scrap(const nlohmann::json& args)
111 {
112 m_request_handler_impl->scrap(args);
113 m_latency_buffer_impl->scrap(args);
114 m_raw_processor_impl->scrap(args);
115 }
116
117 // Starts readoutmodel's internals
118 void start(const nlohmann::json& args);
119
120 // Stops readoutmodel's internals
121 void stop(const nlohmann::json& args);
122
123 // Record function: invokes request handler's record implementation
124 void record(const nlohmann::json& args) override
125 {
126 m_request_handler_impl->record(args);
127 }
128
129 // Opmon get_info call implementation
130 //void get_info(opmonlib::InfoCollector& ci, int level);
131
132 // Consume callback
133 std::function<void(IDT&&)> m_consume_callback;
134
135protected:
136
137 // Perform processing operations on payload
138 void process_item(RDT&& payload);
139
140 // Transform payload if needed, then perform processing
141 void transform_and_process(IDT&& payload);
142
143 // Raw data consume callback
144 void consume_callback(IDT&& payload);
145
146 // Raw data consumer's work function
147 void run_consume();
148
149 // Timesync thread's work function
150 void run_timesync();
151
152 // Postprocess scheduler thread's work function
154
155 // Postprocess schedule coroutine
156 folly::coro::Task<void> postprocess_schedule();
157
158 // Dispatch data request
159 void dispatch_requests(dfmessages::DataRequest& data_request);
160
161 // Transform input data type to readout
162 virtual std::vector<RDT> transform_payload(IDT& original) const
163 {
164 return { reinterpret_cast<RDT&>(original) };
165 }
166
167 // Operational monitoring
168 virtual void generate_opmon_data() override;
169
170 // Constructor params
171 std::atomic<bool>& m_run_marker;
172
173 // CONFIGURATION
174 //appfwk::app::ModInit m_queue_config;
184
185 // STATS
187 using num_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_payloads),metric_t>::type>::type;
188 using sum_payload_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_payloads),metric_t>::type>::type;
189 using num_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_requests),metric_t>::type>::type;
190 using sum_request_t = std::remove_const<std::invoke_result<decltype(&metric_t::sum_requests),metric_t>::type>::type;
191 using rawq_timeout_count_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_data_input_timeouts),metric_t>::type>::type;
192 using num_lb_insert_failures_t = std::remove_const<std::invoke_result<decltype(&metric_t::num_lb_insert_failures),metric_t>::type>::type;
193 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;
194
195 std::atomic<num_payload_t> m_num_payloads{ 0 };
196 std::atomic<sum_payload_t> m_sum_payloads{ 0 };
197 std::atomic<num_request_t> m_num_requests{ 0 };
198 std::atomic<sum_request_t> m_sum_requests{ 0 };
199 std::atomic<rawq_timeout_count_t> m_rawq_timeout_count{ 0 };
200 std::atomic<num_lb_insert_failures_t> m_num_lb_insert_failures{ 0 };
201 std::atomic<num_post_processing_delay_max_waits_t> m_num_post_processing_delay_max_waits{ 0 };
202 std::atomic<int> m_stats_packet_count{ 0 };
203
204 // CONSUMER
206
207 // RAW RECEIVER
208 std::chrono::milliseconds m_raw_receiver_timeout_ms;
209 std::chrono::microseconds m_raw_receiver_sleep_us;
211 std::shared_ptr<raw_receiver_ct> m_raw_data_receiver;
213
214 // REQUEST RECEIVERS
216 std::shared_ptr<request_receiver_ct> m_data_request_receiver;
217
218 // FRAGMENT SENDER
219 //std::chrono::milliseconds m_fragment_sender_timeout_ms;
220 //using fragment_sender_ct = iomanager::SenderConcept<std::pair<std::unique_ptr<daqdataformats::Fragment>, std::string>>;
221 //std::shared_ptr<fragment_sender_ct> m_fragment_sender;
222
223 // TIME-SYNC
225 std::shared_ptr<timesync_sender_ct> m_timesync_sender;
229
230 // POSTPROCESS SCHEDULER
232 folly::coro::Baton m_baton;
233 std::unique_ptr<folly::ThreadWheelTimekeeper> m_timekeeper;
234
235 // LATENCY BUFFER
236 std::shared_ptr<LatencyBufferType> m_latency_buffer_impl;
237
238 // RAW PROCESSING
239 std::shared_ptr<RawDataProcessorType> m_raw_processor_impl;
240
241 // REQUEST HANDLER
242 std::shared_ptr<RequestHandlerType> m_request_handler_impl;
244
245 // ERROR REGISTRY
246 std::unique_ptr<FrameErrorRegistry> m_error_registry;
247
248 // RUN START T0
249 std::chrono::time_point<std::chrono::high_resolution_clock> m_t0;
250};
251
252} // namespace datahandlinglibs
253} // namespace dunedaq
254
255// Declarations
257
258#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)
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
virtual std::vector< RDT > transform_payload(IDT &original) const
std::remove_const< std::invoke_result< decltype(&metric_t::sum_payloads), metric_t >::type >::type sum_payload_t
void record(const nlohmann::json &args) override
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 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.
Definition DataStore.hpp:57
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.