Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:18

0001 #ifndef FWCore_Utilities_EDGetToken_h
0002 #define FWCore_Utilities_EDGetToken_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Utilities
0006 // Class  :     EDGetToken
0007 //
0008 /**\class EDGetToken EDGetToken.h "FWCore/Utilities/interface/EDGetToken.h"
0009 
0010  Description: A Token used to get data from the EDM
0011 
0012  Usage:
0013     A EDGetToken is created by calls to 'consumes' or 'mayConsume' from an EDM module.
0014  The EDGetToken can then be used to quickly retrieve data from the edm::Event, edm::LuminosityBlock or edm::Run.
0015  
0016 The templated form, EDGetTokenT<T>, is the same as EDGetToken except when used to get data the framework
0017  will skip checking that the type being requested matches the type specified during the 'consumes' or 'mayConsume' call.
0018 
0019 */
0020 //
0021 // Original Author:  Chris Jones
0022 //         Created:  Wed, 03 Apr 2013 17:54:11 GMT
0023 //
0024 
0025 // system include files
0026 
0027 // user include files
0028 
0029 // forward declarations
0030 namespace edm {
0031   class EDConsumerBase;
0032   template <typename T>
0033   class EDGetTokenT;
0034 
0035   class EDGetToken {
0036     friend class EDConsumerBase;
0037 
0038   public:
0039     constexpr EDGetToken() noexcept : m_value{s_uninitializedValue} {}
0040 
0041     template <typename T>
0042     constexpr EDGetToken(EDGetTokenT<T> iOther) noexcept : m_value{iOther.m_value} {}
0043 
0044     constexpr EDGetToken(const EDGetToken&) noexcept = default;
0045     constexpr EDGetToken(EDGetToken&&) noexcept = default;
0046     constexpr EDGetToken& operator=(const EDGetToken&) noexcept = default;
0047     constexpr EDGetToken& operator=(EDGetToken&&) noexcept = default;
0048 
0049     // ---------- const member functions ---------------------
0050     constexpr unsigned int index() const noexcept { return m_value; }
0051     constexpr bool isUninitialized() const noexcept { return m_value == s_uninitializedValue; }
0052 
0053   private:
0054     //for testing
0055     friend class TestEDGetToken;
0056 
0057     static const unsigned int s_uninitializedValue = 0xFFFFFFFF;
0058 
0059     constexpr explicit EDGetToken(unsigned int iValue) noexcept : m_value(iValue) {}
0060 
0061     // ---------- member data --------------------------------
0062     unsigned int m_value;
0063   };
0064 
0065   template <typename T>
0066   class EDGetTokenT {
0067     friend class EDConsumerBase;
0068     friend class EDGetToken;
0069 
0070   public:
0071     constexpr EDGetTokenT() : m_value{s_uninitializedValue} {}
0072 
0073     constexpr EDGetTokenT(const EDGetTokenT<T>&) noexcept = default;
0074     constexpr EDGetTokenT(EDGetTokenT<T>&&) noexcept = default;
0075     constexpr EDGetTokenT& operator=(const EDGetTokenT<T>&) noexcept = default;
0076     constexpr EDGetTokenT& operator=(EDGetTokenT<T>&&) noexcept = default;
0077 
0078     template <typename ADAPTER>
0079     constexpr explicit EDGetTokenT(ADAPTER&& iAdapter) : EDGetTokenT(iAdapter.template consumes<T>()) {}
0080 
0081     template <typename ADAPTER>
0082     constexpr EDGetTokenT& operator=(ADAPTER&& iAdapter) {
0083       EDGetTokenT<T> temp(iAdapter.template consumes<T>());
0084       m_value = temp.m_value;
0085 
0086       return *this;
0087     }
0088 
0089     //Needed to avoid EDGetTokenT(ADAPTER&&) from being called instead
0090     // when we can use C++20 concepts we can avoid the problem using a constraint
0091     constexpr EDGetTokenT(EDGetTokenT<T>& iOther) noexcept : m_value{iOther.m_value} {}
0092     constexpr EDGetTokenT(const EDGetTokenT<T>&& iOther) noexcept : m_value{iOther.m_value} {}
0093 
0094     constexpr EDGetTokenT& operator=(EDGetTokenT<T>& iOther) {
0095       return (*this = const_cast<const EDGetTokenT<T>&>(iOther));
0096     }
0097     // ---------- const member functions ---------------------
0098     constexpr unsigned int index() const noexcept { return m_value; }
0099     constexpr bool isUninitialized() const noexcept { return m_value == s_uninitializedValue; }
0100 
0101   private:
0102     //for testing
0103     friend class TestEDGetToken;
0104 
0105     static const unsigned int s_uninitializedValue = 0xFFFFFFFF;
0106 
0107     constexpr explicit EDGetTokenT(unsigned int iValue) noexcept : m_value(iValue) {}
0108 
0109     // ---------- member data --------------------------------
0110     unsigned int m_value;
0111   };
0112 }  // namespace edm
0113 
0114 #endif