CMS 3D CMS Logo

StreamSerializer.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_StreamSerializer_h
2 #define IOPool_Streamer_StreamSerializer_h
3 
11 #include "TBufferFile.h"
12 
13 #include <cstdint>
14 #include <vector>
15 
20 
21 // Data structure to be shared by all output modules for event serialization
23  typedef std::vector<char> SBuffer;
24  static constexpr int init_size = 0; //will be allocated on first event
25  static constexpr unsigned int reserve_size = 50000;
26 
28  : comp_buf_(reserve_size + init_size),
31  rootbuf_(TBuffer::kWrite, init_size),
32  ptr_((unsigned char *)rootbuf_.Buffer()),
33  header_buf_(),
34  adler32_chksum_(0) {}
35 
36  // This object caches the results of the last INIT or event
37  // serialization operation. You get access to the data using the
38  // following member functions.
39 
40  unsigned char const *bufferPointer() const { return get_underlying_safe(ptr_); }
41  unsigned char *&bufferPointer() { return get_underlying_safe(ptr_); }
42  unsigned int currentSpaceUsed() const { return curr_space_used_; }
43  unsigned int currentEventSize() const { return curr_event_size_; }
44  uint32_t adler32_chksum() const { return adler32_chksum_; }
45 
47  header_buf_.clear();
48  header_buf_.shrink_to_fit();
49  rootbuf_.Reset();
50  rootbuf_.Expand(init_size); //shrink TBuffer to size 0 after resetting TBuffer length
51  }
52 
53  std::vector<unsigned char> comp_buf_; // space for compressed data
54  unsigned int curr_event_size_;
55  unsigned int curr_space_used_; // less than curr_event_size_ if compressed
56  TBufferFile rootbuf_;
57  edm::propagate_const<unsigned char *> ptr_; // set to the place where the last event stored
58  SBuffer header_buf_; // place for INIT message creation and streamer event header
59  uint32_t adler32_chksum_; // adler32 check sum for the (compressed) data
60 };
61 
62 class EventMsgBuilder;
63 class InitMsgBuilder;
64 namespace edm {
65  enum StreamerCompressionAlgo { UNCOMPRESSED = 0, ZLIB = 1, LZMA = 2, ZSTD = 4 };
66 
67  class EventForOutput;
70 
72  public:
74 
75  int serializeRegistry(SerializeDataBuffer &data_buffer,
76  const BranchIDLists &branchIDLists,
77  ThinnedAssociationsHelper const &thinnedAssociationsHelper);
78 
79  int serializeEvent(SerializeDataBuffer &data_buffer,
80  EventForOutput const &event,
81  ParameterSetID const &selectorConfig,
82  StreamerCompressionAlgo compressionAlgo,
84  unsigned int reserveSize) const;
85 
91  static unsigned int compressBuffer(unsigned char *inputBuffer,
92  unsigned int inputSize,
93  std::vector<unsigned char> &outputBuffer,
94  int compressionLevel,
95  unsigned int reserveSize);
96 
97  static unsigned int compressBufferLZMA(unsigned char *inputBuffer,
98  unsigned int inputSize,
99  std::vector<unsigned char> &outputBuffer,
100  int compressionLevel,
101  unsigned int reserveSize,
102  bool addHeader = true);
103 
104  static unsigned int compressBufferZSTD(unsigned char *inputBuffer,
105  unsigned int inputSize,
106  std::vector<unsigned char> &outputBuffer,
107  int compressionLevel,
108  unsigned int reserveSize,
109  bool addHeader = true);
110 
111  private:
114  };
115 
116 } // namespace edm
117 
118 #endif
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
std::vector< char > SBuffer
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
unsigned int currentSpaceUsed() const
static constexpr int init_size
std::vector< unsigned char > comp_buf_
unsigned int curr_event_size_
unsigned char const * bufferPointer() const
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
unsigned int curr_space_used_
unsigned char *& bufferPointer()
SelectedProducts const * selections_
uint32_t adler32_chksum() const
HLT enums.
static constexpr unsigned int reserve_size
StreamerCompressionAlgo
unsigned int currentEventSize() const
#define constexpr
Definition: event.py:1
edm::propagate_const< unsigned char * > ptr_
edm::propagate_const< TClass * > tc_