Go to the documentation of this file.00001 #ifndef FWCore_Framework_GenericHandle_h
00002 #define FWCore_Framework_GenericHandle_h
00003
00004
00005
00006
00007
00024
00025
00026
00027
00028
00029
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Utilities/interface/ObjectWithDict.h"
00032 #include "FWCore/Utilities/interface/TypeWithDict.h"
00033
00034
00035 #include <string>
00036
00037
00038 namespace edm {
00040 struct GenericObject {
00041 };
00042
00043 template<>
00044 class Handle<GenericObject> {
00045 public:
00047 Handle(std::string const& iName) :
00048 type_(TypeWithDict::byName(iName)), prod_(), prov_(nullptr) {
00049 if(!bool(type_)) {
00050 Exception::throwThis(errors::NotFound,
00051 "Handle<GenericObject> told to use uknown type '",
00052 iName.c_str(),
00053 "'.\n Please check spelling or that a module uses this type in the job.");
00054 }
00055 }
00056
00058 Handle(TypeWithDict const& iType) :
00059 type_(iType), prod_(), prov_(nullptr) {
00060 if(!bool(iType)) {
00061 Exception::throwThis(errors::NotFound, "Handle<GenericObject> given an invalid type");
00062 }
00063 }
00064
00065 Handle(Handle<GenericObject> const& h):
00066 type_(h.type_),
00067 prod_(h.prod_),
00068 prov_(h.prov_),
00069 whyFailed_(h.whyFailed_) {
00070 }
00071
00072 Handle(ObjectWithDict const& prod, Provenance const* prov, ProductID const&):
00073 type_(prod.typeOf()),
00074 prod_(prod),
00075 prov_(prov) {
00076 assert(prod_);
00077 assert(prov_);
00078 }
00079
00080
00081
00082 void swap(Handle<GenericObject>& other) {
00083
00084 using std::swap;
00085 swap(type_, other.type_);
00086 std::swap(prod_, other.prod_);
00087 swap(prov_, other.prov_);
00088 swap(whyFailed_, other.whyFailed_);
00089 }
00090
00091
00092 Handle<GenericObject>& operator=(Handle<GenericObject> const& rhs) {
00093 Handle<GenericObject> temp(rhs);
00094 this->swap(temp);
00095 return *this;
00096 }
00097
00098 bool isValid() const {
00099 return prod_ && 0!= prov_;
00100 }
00101
00102 bool failedToGet() const {
00103 return 0 != whyFailed_.get();
00104 }
00105 ObjectWithDict const* product() const {
00106 if(this->failedToGet()) {
00107 whyFailed_->raise();
00108 }
00109 return &prod_;
00110 }
00111 ObjectWithDict const* operator->() const {return this->product();}
00112 ObjectWithDict const& operator*() const {return *(this->product());}
00113
00114 TypeWithDict const& type() const {return type_;}
00115 Provenance const* provenance() const {return prov_;}
00116
00117 ProductID id() const {return prov_->productID();}
00118
00119 void clear() { prov_ = 0; whyFailed_.reset();}
00120
00121 void setWhyFailed(boost::shared_ptr<cms::Exception> const& iWhyFailed) {
00122 whyFailed_=iWhyFailed;
00123 }
00124 private:
00125 TypeWithDict type_;
00126 ObjectWithDict prod_;
00127 Provenance const* prov_;
00128 boost::shared_ptr<cms::Exception> whyFailed_;
00129
00130 };
00131
00132 typedef Handle<GenericObject> GenericHandle;
00133
00135 void convert_handle(BasicHandle const& orig,
00136 Handle<GenericObject>& result);
00137
00138
00140 template<>
00141 bool
00142 edm::Event::getByLabel<GenericObject>(std::string const& label,
00143 std::string const& productInstanceName,
00144 Handle<GenericObject>& result) const;
00145
00146 template <>
00147 bool
00148 edm::Event::getByLabel(edm::InputTag const& tag, Handle<GenericObject>& result) const;
00149
00150 }
00151 #endif