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
InitMsgBuilder
Definition: InitMsgBuilder.h:9
edm::StreamSerializer::tc_
edm::propagate_const< TClass * > tc_
Definition: StreamSerializer.h:119
SerializeDataBuffer::init_size
static constexpr int init_size
Definition: StreamSerializer.h:25
edm::StreamSerializer::StreamSerializer
StreamSerializer(SelectedProducts const *selections)
Definition: StreamSerializer.cc:38
SerializeDataBuffer::curr_event_size_
unsigned int curr_event_size_
Definition: StreamSerializer.h:55
edm::UNCOMPRESSED
Definition: StreamSerializer.h:66
StreamedProducts.h
edm::ZSTD
Definition: StreamSerializer.h:66
edm
HLT enums.
Definition: AlignableModifier.h:19
SerializeDataBuffer::adler32_chksum
uint32_t adler32_chksum() const
Definition: StreamSerializer.h:45
edm::StreamSerializer::compressBufferZSTD
static unsigned int compressBufferZSTD(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize, bool addHeader=true)
Definition: StreamSerializer.cc:386
OnlineOutput_cfi.compression_level
compression_level
Definition: OnlineOutput_cfi.py:11
SerializeDataBuffer::header_buf_
SBuffer header_buf_
Definition: StreamSerializer.h:59
SerializeDataBuffer::SerializeDataBuffer
SerializeDataBuffer()
Definition: StreamSerializer.h:28
SerializeDataBuffer::SBuffer
std::vector< char > SBuffer
Definition: StreamSerializer.h:24
SerializeDataBuffer::comp_buf_
std::vector< unsigned char > comp_buf_
Definition: StreamSerializer.h:54
EventMsgBuilder
Definition: EventMsgBuilder.h:8
edm::SelectedProducts
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
Definition: SelectedProducts.h:11
edm::LZMA
Definition: StreamSerializer.h:66
edm::StreamSerializer
Definition: StreamSerializer.h:72
edm::propagate_const< unsigned char * >
edm::StreamSerializer::selections_
const SelectedProducts * selections_
Definition: StreamSerializer.h:118
EventForOutput
edm::Hash< ParameterSetType >
SerializeDataBuffer::bufferPointer
unsigned const char * bufferPointer() const
Definition: StreamSerializer.h:41
edm::StreamSerializer::compressBufferLZMA
static unsigned int compressBufferLZMA(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize, bool addHeader=true)
Definition: StreamSerializer.cc:302
edm::StreamSerializer::serializeEvent
int serializeEvent(SerializeDataBuffer &data_buffer, EventForOutput const &event, ParameterSetID const &selectorConfig, StreamerCompressionAlgo compressionAlgo, int compression_level, unsigned int reserveSize) const
Definition: StreamSerializer.cc:132
SerializeDataBuffer::clearHeaderBuffer
void clearHeaderBuffer()
Definition: StreamSerializer.h:47
edm::StreamerCompressionAlgo
StreamerCompressionAlgo
Definition: StreamSerializer.h:66
edm::BranchIDLists
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
edm::get_underlying_safe
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
Definition: get_underlying_safe.h:40
edm::ThinnedAssociationsHelper
Definition: ThinnedAssociationsHelper.h:35
SerializeDataBuffer::bufferPointer
unsigned char *& bufferPointer()
Definition: StreamSerializer.h:42
SerializeDataBuffer::rootbuf_
TBufferFile rootbuf_
Definition: StreamSerializer.h:57
BranchIDList.h
edm::StreamSerializer::serializeRegistry
int serializeRegistry(SerializeDataBuffer &data_buffer, const BranchIDLists &branchIDLists, ThinnedAssociationsHelper const &thinnedAssociationsHelper)
Definition: StreamSerializer.cc:45
edm::SendJobHeader::ParameterSetMap
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
Definition: StreamedProducts.h:104
edm::EventForOutput
Definition: EventForOutput.h:50
SerializeDataBuffer::ptr_
edm::propagate_const< unsigned char * > ptr_
Definition: StreamSerializer.h:58
edm::StreamSerializer::compressBuffer
static unsigned int compressBuffer(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel, unsigned int reserveSize)
Definition: StreamSerializer.cc:270
SerializeDataBuffer
Definition: StreamSerializer.h:23
edm::ZLIB
Definition: StreamSerializer.h:66
SerializeDataBuffer::adler32_chksum_
uint32_t adler32_chksum_
Definition: StreamSerializer.h:60
clusterbigeventsdebugger_cfi.selections
selections
Definition: clusterbigeventsdebugger_cfi.py:10
ParameterSetID.h
SerializeDataBuffer::reserve_size
static constexpr unsigned int reserve_size
Definition: StreamSerializer.h:26
NanoAODEDMEventContent_cff.compressionLevel
compressionLevel
Definition: NanoAODEDMEventContent_cff.py:15
event
Definition: event.py:1
get_underlying_safe.h
SerializeDataBuffer::currentEventSize
unsigned int currentEventSize() const
Definition: StreamSerializer.h:44
SelectedProducts.h
SerializeDataBuffer::currentSpaceUsed
unsigned int currentSpaceUsed() const
Definition: StreamSerializer.h:43
SerializeDataBuffer::curr_space_used_
unsigned int curr_space_used_
Definition: StreamSerializer.h:56