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.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);
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);
00074 if(!bh.failedToGet()) {
00075 addToGotBranchIDs(*bh.provenance());
00076 return true;
00077 }
00078 }
00079 return false;
00080 }
00081
00082 }