From 15d40b4e548868c6d0916a0ed2203243b22cc6ce Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Wed, 16 Sep 2015 22:24:17 +0200 Subject: [PATCH 1/2] CorrectedJetProducer: change into a global::EDProducer change all specialisations of `CorrectedJetProducer` into `global::EDProducer` modules: - `CorrectedCaloJetProducer` - `CorrectedPFJetProducer` - `CorrectedJPTJetProducer` - `CorrectedTrackJetProducer` - `CorrectedGenJetProducer` --- .../Modules/interface/CorrectedJetProducer.h | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/JetMETCorrections/Modules/interface/CorrectedJetProducer.h b/JetMETCorrections/Modules/interface/CorrectedJetProducer.h index a74425f9505bd..116668f55bdb5 100644 --- a/JetMETCorrections/Modules/interface/CorrectedJetProducer.h +++ b/JetMETCorrections/Modules/interface/CorrectedJetProducer.h @@ -9,7 +9,7 @@ #include "DataFormats/Common/interface/Handle.h" #include "DataFormats/Common/interface/Ref.h" #include "DataFormats/Common/interface/RefToBase.h" -#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/global/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Utilities/interface/InputTag.h" @@ -25,19 +25,17 @@ namespace edm namespace reco { template - class CorrectedJetProducer : public edm::EDProducer + class CorrectedJetProducer : public edm::global::EDProducer<> { public: typedef std::vector JetCollection; explicit CorrectedJetProducer (const edm::ParameterSet& fParameters); virtual ~CorrectedJetProducer () {} - virtual void produce(edm::Event&, const edm::EventSetup&); + virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; private: - edm::EDGetTokenT mInput; - std::vector > mCorrectorTokens; - // cache - std::vector mCorrectors; - bool mVerbose; + const edm::EDGetTokenT mInput; + const std::vector > mCorrectorTokens; + const bool mVerbose; }; } @@ -49,7 +47,6 @@ namespace reco { CorrectedJetProducer::CorrectedJetProducer(const edm::ParameterSet& fConfig) : mInput(consumes(fConfig.getParameter ("src"))) , mCorrectorTokens(edm::vector_transform(fConfig.getParameter >("correctors"), [this](edm::InputTag const & tag){return consumes(tag);})) - , mCorrectors(mCorrectorTokens.size(), 0) , mVerbose (fConfig.getUntrackedParameter ("verbose", false)) { std::string alias = fConfig.getUntrackedParameter ("alias", ""); @@ -60,15 +57,17 @@ namespace reco { } template - void CorrectedJetProducer::produce(edm::Event& fEvent, - const edm::EventSetup& fSetup) + void CorrectedJetProducer::produce(edm::StreamID, edm::Event& fEvent, const edm::EventSetup& fSetup) const { + // cache - note that variable length arrays are a GCC extension + reco::JetCorrector const * correctors[mCorrectorTokens.size()]; + // look for correctors for (unsigned i = 0; i < mCorrectorTokens.size(); i++) { edm::Handle handle; fEvent.getByToken (mCorrectorTokens [i], handle); - mCorrectors [i] = &*handle; + correctors[i] = handle.product(); } edm::Handle jets; //Define Inputs fEvent.getByToken (mInput, jets); //Get Inputs @@ -83,15 +82,15 @@ namespace reco { if (mVerbose) std::cout<<"CorrectedJetProducer::produce-> original jet: " <print()<vectorialCorrection()) ) { + if ( !(correctors[i]->vectorialCorrection()) ) { // Scalar correction double scale = 1.; - if (!(mCorrectors[i]->refRequired())) - scale = mCorrectors[i]->correction (*referenceJet); + if (!(correctors[i]->refRequired())) + scale = correctors[i]->correction (*referenceJet); else - scale = mCorrectors[i]->correction (*referenceJet,jetRef); + scale = correctors[i]->correction (*referenceJet,jetRef); if (mVerbose) std::cout<<"CorrectedJetProducer::produce-> Corrector # " <correction (*referenceJet, jetRef, corrected); + double scale = correctors[i]->correction (*referenceJet, jetRef, corrected); if (mVerbose) std::cout<<"CorrectedJetProducer::produce-> Corrector # " < Date: Fri, 18 Sep 2015 12:58:00 +0200 Subject: [PATCH 2/2] replace GNU/C99 VLA with std::vector --- JetMETCorrections/Modules/interface/CorrectedJetProducer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JetMETCorrections/Modules/interface/CorrectedJetProducer.h b/JetMETCorrections/Modules/interface/CorrectedJetProducer.h index 116668f55bdb5..6be95e6dc1fd4 100644 --- a/JetMETCorrections/Modules/interface/CorrectedJetProducer.h +++ b/JetMETCorrections/Modules/interface/CorrectedJetProducer.h @@ -59,8 +59,8 @@ namespace reco { template void CorrectedJetProducer::produce(edm::StreamID, edm::Event& fEvent, const edm::EventSetup& fSetup) const { - // cache - note that variable length arrays are a GCC extension - reco::JetCorrector const * correctors[mCorrectorTokens.size()]; + // FIXME - use something more efficient instead of an std::vector + std::vector correctors(mCorrectorTokens.size(), nullptr); // look for correctors for (unsigned i = 0; i < mCorrectorTokens.size(); i++)