Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:36:17

0001 #ifndef FWCore_Utilities_ESGetToken_h
0002 #define FWCore_Utilities_ESGetToken_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Utilities
0006 // Class  :     ESGetToken
0007 //
0008 /**\class ESGetToken ESGetToken.h "FWCore/Utilities/interface/ESGetToken.h"
0009 
0010  Description: A token used to get data from the event setup system
0011 
0012  Usage:
0013     An ESGetToken is created by calls to 'esConsumes' from an ED module
0014     or via a ConsumesCollector::consumes.
0015 */
0016 
0017 #include "FWCore/Utilities/interface/ESInputTag.h"
0018 #include "FWCore/Utilities/interface/ESIndices.h"
0019 #include <limits>
0020 
0021 namespace edm {
0022   class EDConsumerBase;
0023   class ESProducer;
0024   class ESConsumesCollector;
0025   class EventSetup;
0026   class EventSetupImpl;
0027   namespace eventsetup {
0028     class EventSetupRecord;
0029   }
0030 
0031   // A ESGetToken is created by calls to 'esConsumes' from an EDM
0032   // module.
0033   template <typename ESProduct, typename ESRecord>
0034   class ESGetToken {
0035     friend class EDConsumerBase;
0036     friend class ESProducer;
0037     friend class ESConsumesCollector;
0038     friend class EventSetup;
0039     friend class EventSetupImpl;
0040     friend class eventsetup::EventSetupRecord;
0041 
0042   public:
0043     constexpr ESGetToken() noexcept = default;
0044 
0045     constexpr ESGetToken(ESGetToken<ESProduct, ESRecord> const&) noexcept = default;
0046     constexpr ESGetToken(ESGetToken<ESProduct, ESRecord>&&) noexcept = default;
0047 
0048     constexpr ESGetToken<ESProduct, ESRecord>& operator=(ESGetToken<ESProduct, ESRecord>&&) noexcept = default;
0049     constexpr ESGetToken<ESProduct, ESRecord>& operator=(ESGetToken<ESProduct, ESRecord> const&) noexcept = default;
0050 
0051     template <typename ADAPTER>
0052     constexpr explicit ESGetToken(ADAPTER&& iAdapter) : ESGetToken(iAdapter.template consumes<ESProduct, ESRecord>()) {}
0053 
0054     template <typename ADAPTER>
0055     constexpr ESGetToken<ESProduct, ESRecord>& operator=(ADAPTER&& iAdapter) {
0056       ESGetToken<ESProduct, ESRecord> temp(std::forward<ADAPTER>(iAdapter));
0057       return (*this = std::move(temp));
0058     }
0059 
0060     //protect against templated version being a better match
0061     constexpr ESGetToken(ESGetToken<ESProduct, ESRecord>& iOther)
0062         : ESGetToken(const_cast<const ESGetToken<ESProduct, ESRecord>&>(iOther)) {}
0063     constexpr ESGetToken<ESProduct, ESRecord>& operator=(ESGetToken<ESProduct, ESRecord>& iOther) noexcept {
0064       return (*this = const_cast<ESGetToken<ESProduct, ESRecord> const&>(iOther));
0065     }
0066     constexpr ESGetToken(ESGetToken<ESProduct, ESRecord> const&& iOther) : ESGetToken(iOther) {}
0067     constexpr ESGetToken<ESProduct, ESRecord>& operator=(ESGetToken<ESProduct, ESRecord> const&& iOther) noexcept {
0068       return (*this = iOther);
0069     }
0070 
0071     constexpr unsigned int transitionID() const noexcept { return m_transitionID; }
0072     constexpr bool isInitialized() const noexcept { return transitionID() != std::numeric_limits<unsigned int>::max(); }
0073     constexpr ESTokenIndex index() const noexcept { return m_index; }
0074     constexpr bool hasValidIndex() const noexcept { return index() != invalidIndex(); }
0075     static constexpr ESTokenIndex invalidIndex() noexcept { return ESTokenIndex{std::numeric_limits<int>::max()}; }
0076 
0077   private:
0078     explicit constexpr ESGetToken(unsigned int transitionID, ESTokenIndex index, char const* label) noexcept
0079         : m_label{label}, m_transitionID{transitionID}, m_index{index} {}
0080 
0081     constexpr char const* name() const noexcept { return m_label; }
0082     char const* m_label{nullptr};
0083     unsigned int m_transitionID{std::numeric_limits<unsigned int>::max()};
0084     ESTokenIndex m_index{std::numeric_limits<int>::max()};
0085   };
0086 
0087 }  // namespace edm
0088 
0089 #endif