Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:46:49

0001 #ifndef FWCore_Framework_ESValidHandle_h
0002 #define FWCore_Framework_ESValidHandle_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ESValidHandle
0007 //
0008 /**\class ESValidHandle ESValidHandle.h FWCore/Framework/interface/ESValidHandle.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Tue Feb  5 14:47:35 EST 2019
0019 //
0020 
0021 // system include files
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/ComponentDescription.h"
0025 
0026 #include <exception>
0027 #include <memory>
0028 #include <utility>
0029 
0030 namespace edm {
0031 
0032   namespace esvhhelper {
0033     void throwIfNotValid(const void*) noexcept(false);
0034   }
0035 
0036   template <typename T>
0037   class ESValidHandle {
0038   public:
0039     typedef T value_type;
0040 
0041     ESValidHandle() = delete;
0042     ESValidHandle(T const& iData, edm::eventsetup::ComponentDescription const* desc) noexcept
0043         : data_{&iData}, description_{desc} {}
0044 
0045     ESValidHandle(ESValidHandle<T> const&) = default;
0046     ESValidHandle(ESValidHandle<T>&&) = default;
0047     ESValidHandle& operator=(ESValidHandle<T> const&) = default;
0048     ESValidHandle& operator=(ESValidHandle<T>&&) = default;
0049 
0050     // ---------- const member functions ---------------------
0051     T const* product() const noexcept { return data_; }
0052     T const* operator->() const noexcept { return product(); }
0053     T const& operator*() const noexcept { return *product(); }
0054     // ---------- static member functions --------------------
0055     static constexpr bool transientAccessOnly = false;
0056 
0057     // ---------- member functions ---------------------------
0058   private:
0059     T const* data_{nullptr};
0060     edm::eventsetup::ComponentDescription const* description_{nullptr};
0061   };
0062 
0063   /** Take a handle (e.g. edm::ESHandle<T>) and
0064    create a edm::ESValidHandle<T>. If the argument is an invalid handle,
0065    an exception will be thrown.
0066    */
0067   template <typename U>
0068   auto makeESValid(const U& iOtherHandleType) noexcept(false) {
0069     esvhhelper::throwIfNotValid(iOtherHandleType.product());
0070     //because of the check, we know this is valid and do not have to check again
0071     return ESValidHandle<typename U::value_type>(*iOtherHandleType.product(), iOtherHandleType.description());
0072   }
0073 
0074 }  // namespace edm
0075 #endif