Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:43

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     template <typename ProductType, BranchType B = InEvent>
0084     void consumesMany() {
0085       m_consumer->consumesMany<ProductType, B>();
0086     }
0087 
0088     void consumesMany(const TypeToGet& id) { m_consumer->consumesMany(id); }
0089 
0090     template <BranchType B>
0091     void consumesMany(const TypeToGet& id) {
0092       m_consumer->consumesMany<B>(id);
0093     }
0094 
0095     // For consuming event-setup products
0096     template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
0097     auto esConsumes() {
0098       return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
0099     }
0100 
0101     template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
0102     auto esConsumes(ESInputTag const& tag) {
0103       return m_consumer->esConsumes<ESProduct, ESRecord, Tr>(tag);
0104     }
0105 
0106     template <typename ESProduct, Transition Tr = Transition::Event>
0107     auto esConsumes(eventsetup::EventSetupRecordKey const& key, ESInputTag const& tag) {
0108       return m_consumer->esConsumes<ESProduct, Tr>(key, tag);
0109     }
0110 
0111     template <Transition Tr = Transition::Event>
0112     [[nodiscard]] constexpr auto esConsumes() noexcept {
0113       return ConsumesCollectorESAdaptor<Tr>(*this);
0114     }
0115 
0116     template <Transition Tr = Transition::Event>
0117     [[nodiscard]] auto esConsumes(ESInputTag tag) noexcept {
0118       return ConsumesCollectorWithTagESAdaptor<Tr>(*this, std::move(tag));
0119     }
0120 
0121   private:
0122     //only EDConsumerBase is allowed to make an instance of this class
0123     friend class EDConsumerBase;
0124 
0125     ConsumesCollector(EDConsumerBase* iConsumer) : m_consumer(iConsumer) {}
0126 
0127     // ---------- member data --------------------------------
0128     edm::propagate_const<EDConsumerBase*> m_consumer;
0129   };
0130 
0131   template <Transition TR>
0132   class ConsumesCollectorESAdaptor {
0133   public:
0134     template <typename TYPE, typename REC>
0135     ESGetToken<TYPE, REC> consumes() {
0136       return m_consumer.template esConsumes<TYPE, REC, TR>();
0137     }
0138 
0139   private:
0140     //only ConsumesCollector is allowed to make an instance of this class
0141     friend class ConsumesCollector;
0142 
0143     explicit ConsumesCollectorESAdaptor(ConsumesCollector iBase) : m_consumer(std::move(iBase)) {}
0144 
0145     ConsumesCollector m_consumer;
0146   };
0147 
0148   template <Transition TR>
0149   class ConsumesCollectorWithTagESAdaptor {
0150   public:
0151     template <typename TYPE, typename REC>
0152     ESGetToken<TYPE, REC> consumes() {
0153       return m_consumer.template esConsumes<TYPE, REC, TR>(m_tag);
0154     }
0155 
0156   private:
0157     //only ConsumesCollector is allowed to make an instance of this class
0158     friend class ConsumesCollector;
0159 
0160     ConsumesCollectorWithTagESAdaptor(ConsumesCollector iBase, ESInputTag iTag)
0161         : m_consumer(std::move(iBase)), m_tag(std::move(iTag)) {}
0162 
0163     ConsumesCollector m_consumer;
0164     ESInputTag const m_tag;
0165   };
0166 
0167   template <BranchType B>
0168   class ConsumesCollectorAdaptor {
0169   public:
0170     template <typename TYPE>
0171     EDGetTokenT<TYPE> consumes() {
0172       return m_consumer.template consumes<TYPE, B>(m_tag);
0173     }
0174 
0175   private:
0176     //only ConsumesCollector is allowed to make an instance of this class
0177     friend class ConsumesCollector;
0178 
0179     ConsumesCollectorAdaptor(ConsumesCollector iBase, edm::InputTag iTag) : m_consumer(iBase), m_tag(std::move(iTag)) {}
0180 
0181     ConsumesCollector m_consumer;
0182     edm::InputTag const m_tag;
0183   };
0184 
0185 }  // namespace edm
0186 
0187 #endif