DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::daqdataformats::Fragment Class Reference

C++ Representation of a DUNE Fragment, wrapping the flat byte array that is the Fragment's "actual" form. More...

#include <Fragment.hpp>

Public Types

enum class  BufferAdoptionMode { kReadOnlyMode , kTakeOverBuffer , kCopyFromBuffer }
 Describes how the "existing Fragment buffer" Constructor should treat the given buffer. More...
 

Public Member Functions

 Fragment (const std::vector< std::pair< void *, size_t > > &pieces)
 Fragment constructor using a vector of buffer pointers.
 
 Fragment (void *buffer, size_t size)
 Fragment constructor using a buffer and size.
 
 Fragment (void *existing_fragment_buffer, BufferAdoptionMode adoption_mode)
 Framgnet constructor using existing Fragment array.
 
 Fragment (Fragment const &)=delete
 Fragment copy constructor is deleted.
 
Fragmentoperator= (Fragment const &)=delete
 Fragment copy assignment operator is deleted.
 
 Fragment (Fragment &&other)
 
Fragmentoperator= (Fragment &&other)
 
 ~Fragment ()
 Fragment destructor.
 
FragmentHeader get_header () const
 Get a copy of the FragmentHeader struct.
 
void set_header_fields (const FragmentHeader &header)
 Copy fields from the provided header in this Fragment's header.
 
const void * get_storage_location () const
 Get a pointer to the Fragment's data array to read its contents directly.
 
trigger_number_t get_trigger_number () const
 Get the trigger_number field from the header.
 
void set_trigger_number (trigger_number_t trigger_number)
 Set the trigger_number for the Fragment.
 
run_number_t get_run_number () const
 Get the run_number field from the header.
 
void set_run_number (run_number_t run_number)
 Set the run_number for the Fragment.
 
timestamp_t get_trigger_timestamp () const
 Get the trigger_timestamp field from the header.
 
void set_trigger_timestamp (timestamp_t trigger_timestamp)
 Set the trigger_timestamp for the Fragment.
 
timestamp_t get_window_begin () const
 Get the window_begin field from the header.
 
void set_window_begin (timestamp_t window_begin)
 Set the window_begin for the Fragment.
 
timestamp_t get_window_end () const
 Get the window_end field from the header.
 
void set_window_end (timestamp_t window_end)
 Set the window_end for the Fragment.
 
SourceID get_element_id () const
 Get the SourceID for the Fragment.
 
void set_element_id (SourceID element_id)
 Set the SourceID for the Fragment.
 
uint16_t get_detector_id () const noexcept
 Get the DetID for the Fragment.
 
void set_detector_id (const uint16_t &detector_id) noexcept
 Set the DetID for the Fragment.
 
std::bitset< 32 > get_status_bits () const
 Get the status_bits header field.
 
void set_status_bits (std::bitset< 32 > status_bits)
 Overwrite the status_bits header field.
 
bool get_status_bit (FragmentStatusBits bit) const
 Get the value of a designated status bit.
 
void set_status_bit (FragmentStatusBits bit, bool value)
 Set the designated status bit.
 
fragment_type_t get_fragment_type_code () const
 Get the fragment_type_t value stored in the header.
 
FragmentType get_fragment_type () const
 Get the fragment_type header field.
 
void set_type (FragmentType fragment_type)
 Set the fragment_type header field.
 
sequence_number_t get_sequence_number () const
 Get the sequence_number field from the header.
 
void set_sequence_number (sequence_number_t number)
 Set the sequence_number for the Fragment.
 
fragment_size_t get_size () const
 Get the total size of the Fragment.
 
fragment_size_t get_data_size () const
 Get the size of the Fragment data.
 
void * get_data () const
 Get a pointer to the data payload in the Fragmnet.
 

Private Member Functions

FragmentHeaderheader_ () const
 Get the FragmentHeader from the m_data_arr array.
 

Private Attributes

void * m_data_arr { nullptr }
 Flat memory containing a FragmentHeader and the data payload.
 
bool m_alloc { false }
 Whether the Fragment owns the memory pointed by m_data_arr.
 

Detailed Description

C++ Representation of a DUNE Fragment, wrapping the flat byte array that is the Fragment's "actual" form.

Definition at line 35 of file Fragment.hpp.

Member Enumeration Documentation

◆ BufferAdoptionMode

