1 #ifndef artdaq_ots_Overlays_STIBFragmentWriter_hh
2 #define artdaq_ots_Overlays_STIBFragmentWriter_hh
17 #include "artdaq-core/Data/Fragment.hh"
18 #include "otsdaq-demo/Overlays/STIBFragment.hh"
24 class STIBFragmentWriter;
43 assert(artdaq_Fragment_.dataSizeBytes() >=
sizeof(
Header));
44 return reinterpret_cast<Header*
>(artdaq_Fragment_.dataBeginBytes());
47 void set_hdr_bunch_counter(Header::counter_t counter)
49 header_()->bunch_counter = counter;
52 void set_hdr_trigger_counter(Header::counter_t counter)
54 header_()->trigger_counter = counter;
57 void set_hdr_trigger_input0(Header::counter_t input)
59 header_()->trigger_input0 = input;
62 void set_hdr_trigger_input1(Header::counter_t input)
64 header_()->trigger_input1 = input;
67 void resize(
size_t nBytes);
70 size_t calc_event_size_words_(
size_t nBytes);
72 static size_t bytes_to_words_(
size_t nBytes);
76 artdaq::Fragment& artdaq_Fragment_;
83 ots::STIBFragmentWriter::STIBFragmentWriter(artdaq::Fragment& f)
86 if(!f.hasMetadata() || f.dataSizeBytes() > 0)
89 "Error in STIBFragmentWriter: Raw artdaq::Fragment "
90 "object does not appear to consist of (and only of) "
91 "its own header + the STIBFragment::Metadata object");
95 artdaq_Fragment_.resizeBytes(
sizeof(Header));
98 inline uint8_t* ots::STIBFragmentWriter::dataBegin()
101 assert(artdaq_Fragment_.dataSizeBytes() >=
102 sizeof(Header) +
sizeof(artdaq::Fragment::value_type));
103 return reinterpret_cast<uint8_t*
>(header_() + 1);
106 inline uint8_t* ots::STIBFragmentWriter::dataEnd()
108 return dataBegin() + stib_data_words();
111 inline void ots::STIBFragmentWriter::resize(
size_t nBytes)
113 artdaq_Fragment_.resizeBytes(
sizeof(Header::data_t) * calc_event_size_words_(nBytes));
114 header_()->event_size = calc_event_size_words_(nBytes);
117 inline size_t ots::STIBFragmentWriter::calc_event_size_words_(
size_t nBytes)
119 return bytes_to_words_(nBytes) + hdr_size_words();
122 inline size_t ots::STIBFragmentWriter::bytes_to_words_(
size_t nBytes)
124 auto mod(nBytes % bytes_per_word_());
125 return (mod == 0) ? nBytes / bytes_per_word_() : nBytes / bytes_per_word_() + 1;