Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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