diff --git a/RecoEgamma/EgammaElectronProducers/test/GEDValueMapAnalyzer.cc b/RecoEgamma/EgammaElectronProducers/test/GEDValueMapAnalyzer.cc index d925f87cd31a9..4526215be0c1e 100644 --- a/RecoEgamma/EgammaElectronProducers/test/GEDValueMapAnalyzer.cc +++ b/RecoEgamma/EgammaElectronProducers/test/GEDValueMapAnalyzer.cc @@ -1,5 +1,6 @@ #include "FWCore/Framework/interface/Event.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/MakerMacros.h" @@ -13,22 +14,26 @@ class GEDValueMapAnalyzer : public edm::one::EDAnalyzer<> { public: GEDValueMapAnalyzer(const edm::ParameterSet&); + ~GEDValueMapAnalyzer() override = default; + void analyze(const edm::Event& iEvent, const edm::EventSetup& c) override; private: - edm::InputTag inputTagValueMapElectrons_; - edm::InputTag inputTagPFCandidates_; + const edm::InputTag inputTagPFCandidates_; + const edm::InputTag inputTagValueMapElectrons_; + const edm::EDGetTokenT pfCandToken_; + const edm::EDGetTokenT > electronToken_; }; -GEDValueMapAnalyzer::GEDValueMapAnalyzer(const edm::ParameterSet& iConfig) { - inputTagPFCandidates_ = iConfig.getParameter("PFCandidates"); - inputTagValueMapElectrons_ = iConfig.getParameter("ElectronValueMap"); -} +GEDValueMapAnalyzer::GEDValueMapAnalyzer(const edm::ParameterSet& iConfig) + : inputTagPFCandidates_(iConfig.getParameter("PFCandidates")), + inputTagValueMapElectrons_(iConfig.getParameter("ElectronValueMap")), + pfCandToken_(consumes(inputTagPFCandidates_)), + electronToken_(consumes >(inputTagValueMapElectrons_)) {} void GEDValueMapAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& c) { - edm::Handle pfCandidatesH; - bool found = iEvent.getByLabel(inputTagPFCandidates_, pfCandidatesH); - if (!found) { + const edm::Handle& pfCandidatesH = iEvent.getHandle(pfCandToken_); + if (!pfCandidatesH.isValid()) { std::ostringstream err; err << " cannot get PFCandidates: " << inputTagPFCandidates_ << std::endl; edm::LogError("PFIsoReader") << err.str(); @@ -37,11 +42,10 @@ void GEDValueMapAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetu // Get the value maps - edm::Handle > electronValMapH; - found = iEvent.getByLabel(inputTagValueMapElectrons_, electronValMapH); + const edm::Handle > electronValMapH = iEvent.getHandle(electronToken_); const edm::ValueMap& myElectronValMap(*electronValMapH); - std::cout << " Read Electron Value Map " << myElectronValMap.size() << std::endl; + edm::LogVerbatim("GEDValueMapAnalyer") << " Read Electron Value Map " << myElectronValMap.size(); unsigned ncandidates = pfCandidatesH->size(); for (unsigned ic = 0; ic < ncandidates; ++ic) { @@ -55,11 +59,13 @@ void GEDValueMapAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetu reco::GsfElectronRef gsfRef = myElectronValMap[pfRef]; //basic check - std::cout << " Comparing GsfTrackRef from GsfElectron and PFCandidate "; + std::ostringstream st1; + st1 << " Comparing GsfTrackRef from GsfElectron and PFCandidate "; if (gsfRef->gsfTrack() == cand.gsfTrackRef()) - std::cout << " OK " << std::endl; + st1 << " OK "; else - std::cout << " Problem different Ref" << std::endl; + st1 << " Problem different Ref"; + edm::LogVerbatim("GEDValueMapAnalyer") << st1.str(); } }