MilliSliceWriter.cc
Go to the documentation of this file.
2 #include "cetlib_except/exception.h"
3 
5 MilliSliceWriter(uint8_t* address, uint32_t max_size_bytes) :
6  MilliSlice(address), max_size_bytes_(max_size_bytes)
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("MilliSliceWriter") << "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 *>(buffer_);
59 }
60 
62 {
63  uint8_t* ms_ptr = buffer_ + sizeof(Header);
64  for (int idx = 0; idx < index; ++idx) {
65  MicroSlice tmp_ms(ms_ptr);
66  ms_ptr += tmp_ms.size();
67  }
68  return ms_ptr;
69 }
uint8_t * data_(int index)
Header::microslice_size_t size() const
Definition: MicroSlice.cc:7
MilliSliceWriter(uint8_t *address, uint32_t max_size_bytes)
uint8_t * buffer_
Definition: MilliSlice.hh:56
std::shared_ptr< MicroSliceWriter > reserveMicroSlice(uint32_t ms_max_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