CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Wrapper.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_Wrapper_h
2 #define DataFormats_Common_Wrapper_h
3 
4 /*----------------------------------------------------------------------
5 
6 Wrapper: A template wrapper around EDProducts to hold the product ID.
7 
8 ----------------------------------------------------------------------*/
9 
15 
16 #include <algorithm>
17 #include <cassert>
18 #include <memory>
19 #include <string>
20 #include <typeinfo>
21 
22 namespace edm {
23  template <typename T>
24  class Wrapper : public WrapperBase {
25  public:
26  typedef T value_type;
27  typedef T wrapped_type; // used with the dictionary to identify Wrappers
29  explicit Wrapper(std::unique_ptr<T> ptr);
30  Wrapper(Wrapper<T> const& rh) = delete; // disallow copy construction
31  Wrapper<T>& operator=(Wrapper<T> const&) = delete; // disallow assignment
32 
33  template <typename... Args>
34  explicit Wrapper(Emplace, Args&&...);
35  ~Wrapper() override {}
36  T const* product() const { return (present ? &obj : nullptr); }
37  T const* operator->() const { return product(); }
38 
39  T& bareProduct() { return obj; }
40 
41  //these are used by FWLite
42  static std::type_info const& productTypeInfo() { return typeid(T); }
43  static std::type_info const& typeInfo() { return typeid(Wrapper<T>); }
44 
45  // the constructor takes ownership of T*
46  Wrapper(T*);
47 
48  //Used by ROOT storage
50 
51  private:
52  bool isPresent_() const override { return present; }
53  std::type_info const& dynamicTypeInfo_() const override { return typeid(T); }
54  std::type_info const& wrappedTypeInfo_() const override { return typeid(Wrapper<T>); }
55 
56  std::type_info const& valueTypeInfo_() const override;
57  std::type_info const& memberTypeInfo_() const override;
58  bool isMergeable_() const override;
59  bool mergeProduct_(WrapperBase const* newProduct) override;
60  bool hasIsProductEqual_() const override;
61  bool isProductEqual_(WrapperBase const* newProduct) const override;
62  bool hasSwap_() const override;
63  void swapProduct_(WrapperBase* newProduct) override;
64 
65  void do_fillView(ProductID const& id,
66  std::vector<void const*>& pointers,
67  FillViewHelperVector& helpers) const override;
68  void do_setPtr(std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const override;
69  void do_fillPtrVector(std::type_info const& iToType,
70  std::vector<unsigned long> const& iIndices,
71  std::vector<void const*>& oPtr) const override;
72 
73  std::shared_ptr<soa::TableExaminerBase> tableExaminer_() const override;
74 
75  private:
76  bool present;
77  T obj;
78  };
79 
80  template <typename T>
81  Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) : WrapperBase(), present(ptr.get() != nullptr), obj() {
82  if (present) {
83  obj = std::move(*ptr);
84  }
85  }
86 
87  template <typename T>
88  template <typename... Args>
89  Wrapper<T>::Wrapper(Emplace, Args&&... args) : WrapperBase(), present(true), obj(std::forward<Args>(args)...) {}
90 
91  template <typename T>
92  Wrapper<T>::Wrapper(T* ptr) : WrapperBase(), present(ptr != 0), obj() {
93  std::unique_ptr<T> temp(ptr);
94  if (present) {
95  obj = std::move(*ptr);
96  }
97  }
98 
99  template <typename T>
100  inline std::type_info const& Wrapper<T>::valueTypeInfo_() const {
101  return detail::getValueType<T>()();
102  }
103 
104  template <typename T>
105  inline std::type_info const& Wrapper<T>::memberTypeInfo_() const {
106  return detail::getMemberType<T>()();
107  }
108 
109  template <typename T>
110  inline bool Wrapper<T>::isMergeable_() const {
112  }
113 
114  template <typename T>
115  inline bool Wrapper<T>::mergeProduct_(WrapperBase const* newProduct) {
116  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
117  assert(wrappedNewProduct != nullptr);
118  return detail::doMergeProduct<T>()(obj, wrappedNewProduct->obj);
119  }
120 
121  template <typename T>
122  inline bool Wrapper<T>::hasIsProductEqual_() const {
124  }
125 
126  template <typename T>
127  inline bool Wrapper<T>::isProductEqual_(WrapperBase const* newProduct) const {
128  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
129  assert(wrappedNewProduct != nullptr);
130  return detail::doIsProductEqual<T>()(obj, wrappedNewProduct->obj);
131  }
132 
133  template <typename T>
134  inline bool Wrapper<T>::hasSwap_() const {
136  }
137 
138  template <typename T>
139  inline void Wrapper<T>::swapProduct_(WrapperBase* newProduct) {
140  Wrapper<T>* wrappedNewProduct = dynamic_cast<Wrapper<T>*>(newProduct);
141  assert(wrappedNewProduct != nullptr);
142  detail::doSwapProduct<T>()(obj, wrappedNewProduct->obj);
143  }
144 
145  namespace soa {
146  template <class T>
148  static std::shared_ptr<edm::soa::TableExaminerBase> make(void const*) {
149  return std::shared_ptr<edm::soa::TableExaminerBase>{};
150  }
151  };
152  } // namespace soa
153  template <typename T>
154  inline std::shared_ptr<edm::soa::TableExaminerBase> Wrapper<T>::tableExaminer_() const {
156  }
157 
158 } // namespace edm
159 
160 #include "DataFormats/Common/interface/WrapperView.icc"
161 
162 #endif
T value_type
Definition: Wrapper.h:26
T const * operator->() const
Definition: Wrapper.h:37
bool hasSwap_() const override
Definition: Wrapper.h:134
static std::shared_ptr< edm::soa::TableExaminerBase > make(void const *)
Definition: Wrapper.h:148
bool isPresent_() const override
Definition: Wrapper.h:52
static std::type_info const & productTypeInfo()
Definition: Wrapper.h:42
#define CMS_CLASS_VERSION(_version_)
assert(be >=bs)
bool hasIsProductEqual_() const override
Definition: Wrapper.h:122
std::type_info const & valueTypeInfo_() const override
Definition: Wrapper.h:100
bool isProductEqual_(WrapperBase const *newProduct) const override
Definition: Wrapper.h:127
T & bareProduct()
Definition: Wrapper.h:39
bool present
Definition: Wrapper.h:76
~Wrapper() override
Definition: Wrapper.h:35
ZVertexSoA * soa
def move
Definition: eostools.py:511
void do_fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndices, std::vector< void const * > &oPtr) const override
T wrapped_type
Definition: Wrapper.h:27
T const * product() const
Definition: Wrapper.h:36
void swapProduct_(WrapperBase *newProduct) override
Definition: Wrapper.h:139
bool mergeProduct_(WrapperBase const *newProduct) override
Definition: Wrapper.h:115
std::type_info const & wrappedTypeInfo_() const override
Definition: Wrapper.h:54
void do_fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const override
Wrapper< T > & operator=(Wrapper< T > const &)=delete
void do_setPtr(std::type_info const &iToType, unsigned long iIndex, void const *&oPtr) const override
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:679
bool isMergeable_() const override
Definition: Wrapper.h:110
std::type_info const & memberTypeInfo_() const override
Definition: Wrapper.h:105
long double T
std::shared_ptr< soa::TableExaminerBase > tableExaminer_() const override
Definition: Wrapper.h:154
std::type_info const & dynamicTypeInfo_() const override
Definition: Wrapper.h:53
static std::type_info const & typeInfo()
Definition: Wrapper.h:43
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector