Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:37

0001 #ifndef RecoBTau_JetTagComputerESProducer_h
0002 #define RecoBTau_JetTagComputerESProducer_h
0003 
0004 #include <string>
0005 #include <memory>
0006 #include <type_traits>
0007 
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "RecoBTau/JetTagComputer/interface/JetTagComputerRecord.h"
0011 #include "RecoBTau/JetTagComputer/interface/JetTagComputer.h"
0012 
0013 /**
0014  * The idea here is to provide two implementations for
0015  * JetTagConmputerESProducer: one for those ConcreteJetTagComputers
0016  * that consume ES products and thus need the ESGetTokens, and one for
0017  * those that do not. All ConcreteJetTagComputers are required to have
0018  * a nested type called 'Tokens'.
0019  *
0020  * Those that need the ESGetTokens should define the nested type as a
0021  * struct/class containing the ESGetTokens and a constructor taking
0022  * edm::ParameterSet and edm::ESConsumesCollector as arguments. In
0023  * this case the constructor of ConcreteJetTagComputer takes this
0024  * 'Tokens' object as an additional argument.
0025  *
0026  * Those that do not need ESGetTokens should define the nested type as
0027  * void, and in this case no further modifications are needed.
0028  */
0029 namespace jet_tag_computer_esproducer_impl {
0030   template <typename ConcreteJetTagComputer, bool>
0031   class JetTagComputerESProducer : public edm::ESProducer {
0032   private:
0033     // check that the template parameter inherits from JetTagComputer
0034     static_assert(std::is_convertible_v<ConcreteJetTagComputer*, JetTagComputer*>);
0035 
0036   public:
0037     using Tokens = typename ConcreteJetTagComputer::Tokens;
0038 
0039     JetTagComputerESProducer(const edm::ParameterSet& pset)
0040         : m_tokens(pset, setWhatProduced(this, pset.getParameter<std::string>("@module_label"))), m_pset(pset) {}
0041 
0042     std::unique_ptr<JetTagComputer> produce(const JetTagComputerRecord& record) {
0043       std::unique_ptr<JetTagComputer> jetTagComputer = std::make_unique<ConcreteJetTagComputer>(m_pset, m_tokens);
0044       jetTagComputer->initialize(record);
0045       jetTagComputer->setupDone();
0046       return jetTagComputer;
0047     }
0048 
0049   private:
0050     const Tokens m_tokens;
0051     const edm::ParameterSet m_pset;
0052   };
0053 
0054   template <typename ConcreteJetTagComputer>
0055   class JetTagComputerESProducer<ConcreteJetTagComputer, true> : public edm::ESProducer {
0056   private:
0057     // check that the template parameter inherits from JetTagComputer
0058     static_assert(std::is_convertible_v<ConcreteJetTagComputer*, JetTagComputer*>);
0059 
0060   public:
0061     JetTagComputerESProducer(const edm::ParameterSet& pset) : m_pset(pset) {
0062       setWhatProduced(this, pset.getParameter<std::string>("@module_label"));
0063     }
0064 
0065     std::unique_ptr<JetTagComputer> produce(const JetTagComputerRecord& record) {
0066       std::unique_ptr<JetTagComputer> jetTagComputer = std::make_unique<ConcreteJetTagComputer>(m_pset);
0067       jetTagComputer->initialize(record);
0068       jetTagComputer->setupDone();
0069       return jetTagComputer;
0070     }
0071 
0072   private:
0073     const edm::ParameterSet m_pset;
0074   };
0075 }  // namespace jet_tag_computer_esproducer_impl
0076 
0077 template <typename T>
0078 using JetTagComputerESProducer =
0079     jet_tag_computer_esproducer_impl::JetTagComputerESProducer<T, std::is_same_v<typename T::Tokens, void>>;
0080 
0081 #endif  // RecoBTau_JetTagComputerESProducer_h