Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "Fireworks/Core/src/FWGenericHandle.h"
00017
00018 namespace edm {
00019 void convert_handle(BasicHandle const& orig,
00020 Handle<FWGenericObject>& result)
00021 {
00022 if(orig.failedToGet()) {
00023 result.setWhyFailed(orig.whyFailed());
00024 return;
00025 }
00026
00027 WrapperHolder originalWrap = orig.wrapperHolder();
00028 if(!originalWrap.isValid()) {
00029 throw edm::Exception(edm::errors::InvalidReference,"NullPointer")
00030 << "edm::BasicHandle has null pointer to Wrapper";
00031 }
00032
00033 Reflex::Object wrap(Reflex::Type::ByTypeInfo(originalWrap.wrappedTypeInfo()), const_cast<void*>(originalWrap.wrapper()));
00034 assert(wrap != Reflex::Object());
00035
00036 Reflex::Object product(wrap.Get("obj"));
00037
00038 if(!product){
00039 throw edm::Exception(edm::errors::LogicError)<<"FWGenericObject could not find 'obj' member";
00040 }
00041 if(product.TypeOf().IsTypedef()){
00042
00043
00044
00045 product = Reflex::Object(product.TypeOf().ToType(), product.Address());
00046 assert(!product.TypeOf().IsTypedef());
00047 }
00048
00049 if(product.TypeOf()!=result.type() &&
00050 !product.TypeOf().IsEquivalentTo(result.type()) &&
00051 product.TypeOf().TypeInfo()!= result.type().TypeInfo()){
00052 std::cerr << "FWGenericObject asked for "<<result.type().Name()
00053 <<" but was given a " << product.TypeOf().Name();
00054 throw edm::Exception(edm::errors::LogicError)<<"FWGenericObject asked for "<<result.type().Name()
00055 <<" but was given a "<<product.TypeOf().Name();
00056 }
00057
00058 Handle<FWGenericObject> h(product, orig.provenance(), orig.id());
00059 h.swap(result);
00060 }
00061
00063 template<>
00064 bool
00065 edm::EventBase::getByLabel<FWGenericObject>(edm::InputTag const& tag,
00066 Handle<FWGenericObject>& result) const
00067 {
00068 std::string dataTypeName = result.type().Name(Reflex::SCOPED);
00069 if (dataTypeName[dataTypeName.size() -1] == '>')
00070 dataTypeName += " ";
00071 std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
00072
00073 Reflex::Type wrapperType = Reflex::Type::ByName(wrapperName);
00074
00075 BasicHandle bh = this->getByLabelImpl(wrapperType.TypeInfo(),
00076 result.type().TypeInfo(),
00077 tag);
00078 convert_handle(bh, result);
00079 if(bh.failedToGet())
00080 return false;
00081 return true;
00082 }
00083
00084 }