MicroSliceWriter.cc
Go to the documentation of this file.
2 #include "cetlib_except/exception.h"
3 
4 dune::MicroSliceWriter::MicroSliceWriter(uint8_t* address, uint32_t max_size_bytes) :
5  MicroSlice(address), max_size_bytes_(max_size_bytes)
6 {
7  header_()->version = 1;
8  header_()->microslice_size = sizeof(Header);
10 }
11 
12 std::shared_ptr<dune::NanoSliceWriter>
14 {
15  // finalize the most recent NanoSlice, in case that hasn't
16  // already been done
18 
19  // test if this new NanoSlice could overflow our maximum size
20  if ((size() + ns_max_bytes) > max_size_bytes_) {
21  throw cet::exception("MicroSliceWriter") << "Slice overflow error";
22  }
23 
24  // create the next NanoSlice in our buffer, and update our
25  // counters to include the new NanoSlice
26  uint8_t* ns_ptr = data_(header_()->nanoslice_count);
27  latest_nanoslice_ptr_.reset(new NanoSliceWriter(ns_ptr, ns_max_bytes));
28  ++(header_()->nanoslice_count);
29  header_()->microslice_size += ns_max_bytes;
30  return latest_nanoslice_ptr_;
31 }
32 
34 {
35  // first, we need to finalize the last NanoSlice, in case that
36  // hasn't already been done
38 
39  // next, we update our maximum size so that no more NanoSlices
40  // can be added
41  int32_t size_diff = max_size_bytes_ - header_()->microslice_size;
43  return size_diff;
44 }
45 
47 {
48  if (header_()->nanoslice_count > 0 &&
49  latest_nanoslice_ptr_.get() != 0) {
50  int size_change = latest_nanoslice_ptr_->finalize();
51  header_()->microslice_size -= size_change;
52  }
53 }
54 
56 {
57  return reinterpret_cast<Header *>(buffer_);
58 }
uint8_t * data_(uint32_t index) const
Definition: MicroSlice.cc:32
uint8_t * buffer_
Definition: MicroSlice.hh:53
MicroSliceWriter(uint8_t *address, uint32_t max_size_bytes)
std::shared_ptr< NanoSliceWriter > latest_nanoslice_ptr_
Header::microslice_size_t size() const
Definition: MicroSlice.cc:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::shared_ptr< NanoSliceWriter > reserveNanoSlice(uint32_t ns_max_bytes)