CMS 3D CMS Logo

StreamSerializer.h

Go to the documentation of this file.
00001 #ifndef IOPool_Streamer_StreamSerializer_h
00002 #define IOPool_Streamer_StreamSerializer_h
00003 
00011 #include "RVersion.h"
00012 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
00013 #include "TBufferFile.h"
00014 typedef TBufferFile RootBuffer;
00015 #else
00016 #include "TBuffer.h"
00017 typedef TBuffer RootBuffer;
00018 #endif
00019 
00020 const int init_size = 1024*1024;
00021 
00022 // Data structure to be shared by all output modules for event serialization
00023 struct SerializeDataBuffer
00024 {
00025   typedef std::vector<char> SBuffer;
00026 
00027   SerializeDataBuffer():
00028     comp_buf_(init_size),
00029     curr_event_size_(),
00030     curr_space_used_(),
00031     rootbuf_(TBuffer::kWrite,init_size),
00032     ptr_((unsigned char*)rootbuf_.Buffer()),
00033     header_buf_(),
00034     bufs_()
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 
00045   std::vector<unsigned char> comp_buf_; // space for compressed data
00046   unsigned int curr_event_size_;
00047   unsigned int curr_space_used_; // less than curr_event_size_ if compressed
00048   RootBuffer rootbuf_;
00049   unsigned char* ptr_; // set to the place where the last event stored
00050   SBuffer header_buf_; // place for INIT message creation
00051   SBuffer bufs_;       // place for EVENT message creation
00052 };
00053 
00054 #include "DataFormats/Provenance/interface/Selections.h"
00055 #include <vector>
00056 
00057 class EventMsgBuilder;
00058 class InitMsgBuilder;
00059 namespace edm
00060 {
00061   
00062   class EventPrincipal;
00063   class StreamSerializer
00064   {
00065 
00066   public:
00067 
00068     StreamSerializer(Selections const* selections);
00069 
00070     int serializeRegistry(SerializeDataBuffer &data_buffer);   
00071     int serializeEvent(EventPrincipal const& eventPrincipal,
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

Generated on Tue Jun 9 17:39:18 2009 for CMSSW by  doxygen 1.5.4