CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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()!=result.type()){
00042         std::cerr << "FWGenericObject asked for "<<result.type().name()
00043          <<" but was given a " << product.typeOf().name();
00044     throw edm::Exception(edm::errors::LogicError)<<"FWGenericObject asked for "<<result.type().name()
00045     <<" but was given a "<<product.typeOf().name();
00046   }
00047   
00048   Handle<FWGenericObject> h(product, orig.provenance(), orig.id());
00049   h.swap(result);
00050 }
00051 
00053 template<>
00054 bool
00055 edm::EventBase::getByLabel<FWGenericObject>(edm::InputTag const& tag,
00056                                              Handle<FWGenericObject>& result) const
00057 {
00058    std::string dataTypeName = result.type().name();
00059    if (dataTypeName[dataTypeName.size() -1] == '>')
00060       dataTypeName += " ";
00061    std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
00062 
00063    edm::TypeWithDict wrapperType(edm::TypeWithDict::byName(wrapperName));
00064 
00065    BasicHandle bh = this->getByLabelImpl(wrapperType.typeInfo(),
00066                                          result.type().typeInfo(),
00067                                          tag);
00068    convert_handle(bh, result);  // throws on conversion error
00069    if(bh.failedToGet()) 
00070       return false;
00071    return true;
00072 }
00073 
00074 }