CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/IOPool/Streamer/interface/StreamSerializer.h

Go to the documentation of this file.
00001 #ifndef IOPool_Streamer_StreamSerializer_h
00002 #define IOPool_Streamer_StreamSerializer_h
00003 
00011 #include "TBufferFile.h"
00012 
00013 #include "DataFormats/Provenance/interface/Selections.h"
00014 #include "DataFormats/Provenance/interface/ParameterSetID.h"
00015 #include <stdint.h>
00016 #include <vector>
00017 
00018 
00019 const int init_size = 1024*1024;
00020 
00021 // Data structure to be shared by all output modules for event serialization
00022 struct SerializeDataBuffer
00023 {
00024   typedef std::vector<char> SBuffer;
00025 
00026   SerializeDataBuffer():
00027     comp_buf_(init_size),
00028     curr_event_size_(),
00029     curr_space_used_(),
00030     rootbuf_(TBuffer::kWrite,init_size),
00031     ptr_((unsigned char*)rootbuf_.Buffer()),
00032     header_buf_(),
00033     bufs_(),
00034     adler32_chksum_(0)
00035   { }
00036 
00037   // This object caches the results of the last INIT or event 
00038   // serialization operation.  You get access to the data using the
00039   // following member functions.
00040 
00041   unsigned char* bufferPointer() const { return ptr_; }
00042   unsigned int currentSpaceUsed() const { return curr_space_used_; }
00043   unsigned int currentEventSize() const { return curr_event_size_; }
00044   uint32_t adler32_chksum() const { return adler32_chksum_; }
00045 
00046   std::vector<unsigned char> comp_buf_; // space for compressed data
00047   unsigned int curr_event_size_;
00048   unsigned int curr_space_used_; // less than curr_event_size_ if compressed
00049   TBufferFile rootbuf_;
00050   unsigned char* ptr_; // set to the place where the last event stored
00051   SBuffer header_buf_; // place for INIT message creation
00052   SBuffer bufs_;       // place for EVENT message creation
00053   uint32_t  adler32_chksum_; // adler32 check sum for the (compressed) data
00054 };
00055 
00056 class EventMsgBuilder;
00057 class InitMsgBuilder;
00058 namespace edm
00059 {
00060   
00061   class EventPrincipal;
00062   class StreamSerializer
00063   {
00064 
00065   public:
00066 
00067     StreamSerializer(Selections const* selections);
00068 
00069     int serializeRegistry(SerializeDataBuffer &data_buffer);   
00070     int serializeEvent(EventPrincipal const& eventPrincipal,
00071                        ParameterSetID const& selectorConfig,
00072                        bool use_compression, int compression_level,
00073                        SerializeDataBuffer &data_buffer);
00074 
00080     static unsigned int compressBuffer(unsigned char *inputBuffer,
00081                                        unsigned int inputSize,
00082                                        std::vector<unsigned char> &outputBuffer,
00083                                        int compressionLevel);
00084 
00085   private:
00086 
00087     // helps to keep the data in this class exception safe
00088     struct Arr
00089     {
00090       explicit Arr(int sz); // allocate
00091       ~Arr(); // free
00092 
00093       char* ptr_;
00094     };
00095 
00096     Selections const* selections_;
00097     // Arr data_;
00098     TClass* tc_;
00099   };
00100 
00101 }
00102 
00103 #endif