CMS 3D CMS Logo

FWGenericHandle.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : FWGenericHandle
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Mar 30 15:48:37 EST 2006
11 //
12 
13 // system include files
14 #include <iostream>
15 
16 // user include files
18 
19 namespace edm {
20 void convert_handle(BasicHandle const& orig,
22 {
23  if(orig.failedToGet()) {
24  result.setWhyFailed(orig.whyFailed());
25  return;
26  }
27 
28  WrapperBase const* originalWrap = orig.wrapper();
29  if(originalWrap == nullptr) {
31  << "edm::BasicHandle has null pointer to Wrapper";
32  }
33 
34  edm::ObjectWithDict wrap(edm::TypeWithDict(originalWrap->wrappedTypeInfo()), const_cast<void*>(static_cast<void const*>(originalWrap)));
35  assert(bool(wrap));
36 
37  edm::ObjectWithDict product(wrap.get("obj"));
38 
39  if(!product){
40  throw edm::Exception(edm::errors::LogicError)<<"FWGenericObject could not find 'obj' member";
41  }
42  if(product.typeOf()!=result.type()){
43  std::cerr << "FWGenericObject asked for "<<result.type().name()
44  <<" but was given a " << product.typeOf().name();
45  throw edm::Exception(edm::errors::LogicError)<<"FWGenericObject asked for "<<result.type().name()
46  <<" but was given a "<<product.typeOf().name();
47  }
48 
49  Handle<FWGenericObject> h(product, orig.provenance(), orig.id());
50  h.swap(result);
51 }
52 
54 template<>
55 bool
56 edm::EventBase::getByLabel<FWGenericObject>(edm::InputTag const& tag,
58 {
59  std::string dataTypeName = result.type().name();
60  if (dataTypeName[dataTypeName.size() -1] == '>')
61  dataTypeName += " ";
62  std::string wrapperName = "edm::Wrapper<" + dataTypeName + ">";
63 
64  edm::TypeWithDict wrapperType(edm::TypeWithDict::byName(wrapperName));
65 
66  BasicHandle bh = this->getByLabelImpl(wrapperType.typeInfo(),
67  result.type().typeInfo(),
68  tag);
69  convert_handle(bh, result); // throws on conversion error
70  if(bh.failedToGet())
71  return false;
72  return true;
73 }
74 
75 }
ProductID id() const
Definition: BasicHandle.h:98
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:102
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void setWhyFailed(std::shared_ptr< cms::Exception > const &iWhyFailed)
edm::TypeWithDict const & type() const
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:82
Provenance const * provenance() const
Definition: BasicHandle.h:94
std::string name() const
WrapperBase const * wrapper() const
Definition: BasicHandle.h:90
std::type_info const & typeInfo() const
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
bool failedToGet() const
Definition: BasicHandle.h:86
std::type_info const & wrappedTypeInfo() const
Definition: WrapperBase.h:45
HLT enums.
auto wrap(F iFunc) -> decltype(iFunc())
ObjectWithDict get(std::string const &memberName) const