Describes how the "existing Fragment buffer" Constructor should treat the given buffer.

Enumerator
kReadOnlyMode 

Just use the buffer in non-owning mode.

kTakeOverBuffer 

Take over control of the buffer.

kCopyFromBuffer 

Copy the contents of the buffer into a new Fragment array.

Definition at line 41 of file Fragment.hpp.

42 {
46 };
@ kCopyFromBuffer
Copy the contents of the buffer into a new Fragment array.
@ kReadOnlyMode
Just use the buffer in non-owning mode.
@ kTakeOverBuffer
Take over control of the buffer.

Constructor & Destructor Documentation

◆ Fragment() [1/5]

dunedaq::daqdataformats::Fragment::Fragment ( const std::vector< std::pair< void *, size_t > > & pieces)
inlineexplicit

Fragment constructor using a vector of buffer pointers.

Parameters
piecesVector of pairs of pointer/size pairs used to initialize Fragment payload

Definition at line 267 of file Fragment.hpp.

268{
269
270 size_t size =
271 sizeof(FragmentHeader) +
272 std::accumulate(pieces.begin(), pieces.end(), 0ULL, [](const size_t& a, const std::pair<void*, size_t>& b) {
273 return a + b.second;
274 });
275
276 if (size < sizeof(FragmentHeader)) {
277 throw std::length_error("The Fragment size is smaller than the Fragment header size.");
278 }
279
280 m_data_arr = malloc(size); // NOLINT
281 if (m_data_arr == nullptr) {
282 throw std::bad_alloc();
283 }
284 m_alloc = true;
285
286 FragmentHeader header;
287 header.size = size;
288 memcpy(m_data_arr, &header, sizeof(header));
289
290 size_t offset = sizeof(FragmentHeader);
291 for (auto& piece : pieces) {
292 if (piece.first == nullptr) {
293 throw std::invalid_argument("The Fragment buffer point to NULL.");
294 }
295 memcpy(static_cast<uint8_t*>(m_data_arr) + offset, piece.first, piece.second); // NOLINT
296 offset += piece.second;
297 }
298}
bool m_alloc
Whether the Fragment owns the memory pointed by m_data_arr.
Definition Fragment.hpp:262
void * m_data_arr
Flat memory containing a FragmentHeader and the data payload.
Definition Fragment.hpp:261
double offset
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ Fragment() [2/5]

dunedaq::daqdataformats::Fragment::Fragment ( void * buffer,
size_t size )
inline

Fragment constructor using a buffer and size.

Parameters
bufferPointer to Fragment payload
sizeSize of payload

Definition at line 300 of file Fragment.hpp.

301 : Fragment({ std::make_pair(buffer, size) })
302{
303}
Fragment(const std::vector< std::pair< void *, size_t > > &pieces)
Fragment constructor using a vector of buffer pointers.
Definition Fragment.hpp:267

◆ Fragment() [3/5]

dunedaq::daqdataformats::Fragment::Fragment ( void * existing_fragment_buffer,
BufferAdoptionMode adoption_mode )
inlineexplicit

Framgnet constructor using existing Fragment array.

Parameters
existing_fragment_bufferPointer to existing Fragment array
adoption_modeHow the constructor should treat the existing_fragment_buffer

Definition at line 305 of file Fragment.hpp.

306{
307 if (adoption_mode == BufferAdoptionMode::kReadOnlyMode) {
308 m_data_arr = existing_fragment_buffer;
309 } else if (adoption_mode == BufferAdoptionMode::kTakeOverBuffer) {
310 m_data_arr = existing_fragment_buffer;
311 m_alloc = true;
312 } else if (adoption_mode == BufferAdoptionMode::kCopyFromBuffer) {
313 auto header = reinterpret_cast<FragmentHeader*>(existing_fragment_buffer); // NOLINT
314 m_data_arr = malloc(header->size); // NOLINT
315 if (m_data_arr == nullptr) {
316 throw std::bad_alloc();
317 }
318 m_alloc = true;
319 memcpy(m_data_arr, existing_fragment_buffer, header->size);
320 }
321}

◆ Fragment() [4/5]

dunedaq::daqdataformats::Fragment::Fragment ( Fragment const & )
delete

Fragment copy constructor is deleted.

◆ Fragment() [5/5]

dunedaq::daqdataformats::Fragment::Fragment ( Fragment && other)
inline

