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 { 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)
 Fragment constructor using existing Fragment array.
FragmentHeader get_header () const
void set_header_fields (const FragmentHeader &header)
 Fields from the provided header overwrite this Fragment's header, except for the size field.
const void * get_storage_location () const
 Get read-only access to the Fragment's underlying data array via a pointer.
trigger_number_t get_trigger_number () const
void set_trigger_number (trigger_number_t trigger_number)
run_number_t get_run_number () const
void set_run_number (run_number_t run_number)
timestamp_t get_trigger_timestamp () const
void set_trigger_timestamp (timestamp_t trigger_timestamp)
timestamp_t get_window_begin () const
void set_window_begin (timestamp_t window_begin)
timestamp_t get_window_end () const
void set_window_end (timestamp_t window_end)
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
void set_detector_id (const uint16_t &detector_id) noexcept
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
void set_sequence_number (sequence_number_t number)
fragment_size_t get_size () const
 Get the total size of the Fragment in bytes, including header and all payload pieces.
fragment_size_t get_data_size () const
 Get the size of the Fragment payload in bytes (total size minus FragmentHeader).
void * get_data () const
 Get a pointer to the data payload in the Fragmnet.
 Fragment (Fragment const &)=delete
Fragmentoperator= (Fragment const &)=delete
 Fragment (Fragment &&other)
Fragmentoperator= (Fragment &&other)
 ~Fragment ()

Private Member Functions

FragmentHeaderheader_ () const

Private Attributes

void * m_data_arr { nullptr }
 Points to 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
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 {
43 kTakeOverBuffer,
44 kCopyFromBuffer
45 };

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

184{
185
186 size_t size =
187 sizeof(FragmentHeader) +
188 std::accumulate(pieces.begin(), pieces.end(), 0ULL, [](const size_t& a, const std::pair<void*, size_t>& b) {
189 return a + b.second;
190 });
191
192 m_data_arr = malloc(size); // NOLINT
193 if (m_data_arr == nullptr) {
194 throw std::bad_alloc();
195 }
196 m_alloc = true;
197
198 FragmentHeader header;
199 header.size = size;
200 memcpy(m_data_arr, &header, sizeof(header));
201
202 size_t offset = sizeof(header);
203 for (auto& piece : pieces) {
204 if (piece.first == nullptr) {
205 free(m_data_arr); // NOLINT
206 throw std::invalid_argument("The Fragment buffer points to NULL.");
207 }
208 memcpy(static_cast<uint8_t*>(m_data_arr) + offset, piece.first, piece.second); // NOLINT
209 offset += piece.second;
210 }
211}
bool m_alloc
Whether the Fragment owns the memory pointed by m_data_arr.
Definition Fragment.hpp:180
void * m_data_arr
Points to flat memory containing a FragmentHeader and the data payload.
Definition Fragment.hpp:179
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 213 of file Fragment.hpp.

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

◆ Fragment() [3/5]

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

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

219{
220 if (adoption_mode == BufferAdoptionMode::kTakeOverBuffer) {
221 m_data_arr = existing_fragment_buffer;
222 m_alloc = true;
223 } else if (adoption_mode == BufferAdoptionMode::kCopyFromBuffer) {
224 auto header = reinterpret_cast<FragmentHeader*>(existing_fragment_buffer); // NOLINT
225 m_data_arr = malloc(header->size); // NOLINT
226 if (m_data_arr == nullptr) {
227 throw std::bad_alloc();
228 }
229 m_alloc = true;
230 memcpy(m_data_arr, existing_fragment_buffer, header->size);
231 }
232}
@ kCopyFromBuffer
Copy the contents of the buffer into a new Fragment array.
Definition Fragment.hpp:44
@ kTakeOverBuffer
Take over control of the buffer.
Definition Fragment.hpp:43

◆ Fragment() [4/5]

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

◆ Fragment() [5/5]

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

Definition at line 161 of file Fragment.hpp.

