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