CMS 3D CMS Logo

BasicHandle.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_BasicHandle_h
2 #define DataFormats_Common_BasicHandle_h
3 
4 /*----------------------------------------------------------------------
5 
6 Handle: Shared "smart pointer" for reference to EDProducts and
7 their Provenances.
8 
9 This is a very preliminary version, and lacks safety features and
10 elegance.
11 
12 If the pointed-to EDProduct or Provenance is destroyed, use of the
13 Handle becomes undefined. There is no way to query the Handle to
14 discover if this has happened.
15 
16 Handles can have:
17  -- Product and Provenance pointers both null;
18  -- Both pointers valid
19 
20 To check validity, one can use the isValid() function.
21 
22 If failedToGet() returns true then the requested data is not available
23 If failedToGet() returns false but isValid() is also false then no attempt
24  to get data has occurred
25 
26 ----------------------------------------------------------------------*/
27 
31 
32 #include <memory>
33 
34 namespace cms {
35  class Exception;
36 }
37 
38 namespace edm {
39  class WrapperBase;
40  template <typename T>
41  class Wrapper;
42 
43  class BasicHandle {
44  public:
45  BasicHandle() = delete;
46 
47  BasicHandle(BasicHandle const& h) = default;
48 
49  BasicHandle(BasicHandle&& h) = default;
50 
51  BasicHandle(WrapperBase const* iProd, Provenance const* iProv) noexcept(true) : product_(iProd), prov_(iProv) {}
52 
54  BasicHandle(std::shared_ptr<HandleExceptionFactory const> const& iWhyFailed) noexcept(true)
55  : product_(), prov_(nullptr), whyFailedFactory_(iWhyFailed) {}
56 
57  ~BasicHandle() = default;
58 
59  void swap(BasicHandle& other) noexcept(true) {
60  using std::swap;
61  swap(product_, other.product_);
62  std::swap(prov_, other.prov_);
63  swap(whyFailedFactory_, other.whyFailedFactory_);
64  }
65 
66  BasicHandle& operator=(BasicHandle&& rhs) = default;
67  BasicHandle& operator=(BasicHandle const& rhs) = default;
68 
69  bool isValid() const noexcept(true) { return product_ && prov_; }
70 
71  bool failedToGet() const noexcept(true) { return bool(whyFailedFactory_); }
72 
73  WrapperBase const* wrapper() const noexcept(true) { return product_; }
74 
75  Provenance const* provenance() const noexcept(true) { return prov_; }
76 
77  ProductID id() const noexcept(true) { return prov_->productID(); }
78 
79  std::shared_ptr<cms::Exception> whyFailed() const { return whyFailedFactory_->make(); }
80 
81  std::shared_ptr<HandleExceptionFactory const> const& whyFailedFactory() const noexcept(true) {
82  return whyFailedFactory_;
83  }
84 
85  std::shared_ptr<HandleExceptionFactory const>& whyFailedFactory() noexcept(true) { return whyFailedFactory_; }
86 
87  void clear() noexcept(true) {
88  product_ = nullptr;
89  prov_ = nullptr;
90  whyFailedFactory_.reset();
91  }
92 
93  static BasicHandle makeInvalid() { return BasicHandle(true); }
94 
95  private:
96  //This is used to create a special invalid BasicHandle
97  explicit BasicHandle(bool) : product_(nullptr) {}
99  Provenance const* prov_;
100  std::shared_ptr<HandleExceptionFactory const> whyFailedFactory_;
101  };
102 
103  // Free swap function
104  inline void swap(BasicHandle& a, BasicHandle& b) noexcept(true) { a.swap(b); }
105 } // namespace edm
106 
107 #endif
BasicHandle()=delete
ProductID const & productID() const
Definition: Provenance.h:79
BasicHandle(std::shared_ptr< HandleExceptionFactory const > const &iWhyFailed) noexcept(true)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:54
WrapperBase const * product_
Definition: BasicHandle.h:98
std::shared_ptr< HandleExceptionFactory const > const & whyFailedFactory() const noexcept(true)
Definition: BasicHandle.h:81
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
BasicHandle & operator=(BasicHandle &&rhs)=default
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:79
void clear() noexcept(true)
Definition: BasicHandle.h:87
bool failedToGet() const noexcept(true)
Definition: BasicHandle.h:71
bool isValid() const noexcept(true)
Definition: BasicHandle.h:69
void swap(BasicHandle &other) noexcept(true)
Definition: BasicHandle.h:59
Namespace of DDCMS conversion namespace.
std::shared_ptr< HandleExceptionFactory const > & whyFailedFactory() noexcept(true)
Definition: BasicHandle.h:85
static BasicHandle makeInvalid()
Definition: BasicHandle.h:93
WrapperBase const * wrapper() const noexcept(true)
Definition: BasicHandle.h:73
double b
Definition: hdecay.h:120
std::shared_ptr< HandleExceptionFactory const > whyFailedFactory_
Definition: BasicHandle.h:100
~BasicHandle()=default
HLT enums.
double a
Definition: hdecay.h:121
BasicHandle(WrapperBase const *iProd, Provenance const *iProv) noexcept(true)
Definition: BasicHandle.h:51
Provenance const * prov_
Definition: BasicHandle.h:99
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Provenance const * provenance() const noexcept(true)
Definition: BasicHandle.h:75
ProductID id() const noexcept(true)
Definition: BasicHandle.h:77