162 {
163 m_alloc = other.m_alloc;
164 other.m_alloc = false;
165 m_data_arr = other.m_data_arr;
166 }

◆ ~Fragment()

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

Definition at line 234 of file Fragment.hpp.

235{
236 if (m_alloc)
237 free(m_data_arr); // NOLINT
238}

Member Function Documentation

◆ get_data()

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

Get a pointer to the data payload in the Fragmnet.

Definition at line 153 of file Fragment.hpp.

154 {
155 // Increment header pointer by one to skip header
156 return static_cast<void*>(header_() + 1); // NOLINT
157 }
FragmentHeader * header_() const
Definition Fragment.hpp:178

◆ get_data_size()

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

Get the size of the Fragment payload in bytes (total size minus FragmentHeader).

Definition at line 150 of file Fragment.hpp.

150{ 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

Definition at line 100 of file Fragment.hpp.

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

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

136{ 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:131
FragmentType
All defined Fragment types.

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

131{ 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

Definition at line 65 of file Fragment.hpp.

65{ return *header_(); }

◆ get_run_number()

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

Definition at line 76 of file Fragment.hpp.

◆ get_sequence_number()

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

Definition at line 143 of file Fragment.hpp.

143{ 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 in bytes, including header and all payload pieces.

Definition at line 147 of file Fragment.hpp.

147{ 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 118 of file Fragment.hpp.

118{ 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:107

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

107{ 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 read-only access to the Fragment's underlying data array via a pointer.

Definition at line 71 of file Fragment.hpp.

71{ return m_data_arr; }

◆ get_trigger_number()

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

Definition at line 73 of file Fragment.hpp.

73{ 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

Definition at line 79 of file Fragment.hpp.

79{ 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

Definition at line 82 of file Fragment.hpp.

82{ 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

Definition at line 85 of file Fragment.hpp.

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

◆ header_()

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

Definition at line 178 of file Fragment.hpp.

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

◆ operator=() [1/2]

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

Definition at line 167 of file Fragment.hpp.

168 {
169 m_alloc = other.m_alloc;
170 other.m_alloc = false;
171 m_data_arr = other.m_data_arr;
172 return *this;
173 }

◆ operator=() [2/2]

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

◆ set_detector_id()

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

Definition at line 101 of file Fragment.hpp.

101{ 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 98 of file Fragment.hpp.

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

◆ set_header_fields()

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

Fields from the provided header overwrite this Fragment's header, except for the size field.

Definition at line 241 of file Fragment.hpp.

242{
243 FragmentHeader* header_ptr{ header_() };
244 fragment_size_t orig_size{ header_ptr->size };
245
246 *header_ptr = header;
247 header_ptr->size = orig_size;
248}
uint64_t fragment_size_t
Definition Types.hpp:23

◆ set_run_number()

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

Definition at line 77 of file Fragment.hpp.

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

◆ set_sequence_number()

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

Definition at line 144 of file Fragment.hpp.

144{ 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 251 of file Fragment.hpp.

253{
254 auto bits = get_status_bits();
255 bits[static_cast<size_t>(bit)] = value;
256 set_status_bits(bits);
257}
void set_status_bits(std::bitset< 32 > status_bits)
Overwrite the status_bits header field.
Definition Fragment.hpp:112

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

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

◆ set_trigger_number()

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

Definition at line 74 of file Fragment.hpp.

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

◆ set_trigger_timestamp()

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

Definition at line 80 of file Fragment.hpp.

80{ 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 141 of file Fragment.hpp.

141{ 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:21

◆ set_window_begin()

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

Definition at line 83 of file Fragment.hpp.

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

◆ set_window_end()

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

Definition at line 86 of file Fragment.hpp.

86{ 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 180 of file Fragment.hpp.

180{ false };

◆ m_data_arr

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

Points to flat memory containing a FragmentHeader and the data payload.

Definition at line 179 of file Fragment.hpp.

179{ nullptr };

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