Definition at line 68 of file Fragment.hpp.

69 {
70 m_alloc = other.m_alloc;
71 other.m_alloc = false;
72 m_data_arr = other.m_data_arr;
73 }

◆ ~Fragment()

dunedaq::daqdataformats::Fragment::~Fragment ( )
inline

Fragment destructor.

Definition at line 323 of file Fragment.hpp.

324{
325 if (m_alloc)
326 free(m_data_arr); // NOLINT
327}

Member Function Documentation

◆ get_data()

void * dunedaq::daqdataformats::Fragment::get_data ( ) const
inline

Get a pointer to the data payload in the Fragmnet.

Returns
Pointer to the data payload in the Fragment

Definition at line 249 of file Fragment.hpp.

250 {
251 // Increment header pointer by one to skip header
252 return static_cast<void*>(header_() + 1); // NOLINT
253 }
FragmentHeader * header_() const
Get the FragmentHeader from the m_data_arr array.
Definition Fragment.hpp:260

◆ get_data_size()

fragment_size_t dunedaq::daqdataformats::Fragment::get_data_size ( ) const
inline

Get the size of the Fragment data.

Returns
The size of the Fragment data, payload only

Definition at line 243 of file Fragment.hpp.

243{ return header_()->size - sizeof(FragmentHeader); }
fragment_size_t size
Size of the Fragment (including header and payload)

◆ get_detector_id()

uint16_t dunedaq::daqdataformats::Fragment::get_detector_id ( ) const
inlinenoexcept

Get the DetID for the Fragment.

Returns
The detector_id header field

Definition at line 174 of file Fragment.hpp.

174{ return header_()->detector_id; } // NOLINT
uint16_t detector_id
Identifier for the subdetector that produced the raw data in the Fragment payload.

◆ get_element_id()

SourceID dunedaq::daqdataformats::Fragment::get_element_id ( ) const
inline

Get the SourceID for the Fragment.

Returns
The element_id header field

Definition at line 162 of file Fragment.hpp.

162{ return header_()->element_id; }
SourceID element_id
Component that generated the data in this Fragment.

◆ get_fragment_type()

FragmentType dunedaq::daqdataformats::Fragment::get_fragment_type ( ) const
inline

Get the fragment_type header field.

Returns
Current value of the fragment_type header field

Definition at line 215 of file Fragment.hpp.

215{ return static_cast<FragmentType>(get_fragment_type_code()); }
fragment_type_t get_fragment_type_code() const
Get the fragment_type_t value stored in the header.
Definition Fragment.hpp:210

◆ get_fragment_type_code()

fragment_type_t dunedaq::daqdataformats::Fragment::get_fragment_type_code ( ) const
inline

Get the fragment_type_t value stored in the header.

Returns
Current value of the fragment_type header field

Definition at line 210 of file Fragment.hpp.

210{ return header_()->fragment_type; }
fragment_type_t fragment_type
Type of the Fragment, indicating the format of the contained payload.

◆ get_header()

FragmentHeader dunedaq::daqdataformats::Fragment::get_header ( ) const
inline

Get a copy of the FragmentHeader struct.

Returns
A copy of the FragmentHeader struct stored in this Fragment

Definition at line 90 of file Fragment.hpp.

90{ return *header_(); }

◆ get_run_number()

run_number_t dunedaq::daqdataformats::Fragment::get_run_number ( ) const
inline

Get the run_number field from the header.

Returns
The run_number header field

Definition at line 120 of file Fragment.hpp.

120{ return header_()->run_number; }
run_number_t run_number
Run number this Fragment is associated with.

◆ get_sequence_number()

sequence_number_t dunedaq::daqdataformats::Fragment::get_sequence_number ( ) const
inline

Get the sequence_number field from the header.

Returns
The sequence_number header field

Definition at line 226 of file Fragment.hpp.

226{ return header_()->sequence_number; }
sequence_number_t sequence_number
Sequence number of this Fragment within a trigger record.

◆ get_size()

fragment_size_t dunedaq::daqdataformats::Fragment::get_size ( ) const
inline

Get the total size of the Fragment.

Returns
The size of the Fragment, including header and all payload pieces

Definition at line 237 of file Fragment.hpp.

237{ return header_()->size; }

◆ get_status_bit()

bool dunedaq::daqdataformats::Fragment::get_status_bit ( FragmentStatusBits bit) const
inline

