CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/IOPool/Streamer/src/StreamDQMSerializer.cc

Go to the documentation of this file.
00001 
00008 #include "IOPool/Streamer/interface/ClassFiller.h"
00009 #include "IOPool/Streamer/interface/StreamDQMSerializer.h"
00010 #include "IOPool/Streamer/interface/StreamSerializer.h"
00011 #include "FWCore/Utilities/interface/Adler32Calculator.h"
00012 
00013 #include <cstdlib>
00014 
00015 namespace edm
00016 {
00017 
00018   const int init_size = 1024*1024;
00019 
00023   StreamDQMSerializer::StreamDQMSerializer():
00024     comp_buf_(init_size),
00025     curr_event_size_(),
00026     curr_space_used_(),
00027     rootbuf_(TBuffer::kWrite,init_size),
00028     ptr_((unsigned char*)rootbuf_.Buffer()),
00029     adler32_chksum_(0)
00030   { }
00031 
00035   int StreamDQMSerializer::serializeDQMEvent(DQMEvent::TObjectTable& toTable,
00036                                              bool use_compression,
00037                                              int compression_level)
00038   {
00039     // initialize the internal TBuffer
00040     rootbuf_.Reset();
00041     RootDebug tracer(10,10);
00042 
00043     // loop over each subfolder
00044     DQMEvent::TObjectTable::const_iterator sfIter;
00045     for (sfIter = toTable.begin(); sfIter != toTable.end(); sfIter++)
00046       {
00047         std::string folderName = sfIter->first;
00048         std::vector<TObject *> toList = sfIter->second;
00049 
00050         // serialize the ME data
00051         uint32 meCount = toList.size();
00052         for (int idx = 0; idx < (int) meCount; idx++) {
00053           TObject *toPtr = toList[idx];
00054           rootbuf_.WriteObject(toPtr);
00055         }
00056       }
00057 
00058     // set sizes and pointer(s) appropriately
00059     curr_event_size_ = rootbuf_.Length();
00060     curr_space_used_ = curr_event_size_;
00061     ptr_ = (unsigned char*) rootbuf_.Buffer();
00062 
00063     // compress the data, if needed
00064     if (use_compression)
00065       {
00066         unsigned int dest_size =
00067           StreamSerializer::compressBuffer(ptr_, curr_event_size_,
00068                                            comp_buf_, compression_level);
00069         // compression succeeded
00070         if (dest_size != 0)
00071           {
00072             ptr_ = &comp_buf_[0]; // reset to point at compressed area
00073             curr_space_used_ = dest_size;
00074           }
00075       }
00076     // calculate the adler32 checksum 
00077     adler32_chksum_ = cms::Adler32((char*)ptr_, curr_space_used_);
00078 
00079 
00080     return curr_space_used_;
00081   }
00082 }