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  ~Wrapper() override {}
32  T const* product() const {return (present ? &obj : nullptr);}
33  T const* operator->() const {return product();}
34 
35  //these are used by FWLite
36  static std::type_info const& productTypeInfo() {return typeid(T);}
37  static std::type_info const& typeInfo() {return typeid(Wrapper<T>);}
38 
39  // the constructor takes ownership of T*
40  Wrapper(T*);
41 
42  //Used by ROOT storage
44 
45 private:
46  bool isPresent_() const override {return present;}
47  std::type_info const& dynamicTypeInfo_() const override {return typeid(T);}
48  std::type_info const& wrappedTypeInfo_() const override {return typeid(Wrapper<T>);}
49 
50  std::type_info const& valueTypeInfo_() const override;
51  std::type_info const& memberTypeInfo_() const override;
52  bool isMergeable_() const override;
53  bool mergeProduct_(WrapperBase const* newProduct) override;
54  bool hasIsProductEqual_() const override;
55  bool isProductEqual_(WrapperBase const* newProduct) const override;
56 
57  void do_fillView(ProductID const& id,
58  std::vector<void const*>& pointers,
59  FillViewHelperVector& helpers) const override;
60  void do_setPtr(std::type_info const& iToType,
61  unsigned long iIndex,
62  void const*& oPtr) const override;
63  void do_fillPtrVector(std::type_info const& iToType,
64  std::vector<unsigned long> const& iIndices,
65  std::vector<void const*>& oPtr) const override;
66 
67  std::shared_ptr<soa::TableExaminerBase> tableExaminer_() const override;
68 
69  private:
70  // We wish to disallow copy construction and assignment.
71  // We make the copy constructor and assignment operator private.
72  Wrapper(Wrapper<T> const& rh) = delete; // disallow copy construction
73  Wrapper<T>& operator=(Wrapper<T> const&) = delete; // disallow assignment
74 
75  bool present;
76  T obj;
77  };
78 
79  template<typename T>
80  Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) :
81  WrapperBase(),
82  present(ptr.get() != nullptr),
83  obj() {
84  if (present) {
85  obj = std::move(*ptr);
86  }
87  }
88 
89  template<typename T>
91  WrapperBase(),
92  present(ptr != 0),
93  obj() {
94  std::unique_ptr<T> temp(ptr);
95  if (present) {
96  obj = std::move(*ptr);
97  }
98  }
99 
100  template<typename T>
101  inline
102  std::type_info const& Wrapper<T>::valueTypeInfo_() const {
103  return detail::getValueType<T>()();
104  }
105 
106  template<typename T>
107  inline
108  std::type_info const& Wrapper<T>::memberTypeInfo_() const {
109  return detail::getMemberType<T>()();
110  }
111 
112  template<typename T>
113  inline
116  }
117 
118  template<typename T>
119  inline
120  bool Wrapper<T>::mergeProduct_(WrapperBase const* newProduct) {
121  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
122  assert(wrappedNewProduct != nullptr);
123  return detail::doMergeProduct<T>()(obj, wrappedNewProduct->obj);
124  }
125 
126  template<typename T>
127  inline
130  }
131 
132  template<typename T>
133  inline
134  bool Wrapper<T>::isProductEqual_(WrapperBase const* newProduct) const {
135  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
136  assert(wrappedNewProduct != nullptr);
137  return detail::doIsProductEqual<T>()(obj, wrappedNewProduct->obj);
138  }
139 
140  namespace soa {
141  template<class T>
143  static std::shared_ptr<edm::soa::TableExaminerBase> make(void const*) {
144  return std::shared_ptr<edm::soa::TableExaminerBase>{};
145  }
146  };
147  }
148  template <typename T>
149  inline
150  std::shared_ptr<edm::soa::TableExaminerBase> Wrapper<T>::tableExaminer_() const {
152  }
153 
154 }
155 
156 #include "DataFormats/Common/interface/WrapperView.icc"
157 
158 #endif
T value_type
Definition: Wrapper.h:27
T const * operator->() const
Definition: Wrapper.h:33
bool isProductEqual_(WrapperBase const *newProduct) const override
Definition: Wrapper.h:134
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:143
std::type_info const & valueTypeInfo_() const override
Definition: Wrapper.h:102
std::type_info const & wrappedTypeInfo_() const override
Definition: Wrapper.h:48
static std::type_info const & productTypeInfo()
Definition: Wrapper.h:36
#define nullptr
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
std::type_info const & dynamicTypeInfo_() const override
Definition: Wrapper.h:47
bool isPresent_() const override
Definition: Wrapper.h:46
std::shared_ptr< soa::TableExaminerBase > tableExaminer_() const override
Definition: Wrapper.h:150
bool hasIsProductEqual_() const override
Definition: Wrapper.h:128
bool present
Definition: Wrapper.h:75
~Wrapper() override
Definition: Wrapper.h:31
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:630
bool isMergeable_() const override
Definition: Wrapper.h:114
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:32
std::type_info const & memberTypeInfo_() const override
Definition: Wrapper.h:108
bool mergeProduct_(WrapperBase const *newProduct) override
Definition: Wrapper.h:120
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:37