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