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