DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SourceModel.hpp
Go to the documentation of this file.
1
8#ifndef ASIOLIBS_SRC_SOURCEMODEL_HPP_
9#define ASIOLIBS_SRC_SOURCEMODEL_HPP_
10
11#include "SourceConcept.hpp"
12
13
15#include "iomanager/Sender.hpp"
16#include "logging/Logging.hpp"
17
19
20// #include "datahandlinglibs/utils/ReusableThread.hpp"
23
24// #include <folly/ProducerConsumerQueue.h>
25// #include <nlohmann/json.hpp>
26
27#include <atomic>
28#include <memory>
29#include <mutex>
30#include <string>
31
32
33namespace dunedaq::asiolibs {
34
35template<class TargetPayloadType>
37{
38public:
41 using data_t = nlohmann::json;
42
49 {}
51
52 void acquire_callback() override
53 {
55 TLOG_DEBUG(5) << "SourceModel callback is already acquired!";
56 } else {
57 // Getting DataMoveCBRegistry
59 m_sink_callback = dmcbr->get_callback<TargetPayloadType>(inherited::m_sink_conf);
61 }
62 }
63
64 bool handle_payload(char* message, std::size_t size) // NOLINT(build/unsigned)
65 {
66 bool push_out = true;
67 if (push_out) {
68
69 TargetPayloadType& target_payload = *reinterpret_cast<TargetPayloadType*>(message);
70
71 (*m_sink_callback)(std::move(target_payload));
72
73 } else {
74 TargetPayloadType target_payload;
75 uint32_t bytes_copied = 0;
76 datahandlinglibs::buffer_copy(message, size, static_cast<void*>(&target_payload), bytes_copied, sizeof(target_payload));
77 }
78
79 return true;
80 }
81
82 std::size_t get_target_payload_size() const override {
83 TargetPayloadType target_payload;
84 return target_payload.get_frame_size(); // TODO (DTE): Could be a static function?
85 }
86
87 void generate_opmon_data() override {
88
90 info.set_dropped_frames( m_dropped_packets.load() );
91
92 publish( std::move(info) );
93 }
94
95private:
96 // Callback internals
98 using sink_cb_t = std::shared_ptr<std::function<void(TargetPayloadType&&)>>;
100
101 std::atomic<uint64_t> m_dropped_packets{0};
102
103};
104
105} // namespace dunedaq::asiolibs
106
107#endif // ASIOLIBS_SRC_SOURCEMODEL_HPP_
const appmodel::DataMoveCallbackConf * m_sink_conf
void generate_opmon_data() override
std::shared_ptr< std::function< void(TargetPayloadType &&)> > sink_cb_t
SourceModel()
SourceModel Constructor.
bool handle_payload(char *message, std::size_t size)
std::atomic< uint64_t > m_dropped_packets
std::size_t get_target_payload_size() const override
static std::shared_ptr< DataMoveCallbackRegistry > get()
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
void buffer_copy(const char *data, std::size_t size, void *buffer, std::uint32_t buffer_pos, const std::size_t &buffer_size)
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size