Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:38

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     FWGenericHandle
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Thu Mar 30 15:48:37 EST 2006
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 
0016 // user include files
0017 #include "Fireworks/Core/src/FWGenericHandle.h"
0018 
0019 namespace edm {
0020   void convert_handle(BasicHandle const& orig, Handle<FWGenericObject>& result) {
0021     if (orig.failedToGet()) {
0022       result.setWhyFailed(orig.whyFailed());
0023       return;
0024     }
0025 
0026     WrapperBase const* originalWrap = orig.wrapper();
0027     if (originalWrap == nullptr) {
0028       throw edm::Exception(edm::errors::InvalidReference, "NullPointer")
0029           << "edm::BasicHandle has null pointer to Wrapper";
0030     }
0031 
0032     edm::ObjectWithDict wrap(edm::TypeWithDict(originalWrap->wrappedTypeInfo()),
0033                              const_cast<void*>(static_cast<void const*>(originalWrap)));
0034     assert(bool(wrap));
0035 
0036     edm::ObjectWithDict product(wrap.get("obj"));
0037 
0038     if (!product) {
0039       throw edm::Exception(edm::errors::LogicError) << "FWGenericObject could not find 'obj' member";
0040     }
0041     if (product.typeOf() != result.type()) {
0042       std::cerr << "FWGenericObject asked for " << result.type().name() << " but was given a "
0043                 << product.typeOf().name();
0044       throw edm::Exception(edm::errors::LogicError)
0045           << "FWGenericObject asked for " << result.type().name() << " but was given a " << product.typeOf().name();
0046     }
0047 
0048     Handle<FWGenericObject> h(product, orig.provenance(), orig.id());
0049     h.swap(result);
0050   }
0051 
0052   ///Specialize the getByLabel method to work with a Handle<FWGenericObject>
0053   template <>
0054   bool edm::EventBase::getByLabel<FWGenericObject>(edm::InputTag const& tag, Handle<FWGenericObject>& result) const {
0055     std::string dataTypeName = result.type().name();
0056     if (dataTypeName[dataTypeName.size() - 1] == '>')
0057       dataTypeName += " ";
0058     std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
0059 
0060     edm::TypeWithDict wrapperType(edm::TypeWithDict::byName(wrapperName));
0061 
0062     BasicHandle bh = this->getByLabelImpl(wrapperType.typeInfo(), result.type().typeInfo(), tag);
0063     convert_handle(bh, result);  // throws on conversion error
0064     if (bh.failedToGet())
0065       return false;
0066     return true;
0067   }
0068 
0069 }  // namespace edm