CMS 3D CMS Logo

ESHandle.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ESHandle_h
2 #define FWCore_Framework_ESHandle_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ESHandle
7 //
16 //
17 // Author: Chris Jones
18 // Created: Fri Apr 1 14:47:35 EST 2005
19 //
20 
21 // system include files
22 
23 // user include files
26 
27 #include <exception>
28 #include <memory>
29 #include <utility>
30 
31 namespace edm {
32 
33  class ESHandleBase {
34  public:
35  ESHandleBase() = default;
36  ESHandleBase(void const* iData, edm::eventsetup::ComponentDescription const* desc)
37  : data_(iData), description_(desc) {}
38 
40  ESHandleBase(std::shared_ptr<ESHandleExceptionFactory>&& iWhyFailed) : whyFailedFactory_(std::move(iWhyFailed)) {}
41 
43 
44  bool isValid() const { return nullptr != data_ && nullptr != description_; }
45 
46  bool failedToGet() const { return bool(whyFailedFactory_); }
47 
48  explicit operator bool() const { return isValid(); }
49 
50  bool operator!() const { return not isValid(); }
51 
52  void swap(ESHandleBase& iOther) {
53  std::swap(data_, iOther.data_);
56  }
57 
58  std::shared_ptr<ESHandleExceptionFactory> const& whyFailedFactory() const { return whyFailedFactory_; }
59 
60  protected:
61  void const* productStorage() const {
62  if (whyFailedFactory_) {
63  std::rethrow_exception(whyFailedFactory_->make());
64  }
65  return data_;
66  }
67 
68  private:
69  // ---------- member data --------------------------------
70  void const* data_{nullptr};
72  std::shared_ptr<ESHandleExceptionFactory> whyFailedFactory_{nullptr};
73  };
74 
75  template <typename T>
76  class ESHandle : public ESHandleBase {
77  public:
78  typedef T value_type;
79 
80  ESHandle() = default;
81  ESHandle(T const* iData) : ESHandleBase(iData, nullptr) {}
82  ESHandle(T const* iData, edm::eventsetup::ComponentDescription const* desc) : ESHandleBase(iData, desc) {}
83  ESHandle(std::shared_ptr<ESHandleExceptionFactory>&&);
84 
85  // ---------- const member functions ---------------------
86  T const* product() const { return static_cast<T const*>(productStorage()); }
87  T const* operator->() const { return product(); }
88  T const& operator*() const { return *product(); }
89  // ---------- static member functions --------------------
90  static constexpr bool transientAccessOnly = false;
91 
92  // ---------- member functions ---------------------------
93  };
94 
95  template <class T>
96  ESHandle<T>::ESHandle(std::shared_ptr<edm::ESHandleExceptionFactory>&& iWhyFailed)
97  : ESHandleBase(std::move(iWhyFailed)) {}
98 
99  // Free swap function
100  inline void swap(ESHandleBase& a, ESHandleBase& b) { a.swap(b); }
101 } // namespace edm
102 #endif
#define nullptr
T const & operator*() const
Definition: ESHandle.h:88
edm::eventsetup::ComponentDescription const * description() const
Definition: ESHandle.cc:9
ESHandleBase()=default
ESHandle(T const *iData, edm::eventsetup::ComponentDescription const *desc)
Definition: ESHandle.h:82
T const * operator->() const
Definition: ESHandle.h:87
bool failedToGet() const
Definition: ESHandle.h:46
ESHandle()=default
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
void swap(ESHandleBase &a, ESHandleBase &b)
Definition: ESHandle.h:100
ESHandle(T const *iData)
Definition: ESHandle.h:81
std::shared_ptr< ESHandleExceptionFactory > whyFailedFactory_
Definition: ESHandle.h:72
edm::eventsetup::ComponentDescription const * description_
Definition: ESHandle.h:71
void const * data_
Definition: ESHandle.h:70
ESHandleBase(std::shared_ptr< ESHandleExceptionFactory > &&iWhyFailed)
Used when the attempt to get the data failed.
Definition: ESHandle.h:40
std::shared_ptr< ESHandleExceptionFactory > const & whyFailedFactory() const
Definition: ESHandle.h:58
double b
Definition: hdecay.h:120
HLT enums.
double a
Definition: hdecay.h:121
void const * productStorage() const
Definition: ESHandle.h:61
bool isValid() const
Definition: ESHandle.h:44
long double T
ESHandleBase(void const *iData, edm::eventsetup::ComponentDescription const *desc)
Definition: ESHandle.h:36
T const * product() const
Definition: ESHandle.h:86
void swap(ESHandleBase &iOther)
Definition: ESHandle.h:52
def move(src, dest)
Definition: eostools.py:511
#define constexpr
bool operator!() const
Definition: ESHandle.h:50