CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondTools/DQM/plugins/DQMReferenceHistogramRootFileEventSetupAnalyzer.cc

Go to the documentation of this file.
00001 // C++ common header
00002 #include <iostream>
00003 #include <vector>
00004 #include <fstream>
00005 
00006 // Boost headers
00007 #include "boost/scoped_ptr.hpp"
00008 
00009 #include "FWCore/Framework/interface/EDAnalyzer.h"
00010 #include "FWCore/Framework/interface/Run.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Utilities/interface/Exception.h"
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018 #include "CondFormats/Common/interface/FileBlob.h"
00019 #include "CondFormats/DataRecord/interface/DQMReferenceHistogramRootFileRcd.h"
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021 #include "DQMServices/Core/interface/MonitorElement.h"
00022 
00023 namespace edmtest {
00024   class DQMReferenceHistogramRootFileEventSetupAnalyzer: public edm::EDAnalyzer {
00025    public:
00026     explicit DQMReferenceHistogramRootFileEventSetupAnalyzer(const edm::ParameterSet & pset);
00027     explicit DQMReferenceHistogramRootFileEventSetupAnalyzer(int i);
00028     virtual ~DQMReferenceHistogramRootFileEventSetupAnalyzer();
00029     virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00030     virtual void beginRun(edm::Run const&, edm::EventSetup const&) ;
00031   private:
00032     bool init_ ;
00033   };
00034   
00035   DQMReferenceHistogramRootFileEventSetupAnalyzer::DQMReferenceHistogramRootFileEventSetupAnalyzer(const edm::ParameterSet &ps) {
00036     init_ = false ;
00037     //std::cout << "DQMReferenceHistogramRootFileEventSetupAnalyzer(const edm::ParameterSet &ps)" << std::endl;
00038   }
00039   
00040   DQMReferenceHistogramRootFileEventSetupAnalyzer::DQMReferenceHistogramRootFileEventSetupAnalyzer(int i) {
00041     init_ = false ;
00042     //std::cout << "DQMReferenceHistogramRootFileEventSetupAnalyzer(int i) " << i << std::endl;
00043   }
00044   
00045   DQMReferenceHistogramRootFileEventSetupAnalyzer::~DQMReferenceHistogramRootFileEventSetupAnalyzer()
00046   {
00047     init_ = false ;
00048     //std::cout << "~DQMReferenceHistogramRootFileEventSetupAnalyzer" << std::endl;
00049   }
00050   
00051   void DQMReferenceHistogramRootFileEventSetupAnalyzer::analyze( const edm::Event& iEvent, const edm::EventSetup& iSetup)
00052   {
00053     return ;
00054   }
00055 
00056   void DQMReferenceHistogramRootFileEventSetupAnalyzer::beginRun(edm::Run const& run , edm::EventSetup const& iSetup)
00057   {
00058     //std::cout << "DQMReferenceHistogramRootFileEventSetupAnalyzer::beginRun()" << std::endl;    
00059     if(!init_)
00060       {
00061         init_ = true ;
00062         edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("DQMReferenceHistogramRootFileRcd"));
00063         if(recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
00064           throw cms::Exception ("Record not found") << "Record \"DQMReferenceHistogramRootFileRcd" 
00065                                                     << "\" does not exist!" << std::endl;
00066         }
00067         edm::ESHandle<FileBlob> rootgeo;
00068         iSetup.get<DQMReferenceHistogramRootFileRcd>().get(rootgeo);
00069         //std::cout<<"ROOT FILE IN MEMORY"<<std::endl;
00070         boost::scoped_ptr<std::vector<unsigned char> > tb( (*rootgeo).getUncompressedBlob() );
00071         // char filename[128];
00072         // sprintf(filename, "mem:%p,%ul", &(*tb)[0], (unsigned long) tb->size());
00073         // edm::Service<DQMStore>()->open(filename, false, "", "Reference");
00074         
00075         //here you can implement the stream for putting the TFile on disk...
00076         std::string outfile("dqmreference.root") ;
00077         ofstream output(outfile.c_str()) ;
00078         output.write((const char *)&(*tb)[0], tb->size());
00079         output.close() ;
00080         
00081         DQMStore *dqm = &*edm::Service<DQMStore>();
00082         dqm->open(outfile, false, "", "Reference");
00083         remove(outfile.c_str());
00084         
00085         std::vector<MonitorElement *> mes = dqm->getAllContents("");
00086         // for (std::vector<MonitorElement *>::iterator i = mes.begin(), e = mes.end(); i != e; ++i)
00087         //  std::cout << "ME '" << (*i)->getFullname() << "'\n";
00088         
00089         //std::cout<<"SIZE FILE = "<<tb->size()<<std::endl;
00090       }
00091   }
00092   
00093   DEFINE_FWK_MODULE(DQMReferenceHistogramRootFileEventSetupAnalyzer);
00094 }