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 
30 
31 #include "boost/shared_ptr.hpp"
32 
33 namespace cms {
34  class Exception;
35 }
36 
37 namespace edm {
38  class EDProduct;
39  template <typename T> class Wrapper;
40 
41  class BasicHandle {
42  public:
44  product_(),
45  prov_(0) {}
46 
48  product_(h.product_),
49  prov_(h.prov_),
51 
52  BasicHandle(boost::shared_ptr<EDProduct const> prod, Provenance const* prov) :
53  product_(prod), prov_(prov) {
54 
55  }
56 
58  BasicHandle(boost::shared_ptr<cms::Exception> const& iWhyFailed):
59  product_(),
60  prov_(0),
61  whyFailed_(iWhyFailed) {}
62 
64 
65  void swap(BasicHandle& other) {
66  using std::swap;
67  swap(product_, other.product_);
68  std::swap(prov_, other.prov_);
69  swap(whyFailed_,other.whyFailed_);
70  }
71 
72 
74  BasicHandle temp(rhs);
75  this->swap(temp);
76  return *this;
77  }
78 
79  bool isValid() const {
80  return product_ && prov_;
81  }
82 
83  bool failedToGet() const {
84  return 0 != whyFailed_.get();
85  }
86 
87  EDProduct const* wrapper() const {
88  return product_.get();
89  }
90 
91  boost::shared_ptr<EDProduct const> product() const {
92  return product_;
93  }
94 
95  Provenance const* provenance() const {
96  return prov_;
97  }
98 
99  ProductID id() const {
100  return prov_->productID();
101  }
102 
103  boost::shared_ptr<cms::Exception> whyFailed() const {
104  return whyFailed_;
105  }
106  private:
107  boost::shared_ptr<EDProduct const> product_;
109  boost::shared_ptr<cms::Exception> whyFailed_;
110  };
111 
112  // Free swap function
113  inline
114  void
116  a.swap(b);
117  }
118 }
119 
120 #endif
ProductID id() const
Definition: BasicHandle.h:99
EDProduct const * wrapper() const
Definition: BasicHandle.h:87
BasicHandle & operator=(BasicHandle const &rhs)
Definition: BasicHandle.h:73
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
BasicHandle(boost::shared_ptr< EDProduct const > prod, Provenance const *prov)
Definition: BasicHandle.h:52
Provenance const * provenance() const
Definition: BasicHandle.h:95
void swap(BasicHandle &other)
Definition: BasicHandle.h:65
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
BasicHandle(BasicHandle const &h)
Definition: BasicHandle.h:47
boost::shared_ptr< cms::Exception > whyFailed_
Definition: BasicHandle.h:109
bool failedToGet() const
Definition: BasicHandle.h:83
boost::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:103
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:58
bool isValid() const
Definition: BasicHandle.h:79
double a
Definition: hdecay.h:121
boost::shared_ptr< EDProduct const > product() const
Definition: BasicHandle.h:91
boost::shared_ptr< EDProduct const > product_
Definition: BasicHandle.h:107
ProductID const & productID() const
Definition: Provenance.h:88
Provenance const * prov_
Definition: BasicHandle.h:108
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4