CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
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 #ifndef __GCCXML__
31  explicit Wrapper(std::unique_ptr<T> ptr);
32 #endif
33  virtual ~Wrapper() {}
34  T const* product() const {return (present ? &obj : 0);}
35  T const* operator->() const {return product();}
36 
37  //these are used by FWLite
38  static std::type_info const& productTypeInfo() {return typeid(T);}
39  static std::type_info const& typeInfo() {return typeid(Wrapper<T>);}
40 
41  // the constructor takes ownership of T*
42  Wrapper(T*);
43 
44  //Used by ROOT storage
46 
47 private:
48  virtual bool isPresent_() const GCC11_OVERRIDE {return present;}
49  virtual std::type_info const& dynamicTypeInfo_() const GCC11_OVERRIDE {return typeid(T);}
50  virtual std::type_info const& wrappedTypeInfo_() const GCC11_OVERRIDE {return typeid(Wrapper<T>);}
51 
52  virtual std::type_info const& valueTypeInfo_() const GCC11_OVERRIDE;
53  virtual std::type_info const& memberTypeInfo_() const GCC11_OVERRIDE;
54 #ifndef __GCCXML__
55  virtual bool isMergeable_() const GCC11_OVERRIDE;
56  virtual bool mergeProduct_(WrapperBase const* newProduct) GCC11_OVERRIDE;
57  virtual bool hasIsProductEqual_() const GCC11_OVERRIDE;
58  virtual bool isProductEqual_(WrapperBase const* newProduct) const GCC11_OVERRIDE;
59 #endif
60 
61  virtual void do_fillView(ProductID const& id,
62  std::vector<void const*>& pointers,
63  FillViewHelperVector& helpers) const GCC11_OVERRIDE;
64  virtual void do_setPtr(std::type_info const& iToType,
65  unsigned long iIndex,
66  void const*& oPtr) const GCC11_OVERRIDE;
67  virtual void do_fillPtrVector(std::type_info const& iToType,
68  std::vector<unsigned long> const& iIndices,
69  std::vector<void const*>& oPtr) const GCC11_OVERRIDE;
70 
71  private:
72  // We wish to disallow copy construction and assignment.
73  // We make the copy constructor and assignment operator private.
74  Wrapper(Wrapper<T> const& rh); // disallow copy construction
75  Wrapper<T>& operator=(Wrapper<T> const&); // disallow assignment
76 
77  bool present;
78  T obj;
79  };
80 
81 #ifndef __GCCXML__
82  template<typename T>
83  inline
84  void swap_or_assign(T& a, T& b) {
86  }
87 
88  template<typename T>
89  Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) :
90  WrapperBase(),
91  present(ptr.get() != 0),
92  obj() {
93  if (present) {
94  // The following will call swap if T has such a function,
95  // and use assignment if T has no such function.
96  swap_or_assign(obj, *ptr);
97  }
98  }
99 
100  template<typename T>
102  WrapperBase(),
103  present(ptr != 0),
104  obj() {
105  std::unique_ptr<T> temp(ptr);
106  if (present) {
107  // The following will call swap if T has such a function,
108  // and use assignment if T has no such function.
109  swap_or_assign(obj, *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 #endif
153 }
154 
155 #include "DataFormats/Common/interface/WrapperView.icc"
156 
157 #endif
virtual std::type_info const & valueTypeInfo_() const
Definition: Wrapper.h:115
T value_type
Definition: Wrapper.h:27
T const * operator->() const
Definition: Wrapper.h:35
#define GCC11_OVERRIDE
assert(m_qm.get())
virtual std::type_info const & memberTypeInfo_() const
Definition: Wrapper.h:121
virtual bool isProductEqual_(WrapperBase const *newProduct) const
Definition: Wrapper.h:147
virtual bool isMergeable_() const
Definition: Wrapper.h:127
void swap_or_assign(T &a, T &b)
Definition: Wrapper.h:84
static std::type_info const & productTypeInfo()
Definition: Wrapper.h:38
virtual void do_fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndices, std::vector< void const * > &oPtr) const
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
virtual bool mergeProduct_(WrapperBase const *newProduct)
Definition: Wrapper.h:133
virtual bool hasIsProductEqual_() const
Definition: Wrapper.h:141
virtual std::type_info const & dynamicTypeInfo_() const
Definition: Wrapper.h:49
bool present
Definition: Wrapper.h:77
virtual bool isPresent_() const
Definition: Wrapper.h:48
virtual ~Wrapper()
Definition: Wrapper.h:33
virtual void do_setPtr(std::type_info const &iToType, unsigned long iIndex, void const *&oPtr) const
#define private
Definition: FWEveView.cc:22
T wrapped_type
Definition: Wrapper.h:28
T const * product() const
Definition: Wrapper.h:34
double b
Definition: hdecay.h:120
virtual std::type_info const & wrappedTypeInfo_() const
Definition: Wrapper.h:50
string const
Definition: compareJSON.py:14
double a
Definition: hdecay.h:121
virtual void do_fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const
volatile std::atomic< bool > shutdown_flag false
long double T
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
Wrapper< T > & operator=(Wrapper< T > const &)
T get(const Candidate &c)
Definition: component.h:55
static std::type_info const & typeInfo()
Definition: Wrapper.h:39