Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:01

0001 #ifndef FWCore_Framework_ConsumesCollector_h
0002 #define FWCore_Framework_ConsumesCollector_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     edm::ConsumesCollector
0007 //
0008 /**\class edm::ConsumesCollector ConsumesCollector.h "FWCore/Framework/interface/ConsumesCollector.h"
0009 
0010  Description: Helper class to gather consumes information for EDConsumerBase class.
0011 
0012  Usage:
0013     The constructor of a module can get an instance of edm::ConsumesCollector by calling its
0014 consumesCollector() method. This instance can then be passed to helper classes in order to register
0015 the data the helper will request from an Event, LuminosityBlock or Run on behalf of the module.
0016 
0017      WARNING: The ConsumesCollector should be used during the time that modules are being
0018 constructed. It should not be saved and used later. It will not work if it is used to call
0019 the consumes function during beginJob, beginRun, beginLuminosity block, event processing or
0020 at any later time. It can be used while the module constructor is running or be contained in
0021 a functor passed to the Framework with a call to callWhenNewProductsRegistered.
0022 
0023 */
0024 //
0025 // Original Author:  Chris Jones
0026 //         Created:  Fri, 07 Jun 2013 12:44:47 GMT
0027 //
0028 
0029 // system include files
0030 
0031 // user include files
0032 #include "FWCore/Framework/interface/EDConsumerBase.h"
0033 #include "FWCore/Utilities/interface/propagate_const.h"
0034 
0035 // forward declarations
0036 namespace edm {
0037   class EDConsumerBase;
0038   template <Transition TR>
0039   class ConsumesCollectorESAdaptor;
0040   template <Transition TR>
0041   class ConsumesCollectorWithTagESAdaptor;
0042   template <BranchType B>
0043   class ConsumesCollectorAdaptor;
0044 
0045   class ConsumesCollector {
0046   public:
0047     ConsumesCollector() = delete;
0048     ConsumesCollector(ConsumesCollector const&);
0049     ConsumesCollector(ConsumesCollector&&) = default;
0050     ConsumesCollector& operator=(ConsumesCollector const&);
0051     ConsumesCollector& operator=(ConsumesCollector&&) = default;
0052 
0053     // ---------- member functions ---------------------------
0054     template <typename ProductType, BranchType B = InEvent>
0055     EDGetTokenT<ProductType> consumes(edm::InputTag const& tag) {
0056       return m_consumer->consumes<ProductType, B>(tag);
0057     }
0058 
0059     template <BranchType B = InEvent>
0060     [[nodiscard]] ConsumesCollectorAdaptor<B> consumes(edm::InputTag tag) {
0061       return ConsumesCollectorAdaptor<B>(*this, std::move(tag));
0062     }
0063 
0064     EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) { return m_consumer->consumes(id, tag); }
0065 
0066     template <BranchType B>
0067     EDGetToken consumes(TypeToGet const& id, edm::InputTag const& tag) {
0068       return m_consumer->consumes<B>(id, tag);
0069     }
0070 
0071     template <typename ProductType, BranchType B = InEvent>
0072     EDGetTokenT<ProductType> mayConsume(edm::InputTag const& tag) {
0073       return m_consumer->mayConsume<ProductType, B>(tag);
0074     }
0075 
0076     EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) { return m_consumer->mayConsume(id, tag); }
0077 
0078     template <BranchType B>
0079     EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
0080       return m_consumer->mayConsume<B>(id, tag);
0081     }
0082 
0083     // For consuming event-setup products
0084     template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
0085     auto esConsumes() {
0086       return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
0087     }
0088 
0089     template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
0090     auto esConsumes(ESInputTag const& tag) {
0091       return m_consumer->esConsumes<ESProduct, ESRecord, Tr>(tag);
0092     }
0093 
0094     template <typename ESProduct, Transition Tr = Transition::Event>
0095     auto esConsumes(eventsetup::EventSetupRecordKey const& key, ESInputTag const& tag) {
0096       return m_consumer->esConsumes<ESProduct, Tr>(key, tag);
0097     }
0098 
0099     template <Transition Tr = Transition::Event>
0100     [[nodiscard]] constexpr auto esConsumes() noexcept {
0101       return ConsumesCollectorESAdaptor<Tr>(*this);
0102     }
0103 
0104     template <Transition Tr = Transition::Event>
0105     [[nodiscard]] auto esConsumes(ESInputTag tag) noexcept {
0106       return ConsumesCollectorWithTagESAdaptor<Tr>(*this, std::move(tag));
0107     }
0108 
0109   private:
0110     //only EDConsumerBase is allowed to make an instance of this class
0111     friend class EDConsumerBase;
0112 
0113     ConsumesCollector(EDConsumerBase* iConsumer) : m_consumer(iConsumer) {}
0114 
0115     // ---------- member data --------------------------------
0116     edm::propagate_const<EDConsumerBase*> m_consumer;
0117   };
0118 
0119   template <Transition TR>
0120   class ConsumesCollectorESAdaptor {
0121   public:
0122     template <typename TYPE, typename REC>
0123     ESGetToken<TYPE, REC> consumes() {
0124       return m_consumer.template esConsumes<TYPE, REC, TR>();
0125     }
0126 
0127   private:
0128     //only ConsumesCollector is allowed to make an instance of this class
0129     friend class ConsumesCollector;
0130 
0131     explicit ConsumesCollectorESAdaptor(ConsumesCollector iBase) : m_consumer(std::move(iBase)) {}
0132 
0133     ConsumesCollector m_consumer;
0134   };
0135 
0136   template <Transition TR>
0137   class ConsumesCollectorWithTagESAdaptor {
0138   public:
0139     template <typename TYPE, typename REC>
0140     ESGetToken<TYPE, REC> consumes() {
0141       return m_consumer.template esConsumes<TYPE, REC, TR>(m_tag);
0142     }
0143 
0144   private:
0145     //only ConsumesCollector is allowed to make an instance of this class
0146     friend class ConsumesCollector;
0147 
0148     ConsumesCollectorWithTagESAdaptor(ConsumesCollector iBase, ESInputTag iTag)
0149         : m_consumer(std::move(iBase)), m_tag(std::move(iTag)) {}
0150 
0151     ConsumesCollector m_consumer;
0152     ESInputTag const m_tag;
0153   };
0154 
0155   template <BranchType B>
0156   class ConsumesCollectorAdaptor {
0157   public:
0158     template <typename TYPE>
0159     EDGetTokenT<TYPE> consumes() {
0160       return m_consumer.template consumes<TYPE, B>(m_tag);
0161     }
0162 
0163   private:
0164     //only ConsumesCollector is allowed to make an instance of this class
0165     friend class ConsumesCollector;
0166 
0167     ConsumesCollectorAdaptor(ConsumesCollector iBase, edm::InputTag iTag) : m_consumer(iBase), m_tag(std::move(iTag)) {}
0168 
0169     ConsumesCollector m_consumer;
0170     edm::InputTag const m_tag;
0171   };
0172 
0173 }  // namespace edm
0174 
0175 #endif