DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dpdklibs
src
SourceModel.hpp
Go to the documentation of this file.
1
8
#ifndef DPDKLIBS_SRC_SOURCEMODEL_HPP_
9
#define DPDKLIBS_SRC_SOURCEMODEL_HPP_
10
11
#include "
SourceConcept.hpp
"
12
13
#include "
dpdklibs/Issues.hpp
"
14
15
#include "
iomanager/IOManager.hpp
"
16
#include "
iomanager/Sender.hpp
"
17
#include "
logging/Logging.hpp
"
18
19
#include "
dpdklibs/opmon/SourceModel.pb.h
"
20
21
#include "
datahandlinglibs/DataMoveCallbackRegistry.hpp
"
22
23
// #include <folly/ProducerConsumerQueue.h>
24
// #include <nlohmann/json.hpp>
25
26
#include <atomic>
27
#include <memory>
28
#include <mutex>
29
#include <string>
30
31
namespace
dunedaq::dpdklibs
{
32
33
template
<
class
TargetPayloadType>
34
class
SourceModel
:
public
SourceConcept
35
{
36
public
:
37
using
sink_t
=
iomanager::SenderConcept<TargetPayloadType>
;
38
using
inherited
=
SourceConcept
;
39
using
data_t
= nlohmann::json;
40
45
SourceModel
()
46
:
SourceConcept
()
47
{
48
}
49
~SourceModel
() {}
50
51
void
acquire_callback
()
override
52
{
53
if
(
m_callback_is_acquired
) {
54
TLOG_DEBUG
(5) <<
"SourceModel callback is already acquired!"
;
55
}
else
{
56
// Getting DataMoveCBRegistry
57
auto
dmcbr =
datahandlinglibs::DataMoveCallbackRegistry::get
();
58
m_sink_callback
= dmcbr->get_callback<TargetPayloadType>(
inherited::m_sink_conf
);
59
m_callback_is_acquired
=
true
;
60
}
61
}
62
63
// Process an incoming raw byte buffer and extract complete frames of type TargetPayloadType.
64
void
handle_daq_frame
(
char
* buffer, std::size_t
size
)
65
{
66
// Calculate how many full frames fit in the incoming message buffer.
67
std::size_t full_frames =
size
/
m_expected_frame_size
;
68
69
// Calculate leftover bytes that don't form a complete frame.
70
if
(
size
%
m_expected_frame_size
> 0) [[unlikely]] {
71
++
m_leftover_bytes_encountered
;
72
}
73
74
// Process each full frames
75
for
(std::size_t i = 0; i < full_frames; ++i) {
76
// Calculate pointer to the i-th frame chunk inside the message buffer.
77
const
char
* src = buffer + i *
m_expected_frame_size
;
78
79
// Materialize a real TargetPayloadType object by copying bytes from the buffer.
80
// This is defined behavior, alignment-safe, and fast, without pointer vodoo
81
// Previously reinterpret_cast to TargetPayloadType* introduced alignment traps
82
// “pretend there’s a constructed object there” UB. Scatter won't work like that.
83
TargetPayloadType frame;
84
std::memcpy(&frame, src,
m_expected_frame_size
);
85
86
// Pass by value (moved); no references into 'buffer', so no UAF.
87
(*m_sink_callback)(std::move(frame));
88
}
89
}
90
91
void
generate_opmon_data
()
override
92
{
93
94
if
(
m_failed_to_send_daq_payloads
!= 0) {
95
ers::warning
(FailedToSendData(
ERS_HERE
,
inherited::m_sink_conf
->UID(),
m_failed_to_send_daq_payloads
));
96
}
97
98
opmon::SourceInfo
info;
99
info.set_failed_to_send_daq_payloads(
m_failed_to_send_daq_payloads
.exchange(0));
100
info.set_leftover_bytes_encountered(
m_leftover_bytes_encountered
.exchange(0));
101
102
publish
(std::move(info));
103
}
104
105
private
:
106
// Constants
107
const
std::size_t
m_expected_frame_size
=
sizeof
(TargetPayloadType);
108
109
// Callback internals
110
bool
m_callback_is_acquired
{
false
};
111
using
sink_cb_t
= std::shared_ptr<std::function<void(TargetPayloadType&&)>>;
112
sink_cb_t
m_sink_callback
;
113
114
// Stats
115
std::atomic<uint64_t>
m_leftover_bytes_encountered
{ 0 };
116
std::atomic<uint64_t>
m_failed_to_send_daq_payloads
{ 0 };
117
};
118
119
}
// namespace dunedaq::dpdklibs
120
121
#endif
// DPDKLIBS_SRC_SOURCEMODEL_HPP_
DataMoveCallbackRegistry.hpp
IOManager.hpp
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:127
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get
static std::shared_ptr< DataMoveCallbackRegistry > get()
Definition
DataMoveCallbackRegistry.hpp:52
dunedaq::dpdklibs::SourceConcept::SourceConcept
SourceConcept()
Definition
SourceConcept.hpp:32
dunedaq::dpdklibs::SourceConcept::m_sink_conf
const appmodel::DataMoveCallbackConf * m_sink_conf
Definition
SourceConcept.hpp:55
dunedaq::dpdklibs::SourceModel::m_failed_to_send_daq_payloads
std::atomic< uint64_t > m_failed_to_send_daq_payloads
Definition
SourceModel.hpp:116
dunedaq::dpdklibs::SourceModel::data_t
nlohmann::json data_t
Definition
SourceModel.hpp:39
dunedaq::dpdklibs::SourceModel::SourceModel
SourceModel()
SourceModel Constructor.
Definition
SourceModel.hpp:45
dunedaq::dpdklibs::SourceModel::m_leftover_bytes_encountered
std::atomic< uint64_t > m_leftover_bytes_encountered
Definition
SourceModel.hpp:115
dunedaq::dpdklibs::SourceModel::generate_opmon_data
void generate_opmon_data() override
Definition
SourceModel.hpp:91
dunedaq::dpdklibs::SourceModel::m_callback_is_acquired
bool m_callback_is_acquired
Definition
SourceModel.hpp:110
dunedaq::dpdklibs::SourceModel::m_sink_callback
sink_cb_t m_sink_callback
Definition
SourceModel.hpp:112
dunedaq::dpdklibs::SourceModel::sink_t
iomanager::SenderConcept< TargetPayloadType > sink_t
Definition
SourceModel.hpp:37
dunedaq::dpdklibs::SourceModel::m_expected_frame_size
const std::size_t m_expected_frame_size
Definition
SourceModel.hpp:107
dunedaq::dpdklibs::SourceModel::sink_cb_t
std::shared_ptr< std::function< void(TargetPayloadType &&)> > sink_cb_t
Definition
SourceModel.hpp:111
dunedaq::dpdklibs::SourceModel::inherited
SourceConcept inherited
Definition
SourceModel.hpp:38
dunedaq::dpdklibs::SourceModel::handle_daq_frame
void handle_daq_frame(char *buffer, std::size_t size)
Definition
SourceModel.hpp:64
dunedaq::dpdklibs::SourceModel::acquire_callback
void acquire_callback() override
Definition
SourceModel.hpp:51
dunedaq::dpdklibs::SourceModel::~SourceModel
~SourceModel()
Definition
SourceModel.hpp:49
dunedaq::dpdklibs::opmon::SourceInfo
Definition
SourceModel.pb.h:80
dunedaq::iomanager::SenderConcept
Definition
Sender.hpp:44
dunedaq::opmonlib::MonitorableObject::publish
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
Definition
MonitorableObject.cpp:59
SourceModel.pb.h
Issues.hpp
SourceConcept.hpp
Sender.hpp
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:116
dunedaq::dpdklibs
Definition
ARP.hpp:16
dunedaq::size
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size
Definition
FelixIssues.hpp:30
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:150
Generated on
for DUNE-DAQ by
1.18.0