CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/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   edm::ObjectWithDict wrap(edm::TypeWithDict(originalWrap.wrappedTypeInfo()), const_cast<void*>(originalWrap.wrapper()));
00034   assert(bool(wrap));
00035   
00036   edm::ObjectWithDict 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 'edm::TypeWithDictdef' 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 = edm::ObjectWithDict(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(edm::TypeNameHandling::Scoped);
00069    if (dataTypeName[dataTypeName.size() -1] == '>')
00070       dataTypeName += " ";
00071    std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
00072 
00073    edm::TypeWithDict wrapperType(edm::TypeWithDict::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 }