CMS 3D CMS Logo

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 
16 
17 #include <algorithm>
18 #include <cassert>
19 #include <memory>
20 #include <string>
21 #include <typeinfo>
22 
23 namespace edm {
24  template<typename T>
25  class Wrapper : public WrapperBase {
26  public:
27  typedef T value_type;
28  typedef T wrapped_type; // used with the dictionary to identify Wrappers
30  explicit Wrapper(std::unique_ptr<T> ptr);
31 
32  template<typename... Args>
33  explicit Wrapper( Args&&... );
34  ~Wrapper() override {}
35  T const* product() const {return (present ? &obj : nullptr);}
36  T const* operator->() const {return product();}
37 
38  T& bareProduct() { return obj;}
39 
40  //these are used by FWLite
41  static std::type_info const& productTypeInfo() {return typeid(T);}
42  static std::type_info const& typeInfo() {return typeid(Wrapper<T>);}
43 
44  // the constructor takes ownership of T*
45  Wrapper(T*);
46 
47  //Used by ROOT storage
49 
50 private:
51  bool isPresent_() const override {return present;}
52  std::type_info const& dynamicTypeInfo_() const override {return typeid(T);}
53  std::type_info const& wrappedTypeInfo_() const override {return typeid(Wrapper<T>);}
54 
55  std::type_info const& valueTypeInfo_() const override;
56  std::type_info const& memberTypeInfo_() const override;
57  bool isMergeable_() const override;
58  bool mergeProduct_(WrapperBase const* newProduct) override;
59  bool hasIsProductEqual_() const override;
60  bool isProductEqual_(WrapperBase const* newProduct) const override;
61 
62  void do_fillView(ProductID const& id,
63  std::vector<void const*>& pointers,
64  FillViewHelperVector& helpers) const override;
65  void do_setPtr(std::type_info const& iToType,
66  unsigned long iIndex,
67  void const*& oPtr) const override;
68  void do_fillPtrVector(std::type_info const& iToType,
69  std::vector<unsigned long> const& iIndices,
70  std::vector<void const*>& oPtr) const override;
71 
72  std::shared_ptr<soa::TableExaminerBase> tableExaminer_() const override;
73 
74  private:
75  // We wish to disallow copy construction and assignment.
76  // We make the copy constructor and assignment operator private.
77  Wrapper(Wrapper<T> const& rh) = delete; // disallow copy construction
78  Wrapper<T>& operator=(Wrapper<T> const&) = delete; // disallow assignment
79 
80  bool present;
81  T obj;
82  };
83 
84  template<typename T>
85  Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) :
86  WrapperBase(),
87  present(ptr.get() != nullptr),
88  obj() {
89  if (present) {
90  obj = std::move(*ptr);
91  }
92  }
93 
94  template<typename T>
95  template<typename... Args>
97  WrapperBase(),
98  present(true),
99  obj(std::forward<Args>(args)...) {
100  }
101 
102  template<typename T>
104  WrapperBase(),
105  present(ptr != 0),
106  obj() {
107  std::unique_ptr<T> temp(ptr);
108  if (present) {
109  obj = std::move(*ptr);
110  }
111  }
112 
113  template<typename T>
114  inline
115  std::type_info const& Wrapper<T>::valueTypeInfo_() const {
116  return detail::getValueType<T>()();
117  }
118 
119  template<typename T>
120  inline
121  std::type_info const& Wrapper<T>::memberTypeInfo_() const {
122  return detail::getMemberType<T>()();
123  }
124 
125  template<typename T>
126  inline
129  }
130 
131  template<typename T>
132  inline
133  bool Wrapper<T>::mergeProduct_(WrapperBase const* newProduct) {
134  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
135  assert(wrappedNewProduct != nullptr);
136  return detail::doMergeProduct<T>()(obj, wrappedNewProduct->obj);
137  }
138 
139  template<typename T>
140  inline
143  }
144 
145  template<typename T>
146  inline
147  bool Wrapper<T>::isProductEqual_(WrapperBase const* newProduct) const {
148  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
149  assert(wrappedNewProduct != nullptr);
150  return detail::doIsProductEqual<T>()(obj, wrappedNewProduct->obj);
151  }
152 
153  namespace soa {
154  template<class T>
156  static std::shared_ptr<edm::soa::TableExaminerBase> make(void const*) {
157  return std::shared_ptr<edm::soa::TableExaminerBase>{};
158  }
159  };
160  }
161  template <typename T>
162  inline
163  std::shared_ptr<edm::soa::TableExaminerBase> Wrapper<T>::tableExaminer_() const {
165  }
166 
167 }
168 
169 #include "DataFormats/Common/interface/WrapperView.icc"
170 
171 #endif
T value_type
Definition: Wrapper.h:27
T const * operator->() const
Definition: Wrapper.h:36
bool isProductEqual_(WrapperBase const *newProduct) const override
Definition: Wrapper.h:147
void do_fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndices, std::vector< void const * > &oPtr) const override
static std::shared_ptr< edm::soa::TableExaminerBase > make(void const *)
Definition: Wrapper.h:156
std::type_info const & valueTypeInfo_() const override
Definition: Wrapper.h:115
std::type_info const & wrappedTypeInfo_() const override
Definition: Wrapper.h:53
static std::type_info const & productTypeInfo()
Definition: Wrapper.h:41
#define nullptr
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
std::type_info const & dynamicTypeInfo_() const override
Definition: Wrapper.h:52
bool isPresent_() const override
Definition: Wrapper.h:51
T & bareProduct()
Definition: Wrapper.h:38
std::shared_ptr< soa::TableExaminerBase > tableExaminer_() const override
Definition: Wrapper.h:163
bool hasIsProductEqual_() const override
Definition: Wrapper.h:141
bool present
Definition: Wrapper.h:80
~Wrapper() override
Definition: Wrapper.h:34
void do_fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const override
T const & get(Event const &event, InputTag const &tag)
Definition: Event.h:690
bool isMergeable_() const override
Definition: Wrapper.h:127
T wrapped_type
Definition: Wrapper.h:28
void do_setPtr(std::type_info const &iToType, unsigned long iIndex, void const *&oPtr) const override
T const * product() const
Definition: Wrapper.h:35
std::type_info const & memberTypeInfo_() const override
Definition: Wrapper.h:121
bool mergeProduct_(WrapperBase const *newProduct) override
Definition: Wrapper.h:133
HLT enums.
Wrapper< T > & operator=(Wrapper< T > const &)=delete
long double T
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
def move(src, dest)
Definition: eostools.py:510
static std::type_info const & typeInfo()
Definition: Wrapper.h:42