Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:44

0001 // C++ common header
0002 #include <iostream>
0003 #include <memory>
0004 #include <vector>
0005 #include <fstream>
0006 
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Run.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "CondFormats/Common/interface/FileBlob.h"
0016 #include "CondFormats/DataRecord/interface/DQMXMLFileRcd.h"
0017 #include "DQMServices/Core/interface/DQMStore.h"
0018 
0019 namespace edmtest {
0020   class DQMXMLFileEventSetupAnalyzer : public edm::one::EDAnalyzer<> {
0021   public:
0022     explicit DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet& pset);
0023     explicit DQMXMLFileEventSetupAnalyzer(int i);
0024     ~DQMXMLFileEventSetupAnalyzer() override;
0025     void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
0026     void beginRun(edm::Run const&, edm::EventSetup const&);
0027 
0028   private:
0029     const edm::ESGetToken<FileBlob, DQMXMLFileRcd> fileBlobToken_;
0030     bool init_;
0031     std::string labelToGet_;
0032   };
0033 
0034   DQMXMLFileEventSetupAnalyzer::DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet& ps)
0035       : fileBlobToken_(
0036             esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ps.getParameter<std::string>("labelToGet")))),
0037         labelToGet_(ps.getParameter<std::string>("labelToGet")) {
0038     init_ = false;
0039     edm::LogPrint("DQMXMLFileEventSetupAnalyzer")
0040         << "DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet &ps)" << std::endl;
0041   }
0042 
0043   DQMXMLFileEventSetupAnalyzer::DQMXMLFileEventSetupAnalyzer(int i) {
0044     init_ = false;
0045     edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer(int i) " << i << std::endl;
0046   }
0047 
0048   DQMXMLFileEventSetupAnalyzer::~DQMXMLFileEventSetupAnalyzer() {
0049     init_ = false;
0050     edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "~DQMXMLFileEventSetupAnalyzer" << std::endl;
0051   }
0052 
0053   void DQMXMLFileEventSetupAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { return; }
0054 
0055   void DQMXMLFileEventSetupAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
0056     edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer::beginRun()" << std::endl;
0057     if (!init_) {
0058       init_ = true;
0059       edm::eventsetup::EventSetupRecordKey recordKey(
0060           edm::eventsetup::EventSetupRecordKey::TypeTag::findType("DQMXMLFileRcd"));
0061       if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0062         throw cms::Exception("Record not found") << "Record \"DQMXMLFileRcd"
0063                                                  << "\" does not exist!" << std::endl;
0064       }
0065 
0066       const auto& rootgeo = &iSetup.getData(fileBlobToken_);
0067       edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "XML FILE IN MEMORY 1 with label " << labelToGet_ << std::endl;
0068       std::unique_ptr<std::vector<unsigned char> > tb1((*rootgeo).getUncompressedBlob());
0069       //here you can implement the stream for putting the TFile on disk...
0070       std::string outfile1("XML1_retrieved.xml");
0071       std::ofstream output1(outfile1.c_str());
0072       output1.write((const char*)&(*tb1)[0], tb1->size());
0073       output1.close();
0074 
0075       //    iSetup.get<DQMXMLFileRcd>().get("XML2_mio",rootgeo);
0076       //    std::cout<<"ROOT FILE IN MEMORY 2"<<std::endl;
0077       //    std::unique_ptr<std::vector<unsigned char> > tb2( (*rootgeo).getUncompressedBlob() );
0078       //    //here you can implement the stream for putting the TFile on disk...
0079       //    std::string outfile2("XML2_retrieved.xml") ;
0080       //    std::ofstream output2(outfile2.c_str()) ;
0081       //    output2.write((const char *)&(*tb2)[0], tb2->size());
0082       //    output2.close() ;
0083       //    std::unique_ptr<std::vector<unsigned char> > tb( (*rootgeo).getUncompressedBlob() );
0084     }
0085   }
0086 
0087   DEFINE_FWK_MODULE(DQMXMLFileEventSetupAnalyzer);
0088 }  // namespace edmtest