Get the value of a designated status bit.

Parameters
bitBit to query
Returns
Value of bit (true/false)

Definition at line 197 of file Fragment.hpp.

197{ return get_status_bits()[static_cast<size_t>(bit)]; }
std::bitset< 32 > get_status_bits() const
Get the status_bits header field.
Definition Fragment.hpp:186

◆ get_status_bits()

std::bitset< 32 > dunedaq::daqdataformats::Fragment::get_status_bits ( ) const
inline

Get the status_bits header field.

Returns
Bitset generated from header's status_bits field

Definition at line 186 of file Fragment.hpp.

186{ return header_()->status_bits; }
uint32_t status_bits
Status bits set by the Upstream DAQ.

◆ get_storage_location()

const void * dunedaq::daqdataformats::Fragment::get_storage_location ( ) const
inline

Get a pointer to the Fragment's data array to read its contents directly.

Returns
Pointer to the Fragment's data array

Definition at line 103 of file Fragment.hpp.

103{ return m_data_arr; }

◆ get_trigger_number()

trigger_number_t dunedaq::daqdataformats::Fragment::get_trigger_number ( ) const
inline

Get the trigger_number field from the header.

Returns
The trigger_number header field

Definition at line 110 of file Fragment.hpp.

110{ return header_()->trigger_number; }
trigger_number_t trigger_number
Trigger Number this Fragment is associated with.

◆ get_trigger_timestamp()

timestamp_t dunedaq::daqdataformats::Fragment::get_trigger_timestamp ( ) const
inline

Get the trigger_timestamp field from the header.

Returns
The trigger_timestamp header field

Definition at line 131 of file Fragment.hpp.

131{ return header_()->trigger_timestamp; }
timestamp_t trigger_timestamp
Timestamp of the TriggerDecision.

◆ get_window_begin()

timestamp_t dunedaq::daqdataformats::Fragment::get_window_begin ( ) const
inline

Get the window_begin field from the header.

Returns
The window_begin header field

Definition at line 141 of file Fragment.hpp.

141{ return header_()->window_begin; }
timestamp_t window_begin
Window begin of data in the Fragment.

◆ get_window_end()

timestamp_t dunedaq::daqdataformats::Fragment::get_window_end ( ) const
inline

Get the window_end field from the header.

Returns
The window_end header field

Definition at line 151 of file Fragment.hpp.

151{ return header_()->window_end; }
timestamp_t window_end
Window end of data in the Fragment.

◆ header_()

FragmentHeader * dunedaq::daqdataformats::Fragment::header_ ( ) const
inlineprivate

Get the FragmentHeader from the m_data_arr array.

Returns
Pointer to the FragmentHeader

Definition at line 260 of file Fragment.hpp.

260{ return static_cast<FragmentHeader*>(m_data_arr); }

◆ operator=() [1/2]

Fragment & dunedaq::daqdataformats::Fragment::operator= ( Fragment && other)
inline

Definition at line 74 of file Fragment.hpp.

75 {
76 m_alloc = other.m_alloc;
77 other.m_alloc = false;
78 m_data_arr = other.m_data_arr;
79 return *this;
80 }

◆ operator=() [2/2]

Fragment & dunedaq::daqdataformats::Fragment::operator= ( Fragment const & )
delete

Fragment copy assignment operator is deleted.

◆ set_detector_id()

void dunedaq::daqdataformats::Fragment::set_detector_id ( const uint16_t & detector_id)
inlinenoexcept

Set the DetID for the Fragment.

Parameters
detector_idDetID to use as the detector_id

Definition at line 180 of file Fragment.hpp.

180{ header_()->detector_id = detector_id; } // NOLINT

◆ set_element_id()

void dunedaq::daqdataformats::Fragment::set_element_id ( SourceID element_id)
inline

Set the SourceID for the Fragment.

Parameters
element_idSourceID to use as element_id

Definition at line 168 of file Fragment.hpp.

168{ header_()->element_id = element_id; }

◆ set_header_fields()

void dunedaq::daqdataformats::Fragment::set_header_fields ( const FragmentHeader & header)
inline

Copy fields from the provided header in this Fragment's header.

Parameters
headerHeader to copy into the Fragment data array

The size FragmentHeader field is not copied from the given FragmentHeader

Definition at line 330 of file Fragment.hpp.

