File indexing completed on 2024-04-06 12:03:50
0001 #ifndef DataFormats_Common_BasicHandle_h
0002 #define DataFormats_Common_BasicHandle_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #include "DataFormats/Provenance/interface/ProductID.h"
0029 #include "DataFormats/Provenance/interface/Provenance.h"
0030 #include "DataFormats/Common/interface/HandleExceptionFactory.h"
0031
0032 #include <memory>
0033
0034 namespace cms {
0035 class Exception;
0036 }
0037
0038 namespace edm {
0039 class WrapperBase;
0040 template <typename T>
0041 class Wrapper;
0042
0043 class BasicHandle {
0044 public:
0045 BasicHandle() = delete;
0046
0047 BasicHandle(BasicHandle const& h) = default;
0048
0049 BasicHandle(BasicHandle&& h) = default;
0050
0051 BasicHandle(WrapperBase const* iProd, Provenance const* iProv) noexcept(true) : product_(iProd), prov_(iProv) {}
0052
0053
0054 BasicHandle(std::shared_ptr<HandleExceptionFactory const> const& iWhyFailed) noexcept(true)
0055 : product_(), prov_(nullptr), whyFailedFactory_(iWhyFailed) {}
0056
0057 ~BasicHandle() = default;
0058
0059 void swap(BasicHandle& other) noexcept(true) {
0060 using std::swap;
0061 swap(product_, other.product_);
0062 std::swap(prov_, other.prov_);
0063 swap(whyFailedFactory_, other.whyFailedFactory_);
0064 }
0065
0066 BasicHandle& operator=(BasicHandle&& rhs) = default;
0067 BasicHandle& operator=(BasicHandle const& rhs) = default;
0068
0069 bool isValid() const noexcept(true) { return product_ && prov_; }
0070
0071 bool failedToGet() const noexcept(true) { return bool(whyFailedFactory_); }
0072
0073 WrapperBase const* wrapper() const noexcept(true) { return product_; }
0074
0075 Provenance const* provenance() const noexcept(true) { return prov_; }
0076
0077 ProductID id() const noexcept(true) { return prov_->productID(); }
0078
0079 std::shared_ptr<cms::Exception> whyFailed() const { return whyFailedFactory_->make(); }
0080
0081 std::shared_ptr<HandleExceptionFactory const> const& whyFailedFactory() const noexcept(true) {
0082 return whyFailedFactory_;
0083 }
0084
0085 std::shared_ptr<HandleExceptionFactory const>& whyFailedFactory() noexcept(true) { return whyFailedFactory_; }
0086
0087 void clear() noexcept(true) {
0088 product_ = nullptr;
0089 prov_ = nullptr;
0090 whyFailedFactory_.reset();
0091 }
0092
0093 static BasicHandle makeInvalid() { return BasicHandle(true); }
0094
0095 private:
0096
0097 explicit BasicHandle(bool) : product_(nullptr) {}
0098 WrapperBase const* product_;
0099 Provenance const* prov_;
0100 std::shared_ptr<HandleExceptionFactory const> whyFailedFactory_;
0101 };
0102
0103
0104 inline void swap(BasicHandle& a, BasicHandle& b) noexcept(true) { a.swap(b); }
0105 }
0106
0107 #endif