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