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 
32 
33 #include <memory>
34 
35 namespace cms {
36  class Exception;
37 }
38 
39 namespace edm {
40  class WrapperBase;
41  template <typename T> class Wrapper;
42 
43  class BasicHandle {
44  public:
46  product_(),
47  prov_(nullptr) {}
48 
50  product_(h.product_),
51  prov_(h.prov_),
52  whyFailedFactory_(h.whyFailedFactory_){}
53 
54  BasicHandle(BasicHandle &&h) = default;
55 
56  BasicHandle(WrapperBase const* iProd, Provenance const* iProv) :
57  product_(iProd),
58  prov_(iProv) {
59  }
60 
62  BasicHandle(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed):
63  product_(),
64  prov_(nullptr),
65  whyFailedFactory_(iWhyFailed) {}
66 
68 
70  using std::swap;
71  swap(product_, other.product_);
72  std::swap(prov_, other.prov_);
73  swap(whyFailedFactory_,other.whyFailedFactory_);
74  }
75 
77  BasicHandle temp(rhs);
78  this->swap(temp);
79  return *this;
80  }
81 
82  bool isValid() const {
83  return product_ && prov_;
84  }
85 
86  bool failedToGet() const {
87  return bool(whyFailedFactory_);
88  }
89 
90  WrapperBase const* wrapper() const {
91  return product_;
92  }
93 
94  Provenance const* provenance() const {
95  return prov_;
96  }
97 
98  ProductID id() const {
99  return prov_->productID();
100  }
101 
102  std::shared_ptr<cms::Exception> whyFailed() const {
103  return whyFailedFactory_->make();
104  }
105 
106  std::shared_ptr<HandleExceptionFactory> const& whyFailedFactory() const {
107  return whyFailedFactory_;
108  }
109 
110  std::shared_ptr<HandleExceptionFactory>& whyFailedFactory() {
111  return whyFailedFactory_;
112  }
113 
114  void clear() {
115  product_ = nullptr;
116  prov_ = nullptr;
117  whyFailedFactory_.reset();
118  }
119 
120  private:
123  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
124  };
125 
126  // Free swap function
127  inline
128  void
130  a.swap(b);
131  }
132 }
133 
134 #endif
ProductID id() const
Definition: BasicHandle.h:98
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: BasicHandle.h:123
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:102
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void swap(BasicHandle &a, BasicHandle &b)
Definition: BasicHandle.h:129
BasicHandle & operator=(BasicHandle const &rhs)
Definition: BasicHandle.h:76
#define nullptr
WrapperBase const * product_
Definition: BasicHandle.h:121
BasicHandle(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:62
BasicHandle(WrapperBase const *iProd, Provenance const *iProv)
Definition: BasicHandle.h:56
Provenance const * provenance() const
Definition: BasicHandle.h:94
void swap(BasicHandle &other)
Definition: BasicHandle.h:69
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
BasicHandle(BasicHandle const &h)
Definition: BasicHandle.h:49
WrapperBase const * wrapper() const
Definition: BasicHandle.h:90
Namespace of DDCMS conversion namespace.
bool failedToGet() const
Definition: BasicHandle.h:86
double b
Definition: hdecay.h:120
bool isValid() const
Definition: BasicHandle.h:82
HLT enums.
double a
Definition: hdecay.h:121
Provenance const * prov_
Definition: BasicHandle.h:122
std::shared_ptr< HandleExceptionFactory > & whyFailedFactory()
Definition: BasicHandle.h:110
std::shared_ptr< HandleExceptionFactory > const & whyFailedFactory() const
Definition: BasicHandle.h:106