1 #ifndef artdaq_core_Data_ContainerFragment_hh
2 #define artdaq_core_Data_ContainerFragment_hh
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "cetlib_except/exception.h"
14 class ContainerFragment;
24 static constexpr uint8_t CURRENT_VERSION = 1;
25 static constexpr
size_t CONTAINER_MAGIC = 0x00BADDEED5B1BEE5;
69 uint64_t index_offset;
78 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Upgrading ContainerFragment::MetadataV0 into new ContainerFragment::Metadata";
79 assert(in->
block_count < std::numeric_limits<Metadata::count_t>::max());
80 metadata_alloc_ =
true;
87 index_ptr_ = in->
index;
98 explicit ContainerFragment(
Fragment const& f) : artdaq_Fragment_(f), index_ptr_(nullptr), index_alloc_(false),metadata_(nullptr), metadata_alloc_(false) { }
118 if (metadata_alloc_)
return metadata_;
150 return reinterpret_cast<void const *
>(&*artdaq_Fragment_.
dataBegin());
172 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::at was asked for a non-existent Fragment!";
189 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragSize was asked for a non-existent Fragment!";
192 if (index == 0)
return end;
204 return this->
at(index);
217 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragmentIndex was asked for a non-existent Fragment!";
219 if (index == 0) {
return 0; }
221 auto index_ptr = get_index_();
223 return index_ptr[index - 1];
246 const size_t* create_index_()
const
248 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Creating new index for ContainerFragment";
251 auto current =
reinterpret_cast<uint8_t const*
>(artdaq_Fragment_.
dataBegin());
258 current += this_size;
264 void reset_index_ptr_()
const
266 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Request to reset index_ptr recieved. has_index=" <<
metadata()->has_index <<
", Check word = " << std::hex
270 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Setting index_ptr to found valid index";
271 index_ptr_ =
reinterpret_cast<size_t const*
>(artdaq_Fragment_.
dataBeginBytes() +
metadata()->index_offset);
275 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Index invalid or not found, allocating new index";
282 index_ptr_ = create_index_();
286 const size_t* get_index_()
const
288 if (index_ptr_ !=
nullptr)
return index_ptr_;
296 Fragment
const& artdaq_Fragment_;
298 mutable const size_t* index_ptr_;
299 mutable bool index_alloc_;
300 mutable const Metadata* metadata_;
301 mutable bool metadata_alloc_;
std::unique_ptr< Fragment > FragmentPtr
A std::unique_ptr to a Fragment object.
static constexpr size_t words_per_frag_word_()
Gets the ratio between the fundamental data storage type and the representation within the Fragment...
size_t fragmentIndex(size_t index) const
Get the offset of a Fragment within the ContainerFragment.
The artdaq::ContainerFragment class represents a Fragment which contains other Fragments.
std::size_t dataSizeBytes() const
Return the number of bytes in the data payload. This does not include the number of bytes in the head...
std::size_t sizeBytes() const
Size of vals_ vector ( header + (optional) metadata + payload) in bytes.
byte_t * dataBeginBytes()
Return Fragment::byte_t* pointing at the beginning of the payload.
detail::RawFragmentHeader::type_t type_t
typedef for type_t from RawFragmentHeader
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.
size_t lastFragmentIndex() const
Returns the offset of the last Fragment in the ContainerFragment.
iterator dataBegin()
Return an iterator to the beginning of the data payload (after header and metadata) ...
QuickVec< RawDataType >::value_type value_type
Alias value_type type from QuickVec<RawDataType>
void const * dataBegin() const
Gets the start of the data.
void 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...
Metadata const * metadata() const
const getter function for the Metadata
detail::RawFragmentHeader::RawDataType RawDataType
The RawDataType (currently a 64-bit integer) is the basic unit of data representation within artdaq ...
FragmentPtr operator[](size_t index) const
Alias to ContainerFragment::at()
A Fragment contains the data from one piece of the DAQ system for one event The artdaq::Fragment is t...
FragmentPtr at(size_t index) const
Gets a specific Fragment from the ContainerFragment.
size_t fragSize(size_t index) const
Gets the size of the Fragment at the specified location in the ContainerFragment, in bytes...