CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
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
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
def move
Definition: eostools.py:511
Handle< T > convert_handle(BasicHandle &&bh) noexcept(true)
Definition: ConvertHandle.h:22
T const * product() const
Definition: Wrapper.h:36
Handle< T > convert_handle_check_type(BasicHandle &&bh)
Definition: ConvertHandle.h:36
#define UNLIKELY(x)
Definition: Likely.h:21
long double T
std::shared_ptr< edm::HandleExceptionFactory const > makeInvalidReferenceException()
static HepMC::HEPEVT_Wrapper wrapper