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