1 #ifndef artdaq_core_Data_ContainerFragment_hh
2 #define artdaq_core_Data_ContainerFragment_hh
5 #include "artdaq-core/Data/Fragment.hh"
6 #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());
92 index_ptr_ = in->
index;
93 metadata_ = std::make_unique<Metadata>(md);
94 return metadata_.get();
104 : artdaq_Fragment_(f), index_ptr_(nullptr), index_ptr_owner_(nullptr), metadata_(nullptr) {}
116 if (metadata_)
return metadata_.get();
148 return reinterpret_cast<void const*
>(&*artdaq_Fragment_.
dataBegin());
170 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::at was asked for a non-existent Fragment!";
177 TLOG(TLVL_WARNING,
"ContainerFragment") <<
"Contained Fragment is below minimum size! Reported Data and Metadata sizes will be incorrect!";
178 frag = std::make_unique<Fragment>();
199 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragSize was asked for a non-existent Fragment!";
202 if (index == 0)
return end;
214 return this->
at(index);
227 throw cet::exception(
"ArgumentOutOfRange") <<
"Buffer overrun detected! ContainerFragment::fragmentIndex was asked for a non-existent Fragment!";
229 if (index == 0) {
return 0; }
233 return index_ptr[index - 1];
261 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Creating new index for ContainerFragment";
264 auto current =
reinterpret_cast<uint8_t const*
>(artdaq_Fragment_.
dataBegin());
270 index_ptr_owner_->at(ii) = offset;
271 current += this_size;
274 return &index_ptr_owner_->at(0);
283 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Request to reset index_ptr recieved. has_index=" <<
metadata()->
has_index <<
", Check word = " << std::hex
287 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Setting index_ptr to found valid index";
292 TLOG(TLVL_TRACE,
"ContainerFragment") <<
"Index invalid or not found, allocating new index";
293 index_ptr_owner_.reset(
nullptr);
304 if (index_ptr_ !=
nullptr)
return index_ptr_;
319 mutable const size_t* index_ptr_;
320 mutable std::unique_ptr<std::vector<size_t>> index_ptr_owner_;
321 mutable std::unique_ptr<Metadata> metadata_;
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 ...
size_t headerSizeBytes() const
Get the size of this Fragment's header, in bytes.
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...