CMS 3D CMS Logo

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 {
20  if (orig.failedToGet()) {
21  result.setWhyFailedFactory(orig.whyFailedFactory());
22  return;
23  }
24  WrapperBase const* originalWrap = orig.wrapper();
25  if (originalWrap == nullptr) {
26  throw Exception(errors::InvalidReference, "NullPointer") << "edm::BasicHandle has null pointer to Wrapper";
27  }
28 
29  ObjectWithDict wrap(originalWrap->wrappedTypeInfo(), const_cast<WrapperBase*>(originalWrap));
30  assert(bool(wrap));
31 
32  ObjectWithDict product(wrap.get("obj"));
33  if (!product) {
34  throw Exception(errors::LogicError) << "GenericObject could not find 'obj' member";
35  }
36  if (product.typeOf() != result.type()) {
38  << "GenericObject asked for " << result.type().name() << " but was given a " << product.typeOf().name();
39  }
40 
41  Handle<GenericObject> h(product, orig.provenance(), orig.id());
42  h.swap(result);
43  }
44 
46  template <>
47  bool edm::Event::getByLabel<GenericObject>(std::string const& label,
48  std::string const& productInstanceName,
50  BasicHandle bh = provRecorder_.getByLabel_(
51  TypeID(result.type().typeInfo()), label, productInstanceName, std::string(), moduleCallingContext_);
52  convert_handle(std::move(bh), result); // throws on conversion error
53  if (!result.failedToGet()) {
54  addToGotBranchIDs(*bh.provenance());
55  return true;
56  }
57  return false;
58  }
59 
60  template <>
61  bool edm::Event::getByLabel<GenericObject>(edm::InputTag const& tag, Handle<GenericObject>& result) const {
62  if (tag.process().empty()) {
63  return this->getByLabel(tag.label(), tag.instance(), result);
64  } else {
65  BasicHandle bh = provRecorder_.getByLabel_(
66  TypeID(result.type().typeInfo()), tag.label(), tag.instance(), tag.process(), moduleCallingContext_);
67  convert_handle(std::move(bh), result); // throws on conversion error
68  if (!result.failedToGet()) {
69  addToGotBranchIDs(*bh.provenance());
70  return true;
71  }
72  }
73  return false;
74  }
75 
76 } // namespace edm
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Provenance const * provenance() const (true)
Definition: BasicHandle.h:86
TypeWithDict const & type() const
char const * label
std::string name() const
Handle< T > convert_handle(BasicHandle &&bh)(true)
Definition: ConvertHandle.h:22
void setWhyFailedFactory(std::shared_ptr< HandleExceptionFactory > const &iWhyFailed)
std::type_info const & wrappedTypeInfo() const
Definition: WrapperBase.h:48
HLT enums.
auto wrap(F iFunc) -> decltype(iFunc())
def move(src, dest)
Definition: eostools.py:511
ObjectWithDict get(std::string const &memberName) const