File indexing completed on 2024-04-06 12:11:38
0001 #ifndef Fireworks_FWGenericHandle_h
0002 #define Fireworks_FWGenericHandle_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
0029
0030
0031
0032
0033
0034 #include <string>
0035
0036
0037 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0038 #include "FWCore/Common/interface/EventBase.h"
0039 #include "DataFormats/Common/interface/Handle.h"
0040 #include "DataFormats/Common/interface/ConvertHandle.h"
0041
0042
0043 namespace edm {
0044
0045 struct FWGenericObject {};
0046
0047 template <>
0048 class Handle<FWGenericObject> {
0049 public:
0050
0051 Handle(std::string const& iName) : type_(edm::TypeWithDict::byName(iName)), prod_(), prov_(nullptr) {
0052 if (type_ == edm::TypeWithDict()) {
0053 Exception::throwThis(errors::NotFound,
0054 "Handle<FWGenericObject> told to use uknown type '",
0055 iName.c_str(),
0056 "'.\n Please check spelling or that a module uses this type in the job.");
0057 }
0058 }
0059
0060
0061 Handle(edm::TypeWithDict const& iType) : type_(iType), prod_(), prov_(nullptr) {
0062 if (iType == edm::TypeWithDict()) {
0063 Exception::throwThis(errors::NotFound, "Handle<FWGenericObject> given an invalid edm::TypeWithDict");
0064 }
0065 }
0066
0067 Handle(Handle<FWGenericObject> const& h)
0068 : type_(h.type_), prod_(h.prod_), prov_(h.prov_), whyFailed_(h.whyFailed_) {}
0069
0070 Handle(edm::ObjectWithDict const& prod, Provenance const* prov, ProductID const& pid)
0071 : type_(prod.typeOf()), prod_(prod), prov_(prov) {
0072 assert(prod_);
0073 assert(prov_);
0074
0075 }
0076
0077
0078
0079 void swap(Handle<FWGenericObject>& other) {
0080
0081 using std::swap;
0082 swap(type_, other.type_);
0083 std::swap(prod_, other.prod_);
0084 swap(prov_, other.prov_);
0085 swap(whyFailed_, other.whyFailed_);
0086 }
0087
0088 Handle<FWGenericObject>& operator=(Handle<FWGenericObject> const& rhs) {
0089 Handle<FWGenericObject> temp(rhs);
0090 this->swap(temp);
0091 return *this;
0092 }
0093
0094 bool isValid() const { return prod_ && nullptr != prov_; }
0095
0096 bool failedToGet() const { return nullptr != whyFailed_.get(); }
0097 edm::ObjectWithDict const* product() const {
0098 if (this->failedToGet()) {
0099 whyFailed_->raise();
0100 }
0101 return &prod_;
0102 }
0103 edm::ObjectWithDict const* operator->() const { return this->product(); }
0104 edm::ObjectWithDict const& operator*() const { return *(this->product()); }
0105
0106 edm::TypeWithDict const& type() const { return type_; }
0107 Provenance const* provenance() const { return prov_; }
0108
0109 ProductID id() const { return prov_->productID(); }
0110
0111 void clear() {
0112 prov_ = nullptr;
0113 whyFailed_.reset();
0114 }
0115
0116 void setWhyFailed(std::shared_ptr<cms::Exception> const& iWhyFailed) { whyFailed_ = iWhyFailed; }
0117
0118 private:
0119 edm::TypeWithDict type_;
0120 edm::ObjectWithDict prod_;
0121 Provenance const* prov_;
0122 std::shared_ptr<cms::Exception> whyFailed_;
0123 };
0124
0125 typedef Handle<FWGenericObject> FWGenericHandle;
0126
0127
0128 void convert_handle(BasicHandle const& orig, Handle<FWGenericObject>& result);
0129
0130
0131 template <>
0132 bool edm::EventBase::getByLabel(edm::InputTag const& tag, Handle<FWGenericObject>& result) const;
0133
0134 }
0135 #endif