MilliSliceFragmentWriter.cc
Go to the documentation of this file.
2 #include "cetlib_except/exception.h"
3 
5 MilliSliceFragmentWriter(artdaq::Fragment& frag, uint32_t max_size_bytes) :
6  MilliSliceFragment(frag), max_size_bytes_(max_size_bytes), artdaq_fragment_(frag)
7 {
8  header_()->version = 1;
9  header_()->millislice_size = sizeof(Header);
11 }
12 
13 std::shared_ptr<dune::MicroSliceWriter>
15 {
16  // finalize the most recent MicroSlice, in case that hasn't
17  // already been done
19 
20  // test if this new MicroSlice could overflow our maximum size
21  if ((size() + ms_max_bytes) > max_size_bytes_) {
22  throw cet::exception("MicroSliceWriter") << "Slice overflow error";
23  }
24 
25  // create the next MicroSlice in our buffer, and update our
26  // counters to include the new MicroSlice
27  uint8_t* ms_ptr = data_(header_()->microslice_count);
28  latest_microslice_ptr_.reset(new MicroSliceWriter(ms_ptr, ms_max_bytes));
30  header_()->millislice_size += ms_max_bytes;
32 }
33 
35 {
36  // first, we need to finalize the last MicroSlice, in case that
37  // hasn't already been done
39 
40  // next, we update our maximum size so that no more MicroSlices
41  // can be added
42  int32_t size_diff = max_size_bytes_ - header_()->millislice_size;
44  return size_diff;
45 }
46 
48 {
49  if (header_()->microslice_count > 0 &&
50  latest_microslice_ptr_.get() != 0) {
51  int size_change = latest_microslice_ptr_->finalize();
52  header_()->millislice_size -= size_change;
53  }
54 }
55 
57 {
58  return reinterpret_cast<Header *>(artdaq_fragment_.dataBeginBytes());
59 }
60 
62 {
63  uint8_t* ms_ptr = reinterpret_cast<uint8_t *>(artdaq_fragment_.dataBeginBytes())
64  + sizeof(Header);
65  for (int idx = 0; idx < index; ++idx) {
66  MicroSlice tmp_ms(ms_ptr);
67  ms_ptr += tmp_ms.size();
68  }
69  return ms_ptr;
70 }
std::shared_ptr< MicroSliceWriter > reserveMicroSlice(uint32_t ms_max_bytes)
Header::microslice_size_t size() const
Definition: MicroSlice.cc:7
MilliSliceFragmentWriter(artdaq::Fragment &frag, uint32_t max_size_bytes)
std::shared_ptr< MicroSliceWriter > latest_microslice_ptr_
Header::millislice_size_t size() const
Definition: MilliSlice.cc:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33