MilliSliceFragmentWriter.hh
Go to the documentation of this file.
1 #ifndef dune_artdaq_Overlays_MilliSliceFragmentWriter_hh
2 #define dune_artdaq_Overlays_MilliSliceFragmentWriter_hh
3 
6 
7 namespace dune {
8  class MilliSliceFragmentWriter;
9 }
10 
12 
13 public:
14 
15  // This constructor accepts an empty artdaq::Fragment and creates
16  // a MilliSlice inside it that can be filled with the appropriate data
17  MilliSliceFragmentWriter(artdaq::Fragment& frag, uint32_t max_size_bytes);
18 
19  // Reserves the next MicroSlice in memory within this MilliSlice.
20  // The MicroSliceWriter that is returned is initialized to an empty
21  // state and is ready to be populated with data. This method returns
22  // true if the MicroSlice was successfully added, false if not (for example,
23  // if the additional MicroSlice would overflow the maximum size of the
24  // MilliSlice).
25  std::shared_ptr<MicroSliceWriter> reserveMicroSlice(uint32_t ms_max_bytes);
26 
27  // Finalizes the MilliSlice. This takes care of updating the
28  // MilliSlice so that all internal pointers and data are consistent
29  // with the MicroSlices that have been added. No more MicroSlices
30  // can be added once the MilliSlice has been finalized.
31  // This method returns the number of bytes that were reclaimed
32  // when the maximum size for this MilliSlice was reduced to match
33  // its actual current size.
34  int32_t finalize();
35 
36 protected:
37 
38  // finalizes the MicroSlice that was most recently added and
39  // updates our size to reflect any memory that was reclaimed
40  // by finalizing the MicroSlice
42 
43  // returns a pointer to the header
44  Header* header_();
45 
46  // returns a pointer to the requested MicroSlice
47  uint8_t* data_(int index);
48 
49  uint32_t max_size_bytes_;
50  std::shared_ptr<MicroSliceWriter> latest_microslice_ptr_;
51 
52 private:
53 
54  // Note that this non-const reference hides the const reference in the base
55  // class.
56  // Also Note that we store a reference to the artdaq::Fragment and look up
57  // the dataBeginBytes() each time that we need it so that we are insulated
58  // from changes in the overall layout of the Fragment. Of course, what we
59  // have in the MilliSlice, MicroSlice, and NanoSlice writers isn't infinitely
60  // flexible: If the Fragment is modified in the middle of populating data at
61  // one of these levels, then users should understand that their existing
62  // MicroSliceWriter and NanoSliceWriter references will be invalid.
63  artdaq::Fragment& artdaq_fragment_;
64 };
65 
66 #endif /* dune_artdaq_Overlays_MilliSliceFragmentWriter_hh */
std::shared_ptr< MicroSliceWriter > reserveMicroSlice(uint32_t ms_max_bytes)
MilliSliceFragmentWriter(artdaq::Fragment &frag, uint32_t max_size_bytes)
std::shared_ptr< MicroSliceWriter > latest_microslice_ptr_