Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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.isTypedef()){
00040
00041
00042
00043 product = ObjectWithDict(product.typeOf().toType(), product.address());
00044 assert(!product.isTypedef());
00045 }
00046
00047 if(product.typeOf() != result.type() &&
00048 !product.typeOf().isEquivalentTo(result.type()) &&
00049 product.typeOf().typeInfo() != result.type().typeInfo()){
00050 throw Exception(errors::LogicError) << "GenericObject asked for " << result.type().name()
00051 << " but was given a " << product.typeOf().name();
00052 }
00053
00054 Handle<GenericObject> h(product, orig.provenance(), orig.id());
00055 h.swap(result);
00056 }
00057
00059 template<>
00060 bool
00061 edm::Event::getByLabel<GenericObject>(std::string const& label,
00062 std::string const& productInstanceName,
00063 Handle<GenericObject>& result) const
00064 {
00065 BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), label, productInstanceName, std::string());
00066 convert_handle(bh, result);
00067 if(!bh.failedToGet()) {
00068 addToGotBranchIDs(*bh.provenance());
00069 return true;
00070 }
00071 return false;
00072 }
00073
00074 template<>
00075 bool
00076 edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag,
00077 Handle<GenericObject>& result) const
00078 {
00079 if (tag.process().empty()) {
00080 return this->getByLabel(tag.label(), tag.instance(), result);
00081 } else {
00082 BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), tag.label(), tag.instance(),tag.process());
00083 convert_handle(bh, result);
00084 if(!bh.failedToGet()) {
00085 addToGotBranchIDs(*bh.provenance());
00086 return true;
00087 }
00088 }
00089 return false;
00090 }
00091
00092 }