DQMXMLFileEventSetupAnalyzer

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// C++ common header
#include <iostream>
#include <memory>
#include <vector>
#include <fstream>

#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondFormats/Common/interface/FileBlob.h"
#include "CondFormats/DataRecord/interface/DQMXMLFileRcd.h"
#include "DQMServices/Core/interface/DQMStore.h"

namespace edmtest {
  class DQMXMLFileEventSetupAnalyzer : public edm::one::EDAnalyzer<> {
  public:
    explicit DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet& pset);
    explicit DQMXMLFileEventSetupAnalyzer(int i);
    ~DQMXMLFileEventSetupAnalyzer() override;
    void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
    void beginRun(edm::Run const&, edm::EventSetup const&);

  private:
    const edm::ESGetToken<FileBlob, DQMXMLFileRcd> fileBlobToken_;
    bool init_;
    std::string labelToGet_;
  };

  DQMXMLFileEventSetupAnalyzer::DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet& ps)
      : fileBlobToken_(
            esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", ps.getParameter<std::string>("labelToGet")))),
        labelToGet_(ps.getParameter<std::string>("labelToGet")) {
    init_ = false;
    edm::LogPrint("DQMXMLFileEventSetupAnalyzer")
        << "DQMXMLFileEventSetupAnalyzer(const edm::ParameterSet &ps)" << std::endl;
  }

  DQMXMLFileEventSetupAnalyzer::DQMXMLFileEventSetupAnalyzer(int i) {
    init_ = false;
    edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer(int i) " << i << std::endl;
  }

  DQMXMLFileEventSetupAnalyzer::~DQMXMLFileEventSetupAnalyzer() {
    init_ = false;
    edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "~DQMXMLFileEventSetupAnalyzer" << std::endl;
  }

  void DQMXMLFileEventSetupAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { return; }

  void DQMXMLFileEventSetupAnalyzer::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
    edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "DQMXMLFileEventSetupAnalyzer::beginRun()" << std::endl;
    if (!init_) {
      init_ = true;
      edm::eventsetup::EventSetupRecordKey recordKey(
          edm::eventsetup::EventSetupRecordKey::TypeTag::findType("DQMXMLFileRcd"));
      if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
        throw cms::Exception("Record not found") << "Record \"DQMXMLFileRcd"
                                                 << "\" does not exist!" << std::endl;
      }

      const auto& rootgeo = &iSetup.getData(fileBlobToken_);
      edm::LogPrint("DQMXMLFileEventSetupAnalyzer") << "XML FILE IN MEMORY 1 with label " << labelToGet_ << std::endl;
      std::unique_ptr<std::vector<unsigned char> > tb1((*rootgeo).getUncompressedBlob());
      //here you can implement the stream for putting the TFile on disk...
      std::string outfile1("XML1_retrieved.xml");
      std::ofstream output1(outfile1.c_str());
      output1.write((const char*)&(*tb1)[0], tb1->size());
      output1.close();

      // 	iSetup.get<DQMXMLFileRcd>().get("XML2_mio",rootgeo);
      // 	std::cout<<"ROOT FILE IN MEMORY 2"<<std::endl;
      // 	std::unique_ptr<std::vector<unsigned char> > tb2( (*rootgeo).getUncompressedBlob() );
      // 	//here you can implement the stream for putting the TFile on disk...
      // 	std::string outfile2("XML2_retrieved.xml") ;
      // 	std::ofstream output2(outfile2.c_str()) ;
      // 	output2.write((const char *)&(*tb2)[0], tb2->size());
      // 	output2.close() ;
      //	std::unique_ptr<std::vector<unsigned char> > tb( (*rootgeo).getUncompressedBlob() );
    }
  }

  DEFINE_FWK_MODULE(DQMXMLFileEventSetupAnalyzer);
}  // namespace edmtest