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:
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):
52  product_(iProd),
53  prov_(iProv) {
54  }
55 
57  BasicHandle(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed) noexcept(true) :
58  product_(),
59  prov_(nullptr),
60  whyFailedFactory_(iWhyFailed) {}
61 
62  ~BasicHandle() = default;
63 
65  using std::swap;
66  swap(product_, other.product_);
67  std::swap(prov_, other.prov_);
68  swap(whyFailedFactory_,other.whyFailedFactory_);
69  }
70 
71  BasicHandle& operator=(BasicHandle&& rhs) = default;
72  BasicHandle& operator=(BasicHandle const& rhs) = default;
73 
74  bool isValid() const noexcept(true) {
75  return product_ && prov_;
76  }
77 
78  bool failedToGet() const noexcept(true) {
79  return bool(whyFailedFactory_);
80  }
81 
82  WrapperBase const* wrapper() const noexcept(true) {
83  return product_;
84  }
85 
86  Provenance const* provenance() const noexcept(true) {
87  return prov_;
88  }
89 
91  return prov_->productID();
92  }
93 
94  std::shared_ptr<cms::Exception> whyFailed() const {
95  return whyFailedFactory_->make();
96  }
97 
98  std::shared_ptr<HandleExceptionFactory> const& whyFailedFactory() const noexcept(true) {
99  return whyFailedFactory_;
100  }
101 
102  std::shared_ptr<HandleExceptionFactory>& whyFailedFactory() noexcept(true) {
103  return whyFailedFactory_;
104  }
105 
106  void clear() noexcept(true) {
107  product_ = nullptr;
108  prov_ = nullptr;
109  whyFailedFactory_.reset();
110  }
111 
112  static BasicHandle makeInvalid() { return BasicHandle(true);}
113  private:
114  //This is used to create a special invalid BasicHandle
115  explicit BasicHandle(bool):product_(nullptr) {}
118  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
119  };
120 
121  // Free swap function
122  inline
123  void
125  a.swap(b);
126  }
127 }
128 
129 #endif
WrapperBase const * wrapper() const (true)
Definition: BasicHandle.h:82
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: BasicHandle.h:118
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:94
bool isValid() const (true)
Definition: BasicHandle.h:74
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void clear()(true)
Definition: BasicHandle.h:106
#define nullptr
Provenance const * provenance() const (true)
Definition: BasicHandle.h:86
WrapperBase const * product_
Definition: BasicHandle.h:116
bool failedToGet() const (true)
Definition: BasicHandle.h:78
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::shared_ptr< HandleExceptionFactory > const & whyFailedFactory() const (true)
Definition: BasicHandle.h:98
void swap(BasicHandle &other)(true)
Definition: BasicHandle.h:64
Namespace of DDCMS conversion namespace.
#define noexcept
static BasicHandle makeInvalid()
Definition: BasicHandle.h:112
double b
Definition: hdecay.h:120
std::shared_ptr< HandleExceptionFactory > & whyFailedFactory()(true)
Definition: BasicHandle.h:102
HLT enums.
double a
Definition: hdecay.h:121
BasicHandle(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)(true)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:57
Provenance const * prov_
Definition: BasicHandle.h:117
BasicHandle(WrapperBase const *iProd, Provenance const *iProv)(true)
Definition: BasicHandle.h:51
ProductID id() const (true)
Definition: BasicHandle.h:90
void swap(BasicHandle &a, BasicHandle &b)(true)
Definition: BasicHandle.h:124