DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TimeSlice.hpp
Go to the documentation of this file.
1
8
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 explicit TimeSlice(timeslice_number_t timeslice_number, run_number_t run_number);
33
38 explicit TimeSlice(TimeSliceHeader const& header);
39
49 void set_header(TimeSliceHeader header) { m_header = header; }
50
55 const std::vector<std::unique_ptr<Fragment>>& get_fragments_ref() const { return m_fragments; }
56
61 void set_fragments(std::vector<std::unique_ptr<Fragment>>&& fragments) { m_fragments = std::move(fragments); }
62
67 void add_fragment(std::unique_ptr<Fragment>&& fragment) { m_fragments.emplace_back(std::move(fragment)); }
68
73 void set_element_id(SourceID source_id) { m_header.element_id = source_id; }
74
78 size_t get_total_size_bytes() const
79 {
80 size_t total_size = sizeof(get_header());
81
82 for (auto const& frag_ptr : m_fragments)
83 total_size += frag_ptr->get_size();
84
85 return total_size;
86 }
87
92 {
93 size_t total_size = 0;
94
95 for (auto const& frag_ptr : m_fragments)
96 total_size += frag_ptr->get_data_size();
97
98 return total_size;
99 }
100
101 TimeSlice(TimeSlice const&) = delete;
102 TimeSlice& operator=(TimeSlice const&) = delete;
103 TimeSlice(TimeSlice&&) = default;
105
106 ~TimeSlice() = default;
107
108private:
110 std::vector<std::unique_ptr<Fragment>> m_fragments;
111};
112
113//-------
114
115inline TimeSlice::TimeSlice(timeslice_number_t timeslice_number, run_number_t run_number)
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
129} // namespace dunedaq::daqdataformats
130
131#endif // DAQDATAFORMATS_INCLUDE_DAQDATAFORMATS_TIMESLICE_HPP_
void add_fragment(std::unique_ptr< Fragment > &&fragment)
Add a Fragment pointer to the Fragments vector.
Definition TimeSlice.hpp:67
size_t get_total_size_bytes() const
Get size of timeslice from underlying TimeSliceHeader and Fragments.
Definition TimeSlice.hpp:78
TimeSlice & operator=(TimeSlice &&)=default
Default TimeSlice move assignment operator.
TimeSliceHeader get_header() const
Get a copy of the TimeSliceHeader struct.
Definition TimeSlice.hpp:44
void set_header(TimeSliceHeader header)
Set the TimeSliceHeader to the given TimeSliceHeader object.
Definition TimeSlice.hpp:49
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 some 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:61
~TimeSlice()=default
TimeSlice default destructor.
size_t get_sum_of_fragment_payload_sizes() const
Get the sum of the fragment payload sizes.
Definition TimeSlice.hpp:91
const std::vector< std::unique_ptr< Fragment > > & get_fragments_ref() const
Get a handle to the Fragments.
Definition TimeSlice.hpp:55
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:73
uint64_t timeslice_number_t
Definition Types.hpp:40
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
Data fields associated with a TimeSliceHeader.