Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 fwlite {
0031   class EventBase;
0032 }
0033 
0034 namespace edm {
0035   class EDConsumerBase;
0036   template <typename T>
0037   class EDGetTokenT;
0038 
0039   class EDGetToken {
0040     friend class EDConsumerBase;
0041 
0042   public:
0043     constexpr EDGetToken() noexcept : m_value{s_uninitializedValue} {}
0044 
0045     template <typename T>
0046     constexpr EDGetToken(EDGetTokenT<T> iOther) noexcept : m_value{iOther.m_value} {}
0047 
0048     constexpr EDGetToken(const EDGetToken&) noexcept = default;
0049     constexpr EDGetToken(EDGetToken&&) noexcept = default;
0050     constexpr EDGetToken& operator=(const EDGetToken&) noexcept = default;
0051     constexpr EDGetToken& operator=(EDGetToken&&) noexcept = default;
0052 
0053     // ---------- const member functions ---------------------
0054     constexpr unsigned int index() const noexcept { return m_value; }
0055     constexpr bool isUninitialized() const noexcept { return m_value == s_uninitializedValue; }
0056 
0057   private:
0058     //for testing
0059     friend class TestEDGetToken;
0060 
0061     static const unsigned int s_uninitializedValue = 0xFFFFFFFF;
0062 
0063     constexpr explicit EDGetToken(unsigned int iValue) noexcept : m_value(iValue) {}
0064 
0065     // ---------- member data --------------------------------
0066     unsigned int m_value;
0067   };
0068 
0069   template <typename T>
0070   class EDGetTokenT {
0071     friend class EDConsumerBase;
0072     friend class EDGetToken;
0073     friend class ::fwlite::EventBase;
0074 
0075   public:
0076     constexpr EDGetTokenT() : m_value{s_uninitializedValue} {}
0077 
0078     constexpr EDGetTokenT(const EDGetTokenT<T>&) noexcept = default;
0079     constexpr EDGetTokenT(EDGetTokenT<T>&&) noexcept = default;
0080     constexpr EDGetTokenT& operator=(const EDGetTokenT<T>&) noexcept = default;
0081     constexpr EDGetTokenT& operator=(EDGetTokenT<T>&&) noexcept = default;
0082 
0083     template <typename ADAPTER>
0084     constexpr explicit EDGetTokenT(ADAPTER&& iAdapter) : EDGetTokenT(iAdapter.template consumes<T>()) {}
0085 
0086     template <typename ADAPTER>
0087     constexpr EDGetTokenT& operator=(ADAPTER&& iAdapter) {
0088       EDGetTokenT<T> temp(iAdapter.template consumes<T>());
0089       m_value = temp.m_value;
0090 
0091       return *this;
0092     }
0093 
0094     //Needed to avoid EDGetTokenT(ADAPTER&&) from being called instead
0095     // when we can use C++20 concepts we can avoid the problem using a constraint
0096     constexpr EDGetTokenT(EDGetTokenT<T>& iOther) noexcept : m_value{iOther.m_value} {}
0097     constexpr EDGetTokenT(const EDGetTokenT<T>&& iOther) noexcept : m_value{iOther.m_value} {}
0098 
0099     constexpr EDGetTokenT& operator=(EDGetTokenT<T>& iOther) {
0100       return (*this = const_cast<const EDGetTokenT<T>&>(iOther));
0101     }
0102     // ---------- const member functions ---------------------
0103     constexpr unsigned int index() const noexcept { return m_value; }
0104     constexpr bool isUninitialized() const noexcept { return m_value == s_uninitializedValue; }
0105 
0106   private:
0107     //for testing
0108     friend class TestEDGetToken;
0109 
0110     static const unsigned int s_uninitializedValue = 0xFFFFFFFF;
0111 
0112     constexpr explicit EDGetTokenT(unsigned int iValue) noexcept : m_value(iValue) {}
0113 
0114     // ---------- member data --------------------------------
0115     unsigned int m_value;
0116   };
0117 }  // namespace edm
0118 
0119 #endif