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;
84 TLOG(TLVL_DEBUG,
"ContainerFragment") <<
"Upgrading ContainerFragment::MetadataV0 into new ContainerFragment::Metadata";
85 assert(in->
block_count < std::numeric_limits<Metadata::count_t>::max());
86 metadata_alloc_ =
true;
93 index_ptr_ = in->
index;
104 explicit ContainerFragment(
Fragment const& f) : artdaq_Fragment_(f), index_ptr_(nullptr), index_alloc_(false),metadata_(nullptr), metadata_alloc_(false) { }
124 if (metadata_alloc_)
return metadata_;
156 return reinterpret_cast<void const *
>(&*artdaq_Fragment_.
dataBegin());
178 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::at was asked for a non-existent Fragment!";
195 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragSize was asked for a non-existent Fragment!";
198 if (index == 0)
return end;
210 return this->
at(index);
223 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragmentIndex was asked for a non-existent Fragment!";
225 if (index == 0) {
return 0; }
229 return index_ptr[index - 1];
258 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Creating new index for ContainerFragment";
261 auto current =
reinterpret_cast<uint8_t const*
>(artdaq_Fragment_.
dataBegin());
268 current += this_size;
280 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Request to reset index_ptr recieved. has_index=" <<
metadata()->
has_index <<
", Check word = " << std::hex
284 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Setting index_ptr to found valid index";
289 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Index invalid or not found, allocating new index";
306 if (index_ptr_ !=
nullptr)
return index_ptr_;
316 mutable const size_t* index_ptr_;
317 mutable bool index_alloc_;
318 mutable const Metadata* metadata_;
319 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...
void reset_index_ptr_() const
Reset the index pointer, creating a new index if necessary. ContainerFragmentLoader uses this functio...
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.
Metadata const * UpgradeMetadata(MetadataV0 const *in) const
Upgrade the Metadata of a fixed-size ContainerFragment to the new standard.
Fragment::type_t fragment_type() const
Get the Fragment::type_t of stored Fragment objects.
static constexpr size_t CONTAINER_MAGIC
Marker word used in index.
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>
const size_t * get_index_() const
Get a pointer to the index.
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)
const size_t * create_index_() const
Create an index for the currently-contained Fragments.
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...
static constexpr uint8_t CURRENT_VERSION
The current version of the ContainerFragmentHeader.
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...