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_error_bits () const
 Get the error_bits header field.
 
void set_error_bits (std::bitset< 32 > error_bits)
 Overwrite the error_bits header field.
 
bool get_error_bit (FragmentErrorBits bit) const
 Get the value of a designated error bit.
 
void set_error_bit (FragmentErrorBits bit, bool value)
 Set the designated error 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 37 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 43 of file Fragment.hpp.

44 {
48 };
@ 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 272 of file Fragment.hpp.

273{
274
275 size_t size = sizeof(FragmentHeader) +
276 std::accumulate(pieces.begin(), pieces.end(), 0ULL, [](const size_t& a, const std::pair<void*, size_t>& b) { return a + b.second; });
277
278 if (size < sizeof(FragmentHeader)) {
279 throw std::length_error("The Fragment size is smaller than the Fragment header size.");
280 }
281
282 m_data_arr = malloc(size); // NOLINT(build/unsigned)
283 if (m_data_arr == nullptr) {
284 throw std::bad_alloc();
285 }
286 m_alloc = true;
287
288 FragmentHeader header;
289 header.size = size;
290 memcpy(m_data_arr, &header, sizeof(header));
291
292 size_t offset = sizeof(FragmentHeader);
293 for (auto& piece : pieces) {
294 if (piece.first == nullptr) {
295 throw std::invalid_argument("The Fragment buffer point to NULL.");
296 }
297 memcpy(static_cast<uint8_t*>(m_data_arr) + offset, piece.first, piece.second); // NOLINT(build/unsigned)
298 offset += piece.second;
299 }
300}
bool m_alloc
Whether the Fragment owns the memory pointed by m_data_arr.
Definition Fragment.hpp:267
void * m_data_arr
Flat memory containing a FragmentHeader and the data payload.
Definition Fragment.hpp:266
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 302 of file Fragment.hpp.

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

◆ 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 306 of file Fragment.hpp.

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

◆ 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 70 of file Fragment.hpp.

71 {
72 m_alloc = other.m_alloc;
73 other.m_alloc = false;
74 m_data_arr = other.m_data_arr;
75 }

◆ ~Fragment()

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

Fragment destructor.

Definition at line 324 of file Fragment.hpp.

325{
326 if (m_alloc)
327 free(m_data_arr);
328}

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 254 of file Fragment.hpp.

255 {
256 // Increment header pointer by one to skip header
257 return static_cast<void*>(header_() + 1); // NOLINT
258 }
FragmentHeader * header_() const
Get the FragmentHeader from the m_data_arr array.
Definition Fragment.hpp:265

◆ 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 248 of file Fragment.hpp.

248{ 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 177 of file Fragment.hpp.

177{ return header_()->detector_id; }
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 164 of file Fragment.hpp.

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

◆ get_error_bit()

bool dunedaq::daqdataformats::Fragment::get_error_bit ( FragmentErrorBits bit) const
inline

Get the value of a designated error bit.

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

Definition at line 202 of file Fragment.hpp.

202{ return get_error_bits()[static_cast<size_t>(bit)]; }
std::bitset< 32 > get_error_bits() const
Get the error_bits header field.
Definition Fragment.hpp:191

◆ get_error_bits()

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

Get the error_bits header field.

Returns
Bitset generated from header's error_bits field

Definition at line 191 of file Fragment.hpp.

191{ return header_()->error_bits; }
uint32_t error_bits
Error bits set by the Upstream DAQ.

◆ 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 220 of file Fragment.hpp.

220{ 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:215

◆ 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 215 of file Fragment.hpp.

215{ 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 92 of file Fragment.hpp.

92{ 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 122 of file Fragment.hpp.

122{ 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 231 of file Fragment.hpp.

231{ 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 242 of file Fragment.hpp.

242{ return header_()->size; }

◆ 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 105 of file Fragment.hpp.

105{ 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 112 of file Fragment.hpp.

112{ 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 133 of file Fragment.hpp.

133{ 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 143 of file Fragment.hpp.

143{ 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 153 of file Fragment.hpp.

153{ 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 265 of file Fragment.hpp.

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

◆ operator=() [1/2]

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

Definition at line 76 of file Fragment.hpp.

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

◆ 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 184 of file Fragment.hpp.

184{ header_()->detector_id = detector_id; }

◆ 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 170 of file Fragment.hpp.

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

◆ set_error_bit()

void dunedaq::daqdataformats::Fragment::set_error_bit ( FragmentErrorBits bit,
bool value )
inline

Set the designated error bit.

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

Definition at line 346 of file Fragment.hpp.

348{
349 auto bits = get_error_bits();
350 bits[static_cast<size_t>(bit)] = value;
351 set_error_bits(bits);
352}
void set_error_bits(std::bitset< 32 > error_bits)
Overwrite the error_bits header field.
Definition Fragment.hpp:196

◆ set_error_bits()

void dunedaq::daqdataformats::Fragment::set_error_bits ( std::bitset< 32 > error_bits)
inline

Overwrite the error_bits header field.

Parameters
error_bitsBitset of error bits to set

Definition at line 196 of file Fragment.hpp.

196{ header_()->error_bits = error_bits.to_ulong(); }

◆ 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 331 of file Fragment.hpp.

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

◆ 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 127 of file Fragment.hpp.

127{ 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 236 of file Fragment.hpp.

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

◆ 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 117 of file Fragment.hpp.

117{ 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 138 of file Fragment.hpp.

138{ 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 225 of file Fragment.hpp.

225{ 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 148 of file Fragment.hpp.

148{ 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 158 of file Fragment.hpp.

158{ 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 267 of file Fragment.hpp.

267{ 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 266 of file Fragment.hpp.

266{ nullptr };

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