Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:37

0001 //
0002 // Original Author:  Fedor Ratnikov
0003 //         Created:  Feb. 13, 2008
0004 //         (originally named JetCorrectionServiceChain, renamed in 2011)
0005 //
0006 //
0007 
0008 #include <string>
0009 #include <memory>
0010 #include <vector>
0011 #include <algorithm>
0012 
0013 #include "JetMETCorrections/Objects/interface/ChainedJetCorrector.h"
0014 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 #include "FWCore/Framework/interface/ESProducer.h"
0018 #include "FWCore/Framework/interface/ModuleFactory.h"
0019 
0020 class JetCorrectionESChain : public edm::ESProducer {
0021 public:
0022   JetCorrectionESChain(edm::ParameterSet const& fParameters);
0023   ~JetCorrectionESChain() override;
0024 
0025   std::unique_ptr<JetCorrector> produce(JetCorrectionsRecord const&);
0026 
0027 private:
0028   std::vector<edm::ESGetToken<JetCorrector, JetCorrectionsRecord>> tokens_;
0029 };
0030 
0031 JetCorrectionESChain::JetCorrectionESChain(edm::ParameterSet const& fParameters) {
0032   std::string label(fParameters.getParameter<std::string>("@module_label"));
0033   auto correctors = fParameters.getParameter<std::vector<std::string>>("correctors");
0034   if (std::find(correctors.begin(), correctors.end(), label) != correctors.end()) {
0035     throw cms::Exception("Recursion is not allowed")
0036         << "JetCorrectionESChain: corrector " << label << " is chained to itself";
0037   }
0038   auto cc = setWhatProduced(this, label);
0039   tokens_.resize(correctors.size());
0040   for (size_t i = 0; i < correctors.size(); ++i) {
0041     tokens_[i] = cc.consumes(edm::ESInputTag{"", correctors[i]});
0042   }
0043 }
0044 
0045 JetCorrectionESChain::~JetCorrectionESChain() {}
0046 
0047 std::unique_ptr<JetCorrector> JetCorrectionESChain::produce(JetCorrectionsRecord const& fRecord) {
0048   auto corrector = std::make_unique<ChainedJetCorrector>();
0049   for (const auto& token : tokens_) {
0050     corrector->push_back(&fRecord.get(token));
0051   }
0052   return corrector;
0053 }
0054 
0055 DEFINE_FWK_EVENTSETUP_MODULE(JetCorrectionESChain);