CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GenericHandle.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Class : GenericHandle
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 
15 // user include files
17 
18 namespace edm {
21 {
22  if(orig.failedToGet()) {
23  result.setWhyFailedFactory(orig.whyFailedFactory());
24  return;
25  }
26  WrapperBase const* originalWrap = orig.wrapper();
27  if(originalWrap == nullptr) {
28  throw Exception(errors::InvalidReference,"NullPointer")
29  << "edm::BasicHandle has null pointer to Wrapper";
30  }
31 
32  ObjectWithDict wrap(originalWrap->wrappedTypeInfo(), const_cast<WrapperBase*>(originalWrap));
33  assert(bool(wrap));
34 
35  ObjectWithDict product(wrap.get("obj"));
36  if(!product){
37  throw Exception(errors::LogicError)<<"GenericObject could not find 'obj' member";
38  }
39  if(product.typeOf() != result.type()) {
40  throw Exception(errors::LogicError) << "GenericObject asked for " << result.type().name()
41  << " but was given a " << product.typeOf().name();
42  }
43 
44  Handle<GenericObject> h(product, orig.provenance(), orig.id());
45  h.swap(result);
46 }
47 
49 template<>
50 bool
51 edm::Event::getByLabel<GenericObject>(std::string const& label,
52  std::string const& productInstanceName,
54 {
55  BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), label, productInstanceName, std::string(), moduleCallingContext_);
56  convert_handle(std::move(bh), result); // throws on conversion error
57  if(!result.failedToGet()) {
58  addToGotBranchIDs(*bh.provenance());
59  return true;
60  }
61  return false;
62 }
63 
64 template<>
65 bool
66 edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag,
68 {
69  if (tag.process().empty()) {
70  return this->getByLabel(tag.label(), tag.instance(), result);
71  } else {
72  BasicHandle bh = provRecorder_.getByLabel_(TypeID(result.type().typeInfo()), tag.label(), tag.instance(),tag.process(), moduleCallingContext_);
73  convert_handle(std::move(bh), result); // throws on conversion error
74  if(!result.failedToGet()) {
75  addToGotBranchIDs(*bh.provenance());
76  return true;
77  }
78  }
79  return false;
80 }
81 
82 }
TypeWithDict const & type() const
Provenance const * provenance() const
Definition: BasicHandle.h:103
std::string name() const
tuple result
Definition: query.py:137
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void convert_handle(BasicHandle &&bh, Handle< T > &result)
Definition: ConvertHandle.h:20
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
std::type_info const & wrappedTypeInfo() const
Definition: WrapperBase.h:38
auto wrap(F iFunc) -> decltype(iFunc())
ObjectWithDict get(std::string const &memberName) const