CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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   StreamDQMSerializer::Arr::Arr(int sz):ptr_((char*)malloc(sz)) { }
00019   StreamDQMSerializer::Arr::~Arr() { free(ptr_); }
00020 
00021   const int init_size = 1024*1024;
00022 
00026   StreamDQMSerializer::StreamDQMSerializer():
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     adler32_chksum_(0)
00033   { }
00034 
00038   int StreamDQMSerializer::serializeDQMEvent(DQMEvent::TObjectTable& toTable,
00039                                              bool use_compression,
00040                                              int compression_level)
00041   {
00042     // initialize the internal TBuffer
00043     rootbuf_.Reset();
00044     RootDebug tracer(10,10);
00045 
00046     // loop over each subfolder
00047     DQMEvent::TObjectTable::const_iterator sfIter;
00048     for (sfIter = toTable.begin(); sfIter != toTable.end(); sfIter++)
00049       {
00050         std::string folderName = sfIter->first;
00051         std::vector<TObject *> toList = sfIter->second;
00052 
00053         // serialize the ME data
00054         uint32 meCount = toList.size();
00055         for (int idx = 0; idx < (int) meCount; idx++) {
00056           TObject *toPtr = toList[idx];
00057           rootbuf_.WriteObject(toPtr);
00058         }
00059       }
00060 
00061     // set sizes and pointer(s) appropriately
00062     curr_event_size_ = rootbuf_.Length();
00063     curr_space_used_ = curr_event_size_;
00064     ptr_ = (unsigned char*) rootbuf_.Buffer();
00065 
00066     // compress the data, if needed
00067     if (use_compression)
00068       {
00069         unsigned int dest_size =
00070           StreamSerializer::compressBuffer(ptr_, curr_event_size_,
00071                                            comp_buf_, compression_level);
00072         // compression succeeded
00073         if (dest_size != 0)
00074           {
00075             ptr_ = &comp_buf_[0]; // reset to point at compressed area
00076             curr_space_used_ = dest_size;
00077           }
00078       }
00079     // calculate the adler32 checksum 
00080     adler32_chksum_ = cms::Adler32((char*)ptr_, curr_space_used_);
00081 
00082 
00083     return curr_space_used_;
00084   }
00085 }