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 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 Event::getByLabel<GenericObject>(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 
77  template <>
78  bool Event::getByToken<GenericObject>(EDGetToken token, Handle<GenericObject>& result) const {
79  result.clear();
80  BasicHandle bh =
81  provRecorder_.getByToken_(TypeID(result.type().typeInfo()), PRODUCT_TYPE, token, moduleCallingContext_);
82  convert_handle(std::move(bh), result); // throws on conversion error
83  if (UNLIKELY(result.failedToGet())) {
84  return false;
85  }
86  addToGotBranchIDs(*result.provenance());
87  return true;
88  }
89 
90 } // namespace edm
assert(be >=bs)
char const * label
Handle< T > convert_handle(BasicHandle &&bh) noexcept(true)
Definition: ConvertHandle.h:22
HLT enums.
std::type_info const & wrappedTypeInfo() const
Definition: WrapperBase.h:44
auto wrap(F iFunc) -> decltype(iFunc())
#define UNLIKELY(x)
Definition: Likely.h:21
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Provenance const * provenance() const noexcept(true)
Definition: BasicHandle.h:75
def move(src, dest)
Definition: eostools.py:511