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 
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 
31  template <typename... Args>
32  explicit Wrapper(Emplace, Args&&...);
33  ~Wrapper() override {}
34  T const* product() const { return (present ? &obj : nullptr); }
35  T const* operator->() const { return product(); }
36 
37  T& bareProduct() { return obj; }
38 
39  //these are used by FWLite
40  static std::type_info const& productTypeInfo() { return typeid(T); }
41  static std::type_info const& typeInfo() { return typeid(Wrapper<T>); }
42 
43  // the constructor takes ownership of T*
44  Wrapper(T*);
45 
46  //Used by ROOT storage
48 
49  private:
50  bool isPresent_() const override { return present; }
51  std::type_info const& dynamicTypeInfo_() const override { return typeid(T); }
52  std::type_info const& wrappedTypeInfo_() const override { return typeid(Wrapper<T>); }
53 
54  std::type_info const& valueTypeInfo_() const override;
55  std::type_info const& memberTypeInfo_() const override;
56  bool isMergeable_() const override;
57  bool mergeProduct_(WrapperBase const* newProduct) override;
58  bool hasIsProductEqual_() const override;
59  bool isProductEqual_(WrapperBase const* newProduct) const override;
60  bool hasSwap_() const override;
61  void swapProduct_(WrapperBase* newProduct) override;
62 
63  void do_fillView(ProductID const& id,
64  std::vector<void const*>& pointers,
65  FillViewHelperVector& helpers) const override;
66  void do_setPtr(std::type_info const& iToType, unsigned long iIndex, void const*& oPtr) const override;
67  void do_fillPtrVector(std::type_info const& iToType,
68  std::vector<unsigned long> const& iIndices,
69  std::vector<void const*>& oPtr) const override;
70 
71  std::shared_ptr<soa::TableExaminerBase> tableExaminer_() const override;
72 
73  private:
74  // We wish to disallow copy construction and assignment.
75  // We make the copy constructor and assignment operator private.
76  Wrapper(Wrapper<T> const& rh) = delete; // disallow copy construction
77  Wrapper<T>& operator=(Wrapper<T> const&) = delete; // disallow assignment
78 
79  bool present;
80  T obj;
81  };
82 
83  template <typename T>
84  Wrapper<T>::Wrapper(std::unique_ptr<T> ptr) : WrapperBase(), present(ptr.get() != nullptr), obj() {
85  if (present) {
86  obj = std::move(*ptr);
87  }
88  }
89 
90  template <typename T>
91  template <typename... Args>
92  Wrapper<T>::Wrapper(Emplace, Args&&... args) : WrapperBase(), present(true), obj(std::forward<Args>(args)...) {}
93 
94  template <typename T>
95  Wrapper<T>::Wrapper(T* ptr) : WrapperBase(), present(ptr != 0), obj() {
96  std::unique_ptr<T> temp(ptr);
97  if (present) {
98  obj = std::move(*ptr);
99  }
100  }
101 
102  template <typename T>
103  inline std::type_info const& Wrapper<T>::valueTypeInfo_() const {
104  return detail::getValueType<T>()();
105  }
106 
107  template <typename T>
108  inline std::type_info const& Wrapper<T>::memberTypeInfo_() const {
109  return detail::getMemberType<T>()();
110  }
111 
112  template <typename T>
113  inline bool Wrapper<T>::isMergeable_() const {
115  }
116 
117  template <typename T>
118  inline bool Wrapper<T>::mergeProduct_(WrapperBase const* newProduct) {
119  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
120  assert(wrappedNewProduct != nullptr);
121  return detail::doMergeProduct<T>()(obj, wrappedNewProduct->obj);
122  }
123 
124  template <typename T>
125  inline bool Wrapper<T>::hasIsProductEqual_() const {
127  }
128 
129  template <typename T>
130  inline bool Wrapper<T>::isProductEqual_(WrapperBase const* newProduct) const {
131  Wrapper<T> const* wrappedNewProduct = dynamic_cast<Wrapper<T> const*>(newProduct);
132  assert(wrappedNewProduct != nullptr);
133  return detail::doIsProductEqual<T>()(obj, wrappedNewProduct->obj);
134  }
135 
136  template <typename T>
137  inline bool Wrapper<T>::hasSwap_() const {
139  }
140 
141  template <typename T>
142  inline void Wrapper<T>::swapProduct_(WrapperBase* newProduct) {
143  Wrapper<T>* wrappedNewProduct = dynamic_cast<Wrapper<T>*>(newProduct);
144  assert(wrappedNewProduct != nullptr);
145  detail::doSwapProduct<T>()(obj, wrappedNewProduct->obj);
146  }
147 
148  namespace soa {
149  template <class T>
151  static std::shared_ptr<edm::soa::TableExaminerBase> make(void const*) {
152  return std::shared_ptr<edm::soa::TableExaminerBase>{};
153  }
154  };
155  } // namespace soa
156  template <typename T>
157  inline std::shared_ptr<edm::soa::TableExaminerBase> Wrapper<T>::tableExaminer_() const {
159  }
160 
161 } // namespace edm
162 
163 #include "DataFormats/Common/interface/WrapperView.icc"
164 
165 #endif
writedatasetfile.args
args
Definition: writedatasetfile.py:18
edm::FillViewHelperVector
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
Definition: FillViewHelperVector.h:30
Visibility.h
edm::Wrapper::do_fillPtrVector
void do_fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndices, std::vector< void const * > &oPtr) const override
edm::Wrapper::Wrapper
Wrapper()
Definition: Wrapper.h:28
funct::false
false
Definition: Factorize.h:34
edm::Wrapper::wrapped_type
T wrapped_type
Definition: Wrapper.h:27
WrapperDetail.h
edm::Wrapper::wrappedTypeInfo_
std::type_info const & wrappedTypeInfo_() const override
Definition: Wrapper.h:52
edm::Wrapper::memberTypeInfo_
std::type_info const & memberTypeInfo_() const override
Definition: Wrapper.h:108
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Wrapper::mergeProduct_
bool mergeProduct_(WrapperBase const *newProduct) override
Definition: Wrapper.h:118
edm::detail::doIsProductEqual
Definition: WrapperDetail.h:153
cms::cuda::assert
assert(be >=bs)
edm::Wrapper::tableExaminer_
std::shared_ptr< soa::TableExaminerBase > tableExaminer_() const override
Definition: Wrapper.h:157
watchdog.const
const
Definition: watchdog.py:83
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::Wrapper
Definition: Product.h:10
edm::Wrapper::productTypeInfo
static std::type_info const & productTypeInfo()
Definition: Wrapper.h:40
edm::Wrapper::dynamicTypeInfo_
std::type_info const & dynamicTypeInfo_() const override
Definition: Wrapper.h:51
edm::Wrapper::do_fillView
void do_fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const override
edm::Wrapper::product
T const * product() const
Definition: Wrapper.h:34
edm::detail::getHasSwapFunction
Definition: WrapperDetail.h:181
ProductID.h
edm::Wrapper::value_type
T value_type
Definition: Wrapper.h:26
edm::Wrapper::do_setPtr
void do_setPtr(std::type_info const &iToType, unsigned long iIndex, void const *&oPtr) const override
edm::Wrapper::bareProduct
T & bareProduct()
Definition: Wrapper.h:37
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
WrapperBase.h
edm::Wrapper::isProductEqual_
bool isProductEqual_(WrapperBase const *newProduct) const override
Definition: Wrapper.h:130
funct::true
true
Definition: Factorize.h:173
edm::detail::getMemberType
Definition: WrapperDetail.h:59
helpers
Definition: makeCompositeCandidate.h:8
edm::detail::getHasIsProductEqual
Definition: WrapperDetail.h:143
edm::Wrapper::isMergeable_
bool isMergeable_() const override
Definition: Wrapper.h:113
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:669
edm::Wrapper::~Wrapper
~Wrapper() override
Definition: Wrapper.h:33
edm::Wrapper::operator=
Wrapper< T > & operator=(Wrapper< T > const &)=delete
edm::WrapperBase
Definition: WrapperBase.h:23
edm::Wrapper::typeInfo
static std::type_info const & typeInfo()
Definition: Wrapper.h:41
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CMS_CLASS_VERSION.h
edm::detail::getHasMergeFunction
Definition: WrapperDetail.h:105
T
long double T
Definition: Basic3DVectorLD.h:48
edm::Wrapper::hasSwap_
bool hasSwap_() const override
Definition: Wrapper.h:137
edm::Wrapper::swapProduct_
void swapProduct_(WrapperBase *newProduct) override
Definition: Wrapper.h:142
edm::Wrapper::isPresent_
bool isPresent_() const override
Definition: Wrapper.h:50
edm::detail::doSwapProduct
Definition: WrapperDetail.h:191
edm::Wrapper::present
bool present
Definition: Wrapper.h:79
edm::detail::getValueType
Definition: WrapperDetail.h:37
edm::detail::doMergeProduct
Definition: WrapperDetail.h:115
edm::Wrapper::hasIsProductEqual_
bool hasIsProductEqual_() const override
Definition: Wrapper.h:125
edm::Wrapper::operator->
T const * operator->() const
Definition: Wrapper.h:35
edm::Wrapper::obj
T obj
Definition: Wrapper.h:80
edm::Wrapper::valueTypeInfo_
std::type_info const & valueTypeInfo_() const override
Definition: Wrapper.h:103
edm::soa::MakeTableExaminer
Definition: Wrapper.h:150
edm::ProductID
Definition: ProductID.h:27
edm::soa::MakeTableExaminer::make
static std::shared_ptr< edm::soa::TableExaminerBase > make(void const *)
Definition: Wrapper.h:151
edm::WrapperBase::Emplace
Definition: WrapperBase.h:26