CMS 3D CMS Logo

ConvertHandle.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_ConvertHandle_h
2 #define DataFormats_Common_ConvertHandle_h
3 
8 
9 #include <typeinfo>
10 #include <algorithm>
11 #include <memory>
12 
13 namespace edm {
14 
15  namespace handleimpl {
16  void throwConvertTypeError(std::type_info const& expected, std::type_info const& actual);
17  std::shared_ptr<edm::HandleExceptionFactory const> makeInvalidReferenceException();
18  } // namespace handleimpl
19 
20  // Convert from handle-to-void to handle-to-T
21  template <typename T>
22  Handle<T> convert_handle(BasicHandle&& bh) noexcept(true) {
23  if UNLIKELY (bh.failedToGet()) {
24  return Handle<T>(std::move(bh.whyFailedFactory()));
25  }
26  void const* basicWrapper = bh.wrapper();
27  if UNLIKELY (nullptr == basicWrapper) {
29  }
30  auto wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
31 
32  return Handle<T>(wrapper->product(), bh.provenance());
33  }
34 
35  template <typename T>
37  if UNLIKELY (bh.failedToGet()) {
38  return Handle<T>(std::move(bh.whyFailedFactory()));
39  }
40  void const* basicWrapper = bh.wrapper();
41  if UNLIKELY (basicWrapper == nullptr) {
43  }
44  if UNLIKELY (!(bh.wrapper()->dynamicTypeInfo() == typeid(T))) {
45  handleimpl::throwConvertTypeError(typeid(T), bh.wrapper()->dynamicTypeInfo());
46  }
47  Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
48 
49  return Handle<T>(wrapper->product(), bh.provenance());
50  }
51 
52 } // namespace edm
53 
54 #endif
Likely.h
Handle.h
edm::BasicHandle
Definition: BasicHandle.h:43
edm
HLT enums.
Definition: AlignableModifier.h:19
wrapper
static HepMC::HEPEVT_Wrapper wrapper
Definition: BeamHaloProducer.cc:47
watchdog.const
const
Definition: watchdog.py:83
edm::Handle
Definition: AssociativeIterator.h:50
edm::convert_handle
Handle< T > convert_handle(BasicHandle &&bh) noexcept(true)
Definition: ConvertHandle.h:22
edm::Wrapper
Definition: Product.h:10
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::handleimpl::throwConvertTypeError
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
Definition: ConvertHandle.cc:17
edm::handleimpl::makeInvalidReferenceException
std::shared_ptr< edm::HandleExceptionFactory const > makeInvalidReferenceException()
Definition: ConvertHandle.cc:15
Wrapper.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::convert_handle_check_type
Handle< T > convert_handle_check_type(BasicHandle &&bh)
Definition: ConvertHandle.h:36
T
long double T
Definition: Basic3DVectorLD.h:48
BasicHandle.h