CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
33 
34 #include <memory>
35 
36 namespace cms {
37  class Exception;
38 }
39 
40 namespace edm {
41  class WrapperBase;
42  template <typename T> class Wrapper;
43 
44  class BasicHandle {
45  public:
47  product_(),
48  prov_(0) {}
49 
51  product_(h.product_),
52  prov_(h.prov_),
54 
55  explicit BasicHandle(ProductData const& productData) :
56  product_(productData.wrapper_.get()),
57  prov_(&productData.prov_) {
58  }
59 
60 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
61  BasicHandle(BasicHandle &&h) = default;
62 #endif
63 
64  BasicHandle(WrapperBase const* iProd, Provenance const* iProv) :
65  product_(iProd),
66  prov_(iProv) {
67  }
68 
70  BasicHandle(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed):
71  product_(),
72  prov_(0),
73  whyFailedFactory_(iWhyFailed) {}
74 
76 
77  void swap(BasicHandle& other) {
78  using std::swap;
79  swap(product_, other.product_);
80  std::swap(prov_, other.prov_);
82  }
83 
85  BasicHandle temp(rhs);
86  this->swap(temp);
87  return *this;
88  }
89 
90  bool isValid() const {
91  return product_ && prov_;
92  }
93 
94  bool failedToGet() const {
95  return bool(whyFailedFactory_);
96  }
97 
98  WrapperBase const* wrapper() const {
99  return product_;
100  }
101 
102  Provenance const* provenance() const {
103  return prov_;
104  }
105 
106  ProductID id() const {
107  return prov_->productID();
108  }
109 
110  std::shared_ptr<cms::Exception> whyFailed() const {
111  return whyFailedFactory_->make();
112  }
113 
114  std::shared_ptr<HandleExceptionFactory> const& whyFailedFactory() const {
115  return whyFailedFactory_;
116  }
117 
118  std::shared_ptr<HandleExceptionFactory>& whyFailedFactory() {
119  return whyFailedFactory_;
120  }
121 
122  private:
125  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
126  };
127 
128  // Free swap function
129  inline
130  void
132  a.swap(b);
133  }
134 }
135 
136 #endif
ProductID id() const
Definition: BasicHandle.h:106
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: BasicHandle.h:125
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:110
BasicHandle & operator=(BasicHandle const &rhs)
Definition: BasicHandle.h:84
WrapperBase const * product_
Definition: BasicHandle.h:123
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
BasicHandle(ProductData const &productData)
Definition: BasicHandle.h:55
BasicHandle(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:70
BasicHandle(WrapperBase const *iProd, Provenance const *iProv)
Definition: BasicHandle.h:64
Provenance const * provenance() const
Definition: BasicHandle.h:102
void swap(BasicHandle &other)
Definition: BasicHandle.h:77
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
BasicHandle(BasicHandle const &h)
Definition: BasicHandle.h:50
WrapperBase const * wrapper() const
Definition: BasicHandle.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool failedToGet() const
Definition: BasicHandle.h:94
double b
Definition: hdecay.h:120
bool isValid() const
Definition: BasicHandle.h:90
double a
Definition: hdecay.h:121
ProductID const & productID() const
Definition: Provenance.h:78
Provenance const * prov_
Definition: BasicHandle.h:124
std::shared_ptr< HandleExceptionFactory > & whyFailedFactory()
Definition: BasicHandle.h:118
T get(const Candidate &c)
Definition: component.h:55
std::shared_ptr< HandleExceptionFactory > const & whyFailedFactory() const
Definition: BasicHandle.h:114