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>
36 
37 namespace cms {
38  class Exception;
39 }
40 
41 namespace edm {
42  class WrapperBase;
43  template <typename T> class Wrapper;
44 
45  class BasicHandle {
46  public:
48  product_(),
49  prov_(0) {}
50 
52  product_(h.product_),
53  prov_(h.prov_),
55 
56  explicit BasicHandle(ProductData const& productData) :
57  product_(productData.wrapper_.get()),
58  prov_(&productData.prov_) {
59  }
60 
61 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
62  BasicHandle(BasicHandle &&h) = default;
63 #endif
64 
65  BasicHandle(WrapperBase const* iProd, Provenance const* iProv) :
66  product_(iProd),
67  prov_(iProv) {
68  }
69 
71  BasicHandle(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed):
72  product_(),
73  prov_(0),
74  whyFailedFactory_(iWhyFailed) {}
75 
77 
78  void swap(BasicHandle& other) {
79  using std::swap;
80  swap(product_, other.product_);
81  std::swap(prov_, other.prov_);
83  }
84 
86  BasicHandle temp(rhs);
87  this->swap(temp);
88  return *this;
89  }
90 
91  bool isValid() const {
92  return product_ && prov_;
93  }
94 
95  bool failedToGet() const {
96  return bool(whyFailedFactory_);
97  }
98 
99  WrapperBase const* wrapper() const {
100  return product_;
101  }
102 
103  Provenance const* provenance() const {
104  return prov_;
105  }
106 
107  ProductID id() const {
108  return prov_->productID();
109  }
110 
111  std::shared_ptr<cms::Exception> whyFailed() const {
112  return whyFailedFactory_->make();
113  }
114 
115  std::shared_ptr<HandleExceptionFactory> const& whyFailedFactory() const {
116  return whyFailedFactory_;
117  }
118 
119  std::shared_ptr<HandleExceptionFactory>& whyFailedFactory() {
120  return whyFailedFactory_;
121  }
122 
123  private:
126  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
127  };
128 
129  // Free swap function
130  inline
131  void
133  a.swap(b);
134  }
135 }
136 
137 #endif
ProductID id() const
Definition: BasicHandle.h:107
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: BasicHandle.h:126
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:111
BasicHandle & operator=(BasicHandle const &rhs)
Definition: BasicHandle.h:85
WrapperBase const * product_
Definition: BasicHandle.h:124
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
BasicHandle(ProductData const &productData)
Definition: BasicHandle.h:56
BasicHandle(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:71
BasicHandle(WrapperBase const *iProd, Provenance const *iProv)
Definition: BasicHandle.h:65
Provenance const * provenance() const
Definition: BasicHandle.h:103
void swap(BasicHandle &other)
Definition: BasicHandle.h:78
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
BasicHandle(BasicHandle const &h)
Definition: BasicHandle.h:51
WrapperBase const * wrapper() const
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
bool failedToGet() const
Definition: BasicHandle.h:95
double b
Definition: hdecay.h:120
bool isValid() const
Definition: BasicHandle.h:91
double a
Definition: hdecay.h:121
ProductID const & productID() const
Definition: Provenance.h:79
Provenance const * prov_
Definition: BasicHandle.h:125
std::shared_ptr< HandleExceptionFactory > & whyFailedFactory()
Definition: BasicHandle.h:119
T get(const Candidate &c)
Definition: component.h:55
std::shared_ptr< HandleExceptionFactory > const & whyFailedFactory() const
Definition: BasicHandle.h:115