CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Fireworks/Core/src/FWGenericHandle.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     FWGenericHandle
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Thu Mar 30 15:48:37 EST 2006
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
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     //For a 'Reflex::Typedef' the 'ToType' method returns the actual type
00043     // this is needed since you are now allowed to 'invoke' methods of a 'Typedef'
00044     // only for a 'real' class
00045     product = Reflex::Object(product.TypeOf().ToType(), product.Address());
00046     assert(!product.TypeOf().IsTypedef());
00047   }
00048   // NOTE: comparing on type doesn't seem to always work! The problem appears to be if we have a typedef
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(ROOT::Reflex::SCOPED);
00069    if (dataTypeName[dataTypeName.size() -1] == '>')
00070       dataTypeName += " ";
00071    std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
00072 
00073    ROOT::Reflex::Type wrapperType = ROOT::Reflex::Type::ByName(wrapperName);
00074 
00075    BasicHandle bh = this->getByLabelImpl(wrapperType.TypeInfo(),
00076                                          result.type().TypeInfo(),
00077                                          tag);
00078    convert_handle(bh, result);  // throws on conversion error
00079    if(bh.failedToGet()) 
00080       return false;
00081    return true;
00082 }
00083 
00084 }