331{
332 header_()->trigger_number = header.trigger_number;
333 header_()->trigger_timestamp = header.trigger_timestamp;
334 header_()->window_begin = header.window_begin;
335 header_()->window_end = header.window_end;
336 header_()->run_number = header.run_number;
337 header_()->element_id = header.element_id;
338 header_()->detector_id = header.detector_id;
339 header_()->status_bits = header.status_bits;
340 header_()->fragment_type = header.fragment_type;
341 header_()->sequence_number = header.sequence_number;
342}

◆ set_run_number()

void dunedaq::daqdataformats::Fragment::set_run_number ( run_number_t run_number)
inline

Set the run_number for the Fragment.

Parameters
run_numberValue of run_number to set

Definition at line 125 of file Fragment.hpp.

125{ header_()->run_number = run_number; }

◆ set_sequence_number()

void dunedaq::daqdataformats::Fragment::set_sequence_number ( sequence_number_t number)
inline

Set the sequence_number for the Fragment.

Parameters
sequence_numberValue of sequence_number to set

Definition at line 231 of file Fragment.hpp.

231{ header_()->sequence_number = number; }

◆ set_status_bit()

void dunedaq::daqdataformats::Fragment::set_status_bit ( FragmentStatusBits bit,
bool value )
inline

Set the designated status bit.

Parameters
bitBit to set
valueValue (true/false) for the status bit

Definition at line 345 of file Fragment.hpp.

347{
348 auto bits = get_status_bits();
349 bits[static_cast<size_t>(bit)] = value;
350 set_status_bits(bits);
351}
void set_status_bits(std::bitset< 32 > status_bits)
Overwrite the status_bits header field.
Definition Fragment.hpp:191

◆ set_status_bits()

void dunedaq::daqdataformats::Fragment::set_status_bits ( std::bitset< 32 > status_bits)
inline

Overwrite the status_bits header field.

Parameters
status_bitsBitset of status bits to set

Definition at line 191 of file Fragment.hpp.

191{ header_()->status_bits = status_bits.to_ulong(); }

◆ set_trigger_number()

void dunedaq::daqdataformats::Fragment::set_trigger_number ( trigger_number_t trigger_number)
inline

Set the trigger_number for the Fragment.

Parameters
trigger_numberValue of trigger_number to set

Definition at line 115 of file Fragment.hpp.

115{ header_()->trigger_number = trigger_number; }

◆ set_trigger_timestamp()

void dunedaq::daqdataformats::Fragment::set_trigger_timestamp ( timestamp_t trigger_timestamp)
inline

Set the trigger_timestamp for the Fragment.

Parameters
trigger_timestampValue of trigger_timestamp to set

Definition at line 136 of file Fragment.hpp.

136{ header_()->trigger_timestamp = trigger_timestamp; }

◆ set_type()

void dunedaq::daqdataformats::Fragment::set_type ( FragmentType fragment_type)
inline

Set the fragment_type header field.

Parameters
fragment_typeValue to set

Definition at line 220 of file Fragment.hpp.

220{ header_()->fragment_type = static_cast<fragment_type_t>(fragment_type); }
uint32_t fragment_type_t
Type used to represent Fragment type ID.
Definition Types.hpp:28

◆ set_window_begin()

void dunedaq::daqdataformats::Fragment::set_window_begin ( timestamp_t window_begin)
inline

Set the window_begin for the Fragment.

Parameters
window_beginValue of the window_begin to set

Definition at line 146 of file Fragment.hpp.

146{ header_()->window_begin = window_begin; }

◆ set_window_end()

void dunedaq::daqdataformats::Fragment::set_window_end ( timestamp_t window_end)
inline

Set the window_end for the Fragment.

Parameters
window_endValue of the window_end to set

Definition at line 156 of file Fragment.hpp.

156{ header_()->window_end = window_end; }

Member Data Documentation

◆ m_alloc

bool dunedaq::daqdataformats::Fragment::m_alloc { false }
private

Whether the Fragment owns the memory pointed by m_data_arr.

Definition at line 262 of file Fragment.hpp.

262{ false };

◆ m_data_arr

void* dunedaq::daqdataformats::Fragment::m_data_arr { nullptr }
private

Flat memory containing a FragmentHeader and the data payload.

Definition at line 261 of file Fragment.hpp.

261{ nullptr };

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