CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/EventFilter/StorageManager/src/DQMHttpSource.cc

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