DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TimeSlice.hpp
Go to the documentation of this file.
1
9#ifndef DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_TIMESLICE_HPP_
10#define DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_TIMESLICE_HPP_
11
15
16#include <memory>
17#include <utility>
18#include <vector>
19
21
27{
28public:
32 inline explicit TimeSlice(timeslice_number_t timeslice_number, run_number_t run_number);
33
38 inline explicit TimeSlice(TimeSliceHeader const& header);
39
40 virtual ~TimeSlice() = default;
41
42 TimeSlice(TimeSlice const&) = delete;
43 TimeSlice(TimeSlice&&) = default;
44 TimeSlice& operator=(TimeSlice const&) = delete;
46
56 void set_header(TimeSliceHeader header) { m_header = header; }
57
62 const std::vector<std::unique_ptr<Fragment>>& get_fragments_ref() const { return m_fragments; }
63
68 void set_fragments(std::vector<std::unique_ptr<Fragment>>&& fragments) { m_fragments = std::move(fragments); }
69
74 void add_fragment(std::unique_ptr<Fragment>&& fragment) { m_fragments.emplace_back(std::move(fragment)); }
75
80 void set_element_id(SourceID source_id) { m_header.element_id = source_id; }
81
85 size_t get_total_size_bytes() const
86 {
87 size_t total_size = sizeof(get_header());
88
89 for (auto const& frag_ptr : m_fragments)
90 total_size += frag_ptr->get_size();
91
92 return total_size;
93 }
94
99 {
100 size_t total_size = 0;
101
102 for (auto const& frag_ptr : m_fragments)
103 total_size += frag_ptr->get_data_size();
104
105 return total_size;
106 }
107
108private:
110 std::vector<std::unique_ptr<Fragment>> m_fragments;
111};
112
113//-------
114
116 : m_header()
117 , m_fragments()
118{
119 m_header.timeslice_number = timeslice_number;
120 m_header.run_number = run_number;
121}
122
124 : m_header(header)
125 , m_fragments()
126{}
127
128} // namespace dunedaq::daqdataformats
129
130#endif // DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_TIMESLICE_HPP_
C++ Representation of a DUNE TimeSlice, consisting of a TimeSliceHeader object and a vector of pointe...
Definition TimeSlice.hpp:27
void add_fragment(std::unique_ptr< Fragment > &&fragment)
Add a Fragment pointer to the Fragments vector.
Definition TimeSlice.hpp:74
size_t get_total_size_bytes() const
Get size of timeslice from underlying TimeSliceHeader and Fragments.
Definition TimeSlice.hpp:85
TimeSlice & operator=(TimeSlice &&)=default
Default TimeSlice move assignment operator.
TimeSliceHeader get_header() const
Get a copy of the TimeSliceHeader struct.
Definition TimeSlice.hpp:51
void set_header(TimeSliceHeader header)
Set the TimeSliceHeader to the given TimeSliceHeader object.
Definition TimeSlice.hpp:56
std::vector< std::unique_ptr< Fragment > > m_fragments
Vector of unique_ptrs to Fragment objects.
TimeSlice(timeslice_number_t timeslice_number, run_number_t run_number)
Construct a TimeSlice, filling in header fields.
TimeSlice(TimeSlice const &)=delete
TimeSlices are not copy-constructible.
TimeSlice(TimeSlice &&)=default
Default TimeSlice move constructor.
void set_fragments(std::vector< std::unique_ptr< Fragment > > &&fragments)
Set the Fragments vector to the given vector of Fragments.
Definition TimeSlice.hpp:68
size_t get_sum_of_fragment_payload_sizes() const
Get the sum of the fragment payload sizes.
Definition TimeSlice.hpp:98
const std::vector< std::unique_ptr< Fragment > > & get_fragments_ref() const
Get a handle to the Fragments.
Definition TimeSlice.hpp:62
TimeSlice & operator=(TimeSlice const &)=delete
TimeSlices are not copy-assignable.
TimeSliceHeader m_header
TimeSliceHeader object.
void set_element_id(SourceID source_id)
Set the SourceID for this TimeSlice.
Definition TimeSlice.hpp:80
virtual ~TimeSlice()=default
TimeSlice default destructor.
uint32_t run_number_t
Type used to represent run number.
Definition Types.hpp:20
uint64_t timeslice_number_t
Type used to represent timeslice number.
Definition Types.hpp:49
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
Additional data fields associated with a TimeSliceHeader.
run_number_t run_number
Run Number for the TimeSlice.
timeslice_number_t timeslice_number
Slice number of this TimeSlice within the stream.