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
24  UNLIKELY(bh.failedToGet()) { return Handle<T>(std::move(bh.whyFailedFactory())); }
25  void const* basicWrapper = bh.wrapper();
26  if
27  UNLIKELY(nullptr == basicWrapper) { return Handle<T>{handleimpl::makeInvalidReferenceException()}; }
28  auto wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
29 
30  return Handle<T>(wrapper->product(), bh.provenance());
31  }
32 
33  template <typename T>
35  if
36  UNLIKELY(bh.failedToGet()) { return Handle<T>(std::move(bh.whyFailedFactory())); }
37  void const* basicWrapper = bh.wrapper();
38  if
39  UNLIKELY(basicWrapper == nullptr) { return Handle<T>{handleimpl::makeInvalidReferenceException()}; }
40  if
41  UNLIKELY(!(bh.wrapper()->dynamicTypeInfo() == typeid(T))) {
42  handleimpl::throwConvertTypeError(typeid(T), bh.wrapper()->dynamicTypeInfo());
43  }
44  Wrapper<T> const* wrapper = static_cast<Wrapper<T> const*>(basicWrapper);
45 
46  return Handle<T>(wrapper->product(), bh.provenance());
47  }
48 
49 } // namespace edm
50 
51 #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:34
T
long double T
Definition: Basic3DVectorLD.h:48
BasicHandle.h