CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:106
std::shared_ptr< cms::Exception > whyFailed() const
Definition: BasicHandle.h:110
void setWhyFailed(std::shared_ptr< cms::Exception > const &iWhyFailed)
edm::TypeWithDict const & type() const
assert(m_qm.get())
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
Provenance const * provenance() const
Definition: BasicHandle.h:102
std::string name() const
tuple result
Definition: query.py:137
WrapperBase const * wrapper() const
Definition: BasicHandle.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::type_info const & typeInfo() const
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
bool failedToGet() const
Definition: BasicHandle.h:94
std::type_info const & wrappedTypeInfo() const
Definition: WrapperBase.h:40
auto wrap(F iFunc) -> decltype(iFunc())
ObjectWithDict get(std::string const &memberName) const