CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/EventFilter/StorageManager/src/DQMHttpSource.cc

Go to the documentation of this file.
00001 // $Id: DQMHttpSource.cc,v 1.22.4.2 2011/03/29 15:59:29 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/interface/CurlInterface.h"
00005 #include "EventFilter/StorageManager/src/DQMHttpSource.h"
00006 #include "EventFilter/StorageManager/src/EventServerProxy.icc"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "IOPool/Streamer/interface/StreamDQMDeserializer.h"
00010 
00011 #include "TClass.h"
00012 
00013 #include <string>
00014 #include <vector>
00015 
00016 
00017 namespace edm
00018 {
00019   boost::mutex DQMHttpSource::mutex_;
00020   
00021   
00022   DQMHttpSource::DQMHttpSource
00023   (
00024     const ParameterSet& pset,
00025     const InputSourceDescription& desc
00026   ) :
00027   edm::RawInputSource(pset, desc),
00028   dqmStore_(0),
00029   dqmEventServerProxy_(pset)
00030   {}
00031 
00032 
00033   std::auto_ptr<Event> DQMHttpSource::readOneEvent()
00034   {
00035     initializeDQMStore();
00036     stor::CurlInterface::Content data;
00037 
00038     dqmEventServerProxy_.getOneEvent(data);
00039     if ( data.empty() ) return std::auto_ptr<edm::Event>();
00040 
00041     HeaderView hdrView(&data[0]);
00042     if (hdrView.code() == Header::DONE)
00043       return std::auto_ptr<edm::Event>();
00044 
00045     const DQMEventMsgView dqmEventMsgView(&data[0]);
00046     addEventToDQMBackend(dqmStore_, dqmEventMsgView, true);
00047 
00048     // make a fake event containing no data but the evId and runId from DQMEvent
00049     // and the time stamp from the event at update
00050     std::auto_ptr<Event> e = makeEvent(
00051       dqmEventMsgView.runNumber(),
00052       dqmEventMsgView.lumiSection(),
00053       dqmEventMsgView.eventNumberAtUpdate(),
00054       dqmEventMsgView.timeStamp()
00055     );
00056 
00057     return e;
00058   }
00059   
00060   
00061   void DQMHttpSource::addEventToDQMBackend
00062   (
00063     DQMStore* dqmStore,
00064     const DQMEventMsgView& dqmEventMsgView,
00065     const bool overwrite
00066   )
00067   {
00068     boost::mutex::scoped_lock sl(mutex_);
00069 
00070     edm::StreamDQMDeserializer deserializeWorker;
00071     std::auto_ptr<DQMEvent::TObjectTable> toTablePtr =
00072       deserializeWorker.deserializeDQMEvent(dqmEventMsgView);
00073     
00074     for (DQMEvent::TObjectTable::const_iterator tableIter = toTablePtr->begin(),
00075            tableIterEnd = toTablePtr->end(); tableIter != tableIterEnd; ++tableIter)
00076     {
00077       const std::string subFolderName = tableIter->first;
00078       std::vector<TObject*> toList = tableIter->second;
00079       dqmStore->setCurrentFolder(subFolderName); // creates dir if needed
00080 
00081       for (std::vector<TObject*>::const_iterator objectIter = toList.begin(),
00082              objectIterEnd = toList.end(); objectIter != objectIterEnd; ++objectIter)
00083       {
00084         dqmStore->extract(*objectIter, dqmStore->pwd(), overwrite);
00085         // TObject cloned into DQMStore. Thus, delete it here.
00086         delete *objectIter;
00087       }
00088     }
00089   }
00090   
00091 
00092   void DQMHttpSource::initializeDQMStore()
00093   {
00094     if ( ! dqmStore_ )
00095       dqmStore_ = edm::Service<DQMStore>().operator->();
00096     
00097     if ( ! dqmStore_ )
00098       throw cms::Exception("readOneEvent", "DQMHttpSource")
00099         << "Unable to lookup the DQMStore service!\n";
00100   }
00101 
00102 } // namespace edm
00103 
00104