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
32
namespace
dunedaq::dpdklibs
{
33
34
template
<
class
TargetPayloadType>
35
class
SourceModel
:
public
SourceConcept
36
{
37
public
:
38
using
sink_t
=
iomanager::SenderConcept<TargetPayloadType>
;
39
using
inherited
=
SourceConcept
;
40
using
data_t
= nlohmann::json;
41
46
SourceModel
()
47
:
SourceConcept
()
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
if
(
m_failed_to_send_daq_payloads
!= 0) {
94
ers::warning
(FailedToSendData(
ERS_HERE
,
inherited::m_sink_conf
->UID(),
m_failed_to_send_daq_payloads
));
95
}
96
97
opmon::SourceInfo
info;
98
info.set_failed_to_send_daq_payloads(
m_failed_to_send_daq_payloads
.exchange(0) );
99
info.set_leftover_bytes_encountered(
m_leftover_bytes_encountered
.exchange(0) );
100
101
publish
( std::move(info) );
102
}
103
104
private
:
105
// Constants
106
const
std::size_t
m_expected_frame_size
=
sizeof
(TargetPayloadType);
107
108
// Callback internals
109
bool
m_callback_is_acquired
{
false
};
110
using
sink_cb_t
= std::shared_ptr<std::function<void(TargetPayloadType&&)>>;
111
sink_cb_t
m_sink_callback
;
112
113
// Stats
114
std::atomic<uint64_t>
m_leftover_bytes_encountered
{0};
115
std::atomic<uint64_t>
m_failed_to_send_daq_payloads
{0};
116
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:141
dunedaq::datahandlinglibs::DataMoveCallbackRegistry::get
static std::shared_ptr< DataMoveCallbackRegistry > get()
Definition
DataMoveCallbackRegistry.hpp:50
dunedaq::dpdklibs::SourceConcept::SourceConcept
SourceConcept()
Definition
SourceConcept.hpp:32
dunedaq::dpdklibs::SourceConcept::m_sink_conf
const appmodel::DataMoveCallbackConf * m_sink_conf
Definition
SourceConcept.hpp:60
dunedaq::dpdklibs::SourceModel::m_failed_to_send_daq_payloads
std::atomic< uint64_t > m_failed_to_send_daq_payloads
Definition
SourceModel.hpp:115
dunedaq::dpdklibs::SourceModel::data_t
nlohmann::json data_t
Definition
SourceModel.hpp:40
dunedaq::dpdklibs::SourceModel::SourceModel
SourceModel()
SourceModel Constructor.
Definition
SourceModel.hpp:46
dunedaq::dpdklibs::SourceModel::m_leftover_bytes_encountered
std::atomic< uint64_t > m_leftover_bytes_encountered
Definition
SourceModel.hpp:114
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:109
dunedaq::dpdklibs::SourceModel::m_sink_callback
sink_cb_t m_sink_callback
Definition
SourceModel.hpp:111
dunedaq::dpdklibs::SourceModel::sink_t
iomanager::SenderConcept< TargetPayloadType > sink_t
Definition
SourceModel.hpp:38
dunedaq::dpdklibs::SourceModel::m_expected_frame_size
const std::size_t m_expected_frame_size
Definition
SourceModel.hpp:106
dunedaq::dpdklibs::SourceModel::sink_cb_t
std::shared_ptr< std::function< void(TargetPayloadType &&)> > sink_cb_t
Definition
SourceModel.hpp:110
dunedaq::dpdklibs::SourceModel::inherited
SourceConcept inherited
Definition
SourceModel.hpp:39
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:58
SourceModel.pb.h
Issues.hpp
SourceConcept.hpp
Sender.hpp
Logging.hpp
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
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:28
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:126
Generated on
for DUNE-DAQ by
1.17.0