Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-08-22 04:57:39

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       requires requires(ADAPTER&& a) { a.template consumes<T>(); }
0085     constexpr explicit EDGetTokenT(ADAPTER&& iAdapter) : EDGetTokenT(iAdapter.template consumes<T>()) {}
0086 
0087     template <typename ADAPTER>
0088       requires requires(ADAPTER&& a) { a.template consumes<T>(); }
0089     constexpr EDGetTokenT& operator=(ADAPTER&& iAdapter) {
0090       EDGetTokenT<T> temp(iAdapter.template consumes<T>());
0091       m_value = temp.m_value;
0092 
0093       return *this;
0094     }
0095 
0096     // ---------- const member functions ---------------------
0097     constexpr unsigned int index() const noexcept { return m_value; }
0098     constexpr bool isUninitialized() const noexcept { return m_value == s_uninitializedValue; }
0099 
0100   private:
0101     //for testing
0102     friend class TestEDGetToken;
0103 
0104     static const unsigned int s_uninitializedValue = 0xFFFFFFFF;
0105 
0106     constexpr explicit EDGetTokenT(unsigned int iValue) noexcept : m_value(iValue) {}
0107 
0108     // ---------- member data --------------------------------
0109     unsigned int m_value;
0110   };
0111 }  // namespace edm
0112 
0113 #endif