1 #ifndef artdaq_ots_Overlays_UDPFragmentWriter_hh
2 #define artdaq_ots_Overlays_UDPFragmentWriter_hh
17 #include "artdaq-core/Data/Fragment.hh"
18 #include "artdaq-ots/Overlays/UDPFragment.hh"
24 class UDPFragmentWriter;
43 assert(artdaq_Fragment_.dataSizeBytes() >=
sizeof(
Header));
44 return reinterpret_cast<Header*
>(artdaq_Fragment_.dataBeginBytes());
47 void set_hdr_type(Header::data_type_t dataType) { header_()->type = dataType & 0xF; }
49 void resize(
size_t nBytes);
52 size_t calc_event_size_words_(
size_t nBytes);
54 static size_t bytes_to_words_(
size_t nBytes);
57 artdaq::Fragment& artdaq_Fragment_;
64 ots::UDPFragmentWriter::UDPFragmentWriter(artdaq::Fragment& f) :
UDPFragment(f), artdaq_Fragment_(f)
66 if(!f.hasMetadata() || f.dataSizeBytes() > 0)
69 "Error in UDPFragmentWriter: Raw artdaq::Fragment object does not appear to "
70 "consist of (and only of) its own header + the UDPFragment::Metadata object");
74 artdaq_Fragment_.resizeBytes(
sizeof(Header));
77 inline uint8_t* ots::UDPFragmentWriter::dataBegin()
80 assert(artdaq_Fragment_.dataSizeBytes() >=
sizeof(Header) +
sizeof(artdaq::Fragment::value_type));
81 return reinterpret_cast<uint8_t*
>(header_() + 1);
84 inline uint8_t* ots::UDPFragmentWriter::dataEnd() {
return dataBegin() + udp_data_words(); }
86 inline void ots::UDPFragmentWriter::resize(
size_t nBytes)
88 artdaq_Fragment_.resizeBytes(
sizeof(Header::data_t) * calc_event_size_words_(nBytes));
89 header_()->event_size = calc_event_size_words_(nBytes);
92 inline size_t ots::UDPFragmentWriter::calc_event_size_words_(
size_t nBytes) {
return bytes_to_words_(nBytes) + hdr_size_words(); }
94 inline size_t ots::UDPFragmentWriter::bytes_to_words_(
size_t nBytes)
96 auto mod(nBytes % bytes_per_word_());
97 return (mod == 0) ? nBytes / bytes_per_word_() : nBytes / bytes_per_word_() + 1;