DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::dpdklibs::SourceModel< TargetPayloadType > Class Template Reference

#include <SourceModel.hpp>

Inheritance diagram for dunedaq::dpdklibs::SourceModel< TargetPayloadType >:
[legend]
Collaboration diagram for dunedaq::dpdklibs::SourceModel< TargetPayloadType >:
[legend]

Public Types

using sink_t = iomanager::SenderConcept<TargetPayloadType>
 
using inherited = SourceConcept
 
using data_t = nlohmann::json
 
- Public Types inherited from dunedaq::opmonlib::MonitorableObject
using NodePtr = std::weak_ptr<MonitorableObject>
 
using NewNodePtr = std::shared_ptr<MonitorableObject>
 
using ElementId = std::string
 

Public Member Functions

 SourceModel ()
 SourceModel Constructor.
 
 ~SourceModel ()
 
void set_sink (const std::string &sink_name, bool callback_mode) override
 
void acquire_callback () override
 
std::shared_ptr< sink_t > & get_sink ()
 
void handle_payload (char *message, std::size_t size)
 
void generate_opmon_data () override
 
- Public Member Functions inherited from dunedaq::dpdklibs::SourceConcept
 SourceConcept ()
 
virtual ~SourceConcept ()
 
 SourceConcept (const SourceConcept &)=delete
 SourceConcept is not copy-constructible.
 
SourceConceptoperator= (const SourceConcept &)=delete
 SourceConcept is not copy-assginable.
 
 SourceConcept (SourceConcept &&)=delete
 SourceConcept is not move-constructible.
 
SourceConceptoperator= (SourceConcept &&)=delete
 SourceConcept is not move-assignable.
 
void set_sink_name (const std::string &sink_name)
 
- Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject (const MonitorableObject &)=delete
 
MonitorableObjectoperator= (const MonitorableObject &)=delete
 
 MonitorableObject (MonitorableObject &&)=delete
 
MonitorableObjectoperator= (MonitorableObject &&)=delete
 
virtual ~MonitorableObject ()=default
 
auto get_opmon_id () const noexcept
 
auto get_opmon_level () const noexcept
 

Private Types

using sink_cb_t = std::shared_ptr<std::function<void(TargetPayloadType&&)>>
 

Private Attributes

const std::size_t m_expected_payload_size = sizeof(TargetPayloadType)
 
std::string m_sink_id
 
bool m_sink_is_set { false }
 
std::shared_ptr< sink_tm_sink_queue
 
bool m_callback_mode
 
bool m_callback_is_acquired { false }
 
sink_cb_t m_sink_callback
 
std::atomic< uint64_t > m_leftover_bytes_encountered {0}
 
std::atomic< uint64_t > m_failed_to_send_daq_payloads {0}
 

Additional Inherited Members

- Static Public Member Functions inherited from dunedaq::opmonlib::MonitorableObject
static bool publishable_metric (OpMonLevel entry, OpMonLevel system) noexcept
 
- Public Attributes inherited from dunedaq::dpdklibs::SourceConcept
std::string m_sink_name
 
- Protected Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject ()=default
 
void register_node (ElementId name, NewNodePtr)
 
void publish (google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
 

Detailed Description

template<class TargetPayloadType>
class dunedaq::dpdklibs::SourceModel< TargetPayloadType >

Definition at line 35 of file SourceModel.hpp.

Member Typedef Documentation

◆ data_t

template<class TargetPayloadType >
using dunedaq::dpdklibs::SourceModel< TargetPayloadType >::data_t = nlohmann::json

Definition at line 40 of file SourceModel.hpp.

◆ inherited

template<class TargetPayloadType >
using dunedaq::dpdklibs::SourceModel< TargetPayloadType >::inherited = SourceConcept

Definition at line 39 of file SourceModel.hpp.

◆ sink_cb_t

template<class TargetPayloadType >
using dunedaq::dpdklibs::SourceModel< TargetPayloadType >::sink_cb_t = std::shared_ptr<std::function<void(TargetPayloadType&&)>>
private

Definition at line 146 of file SourceModel.hpp.

◆ sink_t

template<class TargetPayloadType >
using dunedaq::dpdklibs::SourceModel< TargetPayloadType >::sink_t = iomanager::SenderConcept<TargetPayloadType>

Definition at line 38 of file SourceModel.hpp.

Constructor & Destructor Documentation

◆ SourceModel()

template<class TargetPayloadType >
dunedaq::dpdklibs::SourceModel< TargetPayloadType >::SourceModel ( )
inline

SourceModel Constructor.

Parameters
nameInstance name for this SourceModel instance

Definition at line 46 of file SourceModel.hpp.

◆ ~SourceModel()

template<class TargetPayloadType >
dunedaq::dpdklibs::SourceModel< TargetPayloadType >::~SourceModel ( )
inline

Definition at line 49 of file SourceModel.hpp.

49{}

Member Function Documentation

◆ acquire_callback()

template<class TargetPayloadType >
void dunedaq::dpdklibs::SourceModel< TargetPayloadType >::acquire_callback ( )
inlineoverridevirtual

Implements dunedaq::dpdklibs::SourceConcept.

Definition at line 66 of file SourceModel.hpp.

67 {
68 if (m_callback_mode) {
70 TLOG_DEBUG(5) << "SourceModel callback is already acquired!";
71 } else {
72 // Getting DataMoveCBRegistry
74 m_sink_callback = dmcbr->get_callback<TargetPayloadType>(inherited::m_sink_name);
76 }
77 } else {
78 TLOG_DEBUG(5) << "Won't acquire callback, as IOM sink is set!";
79 }
80 }
static std::shared_ptr< DataMoveCallbackRegistry > get()
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112

