00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "FWCore/Framework/interface/GenericHandle.h"
00018
00019 namespace edm {
00020 void convert_handle(BasicHandle const& orig,
00021 Handle<GenericObject>& result)
00022 {
00023 using namespace ROOT::Reflex;
00024 if(orig.failedToGet()) {
00025 result.setWhyFailed(orig.whyFailed());
00026 return;
00027 }
00028 EDProduct const* originalWrap = orig.wrapper();
00029 if (originalWrap == 0)
00030 throw edm::Exception(edm::errors::InvalidReference,"NullPointer")
00031 << "edm::BasicHandle has null pointer to Wrapper";
00032
00033
00034
00035 Object edproductObject(Type::ByTypeInfo(typeid(EDProduct)), const_cast<EDProduct*>(originalWrap));
00036 assert(edproductObject != Object());
00037
00038 Object wrap(edproductObject.CastObject(edproductObject.DynamicType()));
00039 assert(wrap != Object());
00040
00041 Object product(wrap.Get("obj"));
00042 if(!product){
00043 throw edm::Exception(edm::errors::LogicError)<<"GenericObject could not find 'obj' member";
00044 }
00045 if(product.TypeOf().IsTypedef()){
00046
00047
00048
00049 product = Object(product.TypeOf().ToType(), product.Address());
00050 assert(!product.TypeOf().IsTypedef());
00051 }
00052
00053 if(product.TypeOf()!=result.type() &&
00054 !product.TypeOf().IsEquivalentTo(result.type()) &&
00055 product.TypeOf().TypeInfo()!= result.type().TypeInfo()){
00056 throw edm::Exception(edm::errors::LogicError)<<"GenericObject asked for "<<result.type().Name()
00057 <<" but was given a "<<product.TypeOf().Name();
00058 }
00059
00060 Handle<GenericObject> h(product, orig.provenance());
00061 h.swap(result);
00062 }
00063
00065 template<>
00066 bool
00067 edm::Event::getByLabel<GenericObject>(std::string const& label,
00068 const std::string& productInstanceName,
00069 Handle<GenericObject>& result) const
00070 {
00071 BasicHandle bh = this->getByLabel_(TypeID(result.type().TypeInfo()), label, productInstanceName);
00072 convert_handle(bh, result);
00073 if(!bh.failedToGet()) {
00074 addToGotBranchIDs(*bh.provenance());
00075 return true;
00076 }
00077 return false;
00078 }
00079
00080 template<>
00081 bool
00082 edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag,
00083 Handle<GenericObject>& result) const
00084 {
00085 if (tag.process().empty()) {
00086 return this->getByLabel(tag.label(), tag.instance(), result);
00087 } else {
00088 BasicHandle bh = this->getByLabel_(TypeID(result.type().TypeInfo()), tag.label(), tag.instance(),tag.process());
00089 convert_handle(bh, result);
00090 if(!bh.failedToGet()) {
00091 addToGotBranchIDs(*bh.provenance());
00092 return true;
00093 }
00094 }
00095 return false;
00096 }
00097
00098 }