CMS 3D CMS Logo

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 
32 
33 #include <memory>
34 
35 namespace cms {
36  class Exception;
37 }
38 
39 namespace edm {
40  class WrapperBase;
41  template <typename T>
42  class Wrapper;
43 
44  class BasicHandle {
45  public:
46  BasicHandle() = delete;
47 
48  BasicHandle(BasicHandle const& h) = default;
49 
50  BasicHandle(BasicHandle&& h) = default;
51 
52  BasicHandle(WrapperBase const* iProd, Provenance const* iProv) noexcept(true) : product_(iProd), prov_(iProv) {}
53 
55  BasicHandle(std::shared_ptr<HandleExceptionFactory> const& iWhyFailed) noexcept(true)
56  : product_(), prov_(nullptr), whyFailedFactory_(iWhyFailed) {}
57 
58  ~BasicHandle() = default;
59 
60  void swap(BasicHandle& other) noexcept(true) {
61  using std::swap;
62  swap(product_, other.product_);
63  std::swap(prov_, other.prov_);
64  swap(whyFailedFactory_, other.whyFailedFactory_);
65  }
66 
67  BasicHandle& operator=(BasicHandle&& rhs) = default;
68  BasicHandle& operator=(BasicHandle const& rhs) = default;
69 
70  bool isValid() const noexcept(true) { return product_ && prov_; }
71 
72  bool failedToGet() const noexcept(true) { return bool(whyFailedFactory_); }
73 
74  WrapperBase const* wrapper() const noexcept(true) { return product_; }
75 
76  Provenance const* provenance() const noexcept(true) { return prov_; }
77 
78  ProductID id() const noexcept(true) { return prov_->productID(); }
79 
80  std::shared_ptr<cms::Exception> whyFailed() const { return whyFailedFactory_->make(); }
81 
82  std::shared_ptr<HandleExceptionFactory> const& whyFailedFactory() const noexcept(true) { return whyFailedFactory_; }
83 
84  std::shared_ptr<HandleExceptionFactory>& whyFailedFactory() noexcept(true) { return whyFailedFactory_; }
85 
86  void clear() noexcept(true) {
87  product_ = nullptr;
88  prov_ = nullptr;
89  whyFailedFactory_.reset();
90  }
91 
92  static BasicHandle makeInvalid() { return BasicHandle(true); }
93 
94  private:
95  //This is used to create a special invalid BasicHandle
96  explicit BasicHandle(bool) : product_(nullptr) {}
98  Provenance const* prov_;
99  std::shared_ptr<HandleExceptionFactory> whyFailedFactory_;
100  };
101 
102  // Free swap function
103  inline void swap(BasicHandle& a, BasicHandle& b) noexcept(true) { a.swap(b); }
104 } // namespace edm
105 
106 #endif
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
WrapperBase const * wrapper() const (true)
Definition: BasicHandle.h:74
std::shared_ptr< HandleExceptionFactory > whyFailedFactory_
Definition: BasicHandle.h:99
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:80
bool isValid() const (true)
Definition: BasicHandle.h:70
void clear()(true)
Definition: BasicHandle.h:86
#define nullptr
Provenance const * provenance() const (true)
Definition: BasicHandle.h:76
WrapperBase const * product_
Definition: BasicHandle.h:97
bool failedToGet() const (true)
Definition: BasicHandle.h:72
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::shared_ptr< HandleExceptionFactory > const & whyFailedFactory() const (true)
Definition: BasicHandle.h:82
void swap(BasicHandle &other)(true)
Definition: BasicHandle.h:60
Namespace of DDCMS conversion namespace.
#define noexcept
static BasicHandle makeInvalid()
Definition: BasicHandle.h:92
double b
Definition: hdecay.h:118
std::shared_ptr< HandleExceptionFactory > & whyFailedFactory()(true)
Definition: BasicHandle.h:84
HLT enums.
double a
Definition: hdecay.h:119
BasicHandle(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)(true)
Used when the attempt to get the data failed.
Definition: BasicHandle.h:55
Provenance const * prov_
Definition: BasicHandle.h:98
BasicHandle(WrapperBase const *iProd, Provenance const *iProv)(true)
Definition: BasicHandle.h:52
ProductID id() const (true)
Definition: BasicHandle.h:78
void swap(BasicHandle &a, BasicHandle &b)(true)
Definition: BasicHandle.h:103