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 
21 
22 // Data structure to be shared by all output modules for event serialization
24  typedef std::vector<char> SBuffer;
25  static constexpr int init_size = 0; //will be allocated on first event
26  static constexpr unsigned int reserve_size = 50000;
27 
32  rootbuf_(TBuffer::kWrite, init_size),
33  ptr_((unsigned char *)rootbuf_.Buffer()),
34  header_buf_(),
35  adler32_chksum_(0) {}
36 
37  // This object caches the results of the last INIT or event
38  // serialization operation. You get access to the data using the
39  // following member functions.
40 
41  unsigned char const *bufferPointer() const { return get_underlying_safe(ptr_); }
42  unsigned char *&bufferPointer() { return get_underlying_safe(ptr_); }
43  unsigned int currentSpaceUsed() const { return curr_space_used_; }
44  unsigned int currentEventSize() const { return curr_event_size_; }
45  uint32_t adler32_chksum() const { return adler32_chksum_; }
46 
48  header_buf_.clear();
49  header_buf_.shrink_to_fit();
50  rootbuf_.Reset();
51  rootbuf_.Expand(init_size); //shrink TBuffer to size 0 after resetting TBuffer length
52  }
53 
54  std::vector<unsigned char> comp_buf_; // space for compressed data
55  unsigned int curr_event_size_;
56  unsigned int curr_space_used_; // less than curr_event_size_ if compressed
57  TBufferFile rootbuf_;
58  edm::propagate_const<unsigned char *> ptr_; // set to the place where the last event stored
59  SBuffer header_buf_; // place for INIT message creation and streamer event header
60  uint32_t adler32_chksum_; // adler32 check sum for the (compressed) data
61 };
62 
63 class EventMsgBuilder;
64 class InitMsgBuilder;
65 namespace edm {
66  enum StreamerCompressionAlgo { UNCOMPRESSED = 0, ZLIB = 1, LZMA = 2, ZSTD = 4 };
67 
68  class EventForOutput;
69  class ModuleCallingContext;
70  class ThinnedAssociationsHelper;
71 
73  public:
75 
76  int serializeRegistry(SerializeDataBuffer &data_buffer,
77  const BranchIDLists &branchIDLists,
78  ThinnedAssociationsHelper const &thinnedAssociationsHelper);
79 
80  int serializeRegistry(SerializeDataBuffer &data_buffer,
81  const BranchIDLists &branchIDLists,
82  ThinnedAssociationsHelper const &thinnedAssociationsHelper,
83  SendJobHeader::ParameterSetMap const &psetMap);
84 
85  int serializeEvent(SerializeDataBuffer &data_buffer,
86  EventForOutput const &event,
87  ParameterSetID const &selectorConfig,
88  StreamerCompressionAlgo compressionAlgo,
90  unsigned int reserveSize) const;
91 
97  static unsigned int compressBuffer(unsigned char *inputBuffer,
98  unsigned int inputSize,
99  std::vector<unsigned char> &outputBuffer,
100  int compressionLevel,
101  unsigned int reserveSize);
102 
103  static unsigned int compressBufferLZMA(unsigned char *inputBuffer,
104  unsigned int inputSize,
105  std::vector<unsigned char> &outputBuffer,
106  int compressionLevel,
107  unsigned int reserveSize,
108  bool addHeader = true);
109 
110  static unsigned int compressBufferZSTD(unsigned char *inputBuffer,
111  unsigned int inputSize,
112  std::vector<unsigned char> &outputBuffer,
113  int compressionLevel,
114  unsigned int reserveSize,
115  bool addHeader = true);
116 
117  private:
120  };
121 
122 } // namespace edm
123 
124 #endif
static unsigned int compressBufferZSTD(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize, bool addHeader=true)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
unsigned int currentEventSize() const
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
std::vector< char > SBuffer
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
static constexpr int init_size
std::vector< unsigned char > comp_buf_
unsigned int curr_event_size_
int serializeEvent(SerializeDataBuffer &data_buffer, EventForOutput const &event, ParameterSetID const &selectorConfig, StreamerCompressionAlgo compressionAlgo, int compression_level, unsigned int reserveSize) const
int serializeRegistry(SerializeDataBuffer &data_buffer, const BranchIDLists &branchIDLists, ThinnedAssociationsHelper const &thinnedAssociationsHelper)
unsigned char const * bufferPointer() const
unsigned int curr_space_used_
unsigned int currentSpaceUsed() const
static unsigned int compressBufferLZMA(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize, bool addHeader=true)
uint32_t adler32_chksum() const
unsigned char *& bufferPointer()
SelectedProducts const * selections_
static unsigned int compressBuffer(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize)
HLT enums.
static constexpr unsigned int reserve_size
StreamerCompressionAlgo
Definition: event.py:1
edm::propagate_const< unsigned char * > ptr_
StreamSerializer(SelectedProducts const *selections)
edm::propagate_const< TClass * > tc_