◆ generate_opmon_data()

template<class TargetPayloadType >
void dunedaq::dpdklibs::SourceModel< TargetPayloadType >::generate_opmon_data ( )
inlineoverridevirtual

Hook for customisable pubblication. The function can throw, exception will be caught by the monitoring thread

Reimplemented from dunedaq::opmonlib::MonitorableObject.

Definition at line 120 of file SourceModel.hpp.

120 {
121
124 }
125
126 opmon::SourceInfo info;
127 // RS FIXME: These are NOT dropped frames!!! Rename on opmon is needed
128 info.set_dropped_frames( m_failed_to_send_daq_payloads.exchange(0) );
129
130 publish( std::move(info) );
131 }
#define ERS_HERE
std::atomic< uint64_t > m_failed_to_send_daq_payloads
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
void warning(const Issue &issue)
Definition ers.hpp:115

◆ get_sink()

template<class TargetPayloadType >
std::shared_ptr< sink_t > & dunedaq::dpdklibs::SourceModel< TargetPayloadType >::get_sink ( )
inline

Definition at line 83 of file SourceModel.hpp.

83{ return m_sink_queue; }
std::shared_ptr< sink_t > m_sink_queue

◆ handle_payload()

template<class TargetPayloadType >
void dunedaq::dpdklibs::SourceModel< TargetPayloadType >::handle_payload ( char * message,
std::size_t size )
inlinevirtual

Implements dunedaq::dpdklibs::SourceConcept.

Definition at line 86 of file SourceModel.hpp.

87 {
88 // Calculate how many full payloads fit in the incoming message buffer.
89 std::size_t full_payloads = size / m_expected_payload_size;
90
91 // Calculate leftover bytes that don't form a complete payload.
92 if (size % m_expected_payload_size > 0) [[unlikely]] {
94 }
95
96 // Process each full payload
97 for (std::size_t i = 0; i < full_payloads; ++i) {
98 // Calculate pointer to the i-th payload chunk inside the message buffer.
99 const char* src = message + i * m_expected_payload_size;
100
101 // Materialize a real TargetPayloadType object by copying bytes from the buffer.
102 // This is defined behavior, alignment-safe, and fast, without pointer vodoo
103 // Previously reinterpret_cast to TargetPayloadType* introduced alignment traps
104 // “pretend there’s a constructed object there” UB. Scatter won't work like that.
105 TargetPayloadType payload;
106 std::memcpy(&payload, src, m_expected_payload_size);
107
108 if (m_callback_mode) {
109 // Pass by value (moved); no references into 'message', so no UAF.
110 (*m_sink_callback)(std::move(payload));
111 } else {
112 // Queue mode: attempt to enqueue the payload in a non-blocking way.
113 if (!m_sink_queue->try_send(std::move(payload), iomanager::Sender::s_no_block)) {
115 }
116 }
117 }
118 }
std::atomic< uint64_t > m_leftover_bytes_encountered
const std::size_t m_expected_payload_size
static constexpr timeout_t s_no_block
Definition Sender.hpp:26
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ set_sink()

template<class TargetPayloadType >
void dunedaq::dpdklibs::SourceModel< TargetPayloadType >::set_sink ( const std::string & sink_name,
bool callback_mode )
inlineoverridevirtual

Implements dunedaq::dpdklibs::SourceConcept.

Definition at line 51 of file SourceModel.hpp.

52 {
53 m_callback_mode = callback_mode;
54 if (callback_mode) {
55 TLOG_DEBUG(5) << "Callback mode requested. Won't acquire iom sender!";
56 } else {
57 if (m_sink_is_set) {
58 TLOG_DEBUG(5) << "SourceModel sink is already set in initialized!";
59 } else {
61 m_sink_is_set = true;
62 }
63 }
64 }
static std::shared_ptr< iomanager::SenderConcept< Datatype > > get_iom_sender(iomanager::ConnectionId const &id)

Member Data Documentation

◆ m_callback_is_acquired

template<class TargetPayloadType >
bool dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_callback_is_acquired { false }
private

Definition at line 145 of file SourceModel.hpp.

145{ false };

◆ m_callback_mode

template<class TargetPayloadType >
bool dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_callback_mode
private

Definition at line 144 of file SourceModel.hpp.

◆ m_expected_payload_size

template<class TargetPayloadType >
const std::size_t dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_expected_payload_size = sizeof(TargetPayloadType)
private

Definition at line 135 of file SourceModel.hpp.

◆ m_failed_to_send_daq_payloads

template<class TargetPayloadType >
std::atomic<uint64_t> dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_failed_to_send_daq_payloads {0}
private

Definition at line 151 of file SourceModel.hpp.

151{0};

◆ m_leftover_bytes_encountered

template<class TargetPayloadType >
std::atomic<uint64_t> dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_leftover_bytes_encountered {0}
private

Definition at line 150 of file SourceModel.hpp.

150{0};

◆ m_sink_callback

template<class TargetPayloadType >
sink_cb_t dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_sink_callback
private

Definition at line 147 of file SourceModel.hpp.

◆ m_sink_id

template<class TargetPayloadType >
std::string dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_sink_id
private

Definition at line 139 of file SourceModel.hpp.

◆ m_sink_is_set

template<class TargetPayloadType >
bool dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_sink_is_set { false }
private

Definition at line 140 of file SourceModel.hpp.

140{ false };

◆ m_sink_queue

template<class TargetPayloadType >
std::shared_ptr<sink_t> dunedaq::dpdklibs::SourceModel< TargetPayloadType >::m_sink_queue
private

Definition at line 141 of file SourceModel.hpp.


The documentation for this class was generated from the following file: