CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/FWCore/Framework/src/GenericHandle.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     GenericHandle
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 "FWCore/Framework/interface/GenericHandle.h"
00017 
00018 namespace edm {
00019 void convert_handle(BasicHandle const& orig,
00020                     Handle<GenericObject>& result)
00021 {
00022   if(orig.failedToGet()) {
00023     result.setWhyFailed(orig.whyFailed());
00024     return;
00025   }
00026   WrapperHolder originalWrap = orig.wrapperHolder();
00027   if(!originalWrap.isValid()) {
00028     throw Exception(errors::InvalidReference,"NullPointer")
00029       << "edm::BasicHandle has null pointer to Wrapper";
00030   }
00031   
00032   ObjectWithDict wrap(originalWrap.wrappedTypeInfo(), const_cast<void*>(originalWrap.wrapper()));
00033   assert(bool(wrap));
00034   
00035   ObjectWithDict product(wrap.get("obj"));
00036   if(!product){
00037     throw Exception(errors::LogicError)<<"GenericObject could not find 'obj' member";
00038   }
00039   if(product.typeOf() != result.type()) {
00040     throw Exception(errors::LogicError) << "GenericObject asked for " << result.type().name()
00041       << " but was given a " << product.typeOf().name();
00042   }
00043   
00044   Handle<GenericObject> h(product, orig.provenance(), orig.id());
00045   h.swap(result);
00046 }
00047 
00049 template<>
00050 bool
00051 edm::Event::getByLabel<GenericObject>(std::string const& label,
00052                                       std::string const& productInstanceName,
00053                                       Handle<GenericObject>& result) const
00054 {
00055   BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), label, productInstanceName, std::string());
00056   convert_handle(bh, result);  // throws on conversion error
00057   if(!bh.failedToGet()) {
00058     addToGotBranchIDs(*bh.provenance());
00059     return true;
00060   }
00061   return false;
00062 }
00063 
00064 template<>
00065 bool
00066 edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag,
00067                                              Handle<GenericObject>& result) const
00068 {
00069   if (tag.process().empty()) {
00070     return this->getByLabel(tag.label(), tag.instance(), result);
00071   } else {
00072     BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), tag.label(), tag.instance(),tag.process());
00073     convert_handle(bh, result);  // throws on conversion error
00074     if(!bh.failedToGet()) {
00075       addToGotBranchIDs(*bh.provenance());
00076       return true;
00077     }
00078   }
00079   return false;
00080 }
00081 
00082 }