artdaq_core  v1_07_04
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ContainerFragment.hh
1 #ifndef artdaq_core_Data_ContainerFragment_hh
2 #define artdaq_core_Data_ContainerFragment_hh
3 
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib/exception.h"
6 
7 //#include <ostream>
8 //#include <vector>
9 
10 // Implementation of "ContainerFragment", an artdaq::Fragment overlay class
11 
12 #ifndef CONTAINER_FRAGMENT_CAPACITY
13 #define CONTAINER_FRAGMENT_CAPACITY 100
15 #endif
16 
17 namespace artdaq
18 {
19  class ContainerFragment;
20 
24  static const int CONTAINER_FRAGMENT_COUNT_MAX = CONTAINER_FRAGMENT_CAPACITY;
25 }
26 
31 {
32 public:
33 
37  struct Metadata
38  {
39  typedef uint8_t data_t;
40  typedef uint64_t count_t;
41 
45 
48 
50  static size_t const size_words = 8ul + CONTAINER_FRAGMENT_COUNT_MAX * sizeof(size_t) / sizeof(data_t); // Units of Header::data_t
51  };
52 
53  static_assert (sizeof(Metadata) == Metadata::size_words * sizeof(Metadata::data_t), "ContainerFragment::Metadata size changed");
54 
61  explicit ContainerFragment(Fragment const& f) : artdaq_Fragment_(f) { }
62 
67  Metadata const* metadata() const { return artdaq_Fragment_.metadata<Metadata>(); }
68 
83  bool missing_data() const { return static_cast<bool>(metadata()->missing_data); }
84 
89  Fragment const* dataBegin() const
90  {
91  return reinterpret_cast<Fragment const *>(&*artdaq_Fragment_.dataBegin());
92  }
93 
98  Fragment const* dataEnd() const
99  {
100  return reinterpret_cast<Fragment const *>(reinterpret_cast<uint8_t const *>(dataBegin()) + lastFragmentIndex());
101  }
102 
109  Fragment const* at(size_t index) const
110  {
111  if (index > block_count()) throw cet::exception("Buffer overrun detected! ContainerFragment::at was asked for a non-existant Fragment!");
112  return reinterpret_cast<Fragment const *>(reinterpret_cast<uint8_t const *>(dataBegin()) + fragmentIndex(index));
113  }
114 
121  size_t fragSize(size_t index) const
122  {
123  if (index >= block_count()) throw cet::exception("Buffer overrun detected! ContainerFragment::at was asked for a non-existant Fragment!");
124  auto end = metadata()->index[index];
125  if (index == 0) return end;
126  return end - metadata()->index[index - 1];
127  }
128 
135  Fragment const* operator[](size_t index) const
136  {
137  return this->at(index);
138  }
139 
146  size_t fragmentIndex(size_t index) const
147  {
148  if (index > block_count()) throw cet::exception("Buffer overrun detected! ContainerFragment::at was asked for a non-existant Fragment!");
149  if (index == 0) { return 0; }
150  return metadata()->index[index - 1];
151  }
152 
157  size_t lastFragmentIndex() const
158  {
159  return fragmentIndex(block_count());
160  }
161 
162 protected:
163 
168  static constexpr size_t words_per_frag_word_()
169  {
170  return sizeof(Fragment::value_type) / sizeof(Metadata::data_t);
171  }
172 
173 private:
174 
175  Fragment const& artdaq_Fragment_;
176 };
177 
178 #endif /* artdaq_core_Data_ContainerFragment_hh */
static constexpr size_t words_per_frag_word_()
Gets the ratio between the fundamental data storage type and the representation within the Fragment...
static size_t const size_words
Size of the Metadata object.
size_t fragmentIndex(size_t index) const
Get the offset of a Fragment within the ContainerFragment.
Fragment const * dataBegin() const
Gets the start of the data.
The artdaq::ContainerFragment class represents a Fragment which contains other Fragments.
uint64_t count_t
Size of block_count variables.
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
Definition: Fragment.hh:133
bool missing_data() const
Gets the flag if the ContainerFragment knows that it is missing data.
Fragment::type_t fragment_type() const
Get the Fragment::type_t of stored Fragment objects.
static const int CONTAINER_FRAGMENT_COUNT_MAX
The maximum capacity of the ContainerFragment (in fragments)
count_t fragment_type
The Fragment::type_t of stored Fragment objects.
size_t lastFragmentIndex() const
Returns the offset of the last Fragment in the ContainerFragment.
Fragment const * operator[](size_t index) const
Alias to ContainerFragment::at()
count_t block_count
The number of Fragment objects stored in the ContainerFragment.
iterator dataBegin()
Return an iterator to the beginning of the data payload (after header and metadata) ...
Definition: Fragment.hh:1008
QuickVec< RawDataType >::value_type value_type
Alias value_type type from QuickVec&lt;RawDataType&gt;
Definition: Fragment.hh:180
Contains the information necessary for retrieving Fragment objects from the ContainerFragment.
count_t missing_data
Flag if the ContainerFragment knows that it is missing data.
Fragment const * dataEnd() const
Gets the last Fragment in the ContainerFragment.
ContainerFragment(Fragment const &f)
Metadata::count_t block_count() const
Gets the number of fragments stored in the ContainerFragment.
T * metadata()
Return a pointer to the metadata. This throws an exception if the Fragment contains no metadata...
Definition: Fragment.hh:892
Metadata const * metadata() const
const getter function for the Metadata
size_t index[CONTAINER_FRAGMENT_COUNT_MAX]
Offset of each Fragment within the ContainerFragment.
Fragment const * at(size_t index) const
Gets a specific Fragment from the ContainerFragment.
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
Definition: Fragment.hh:81
size_t fragSize(size_t index) const
Gets the size of the Fragment at the specified location in the ContainerFragment. ...
uint8_t data_t
Basic unit of data-retrieval.