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  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
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:29
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:54
edm::Wrapper::memberTypeInfo_
std::type_info const & memberTypeInfo_() const override
Definition: Wrapper.h:105
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Wrapper::mergeProduct_
bool mergeProduct_(WrapperBase const *newProduct) override
Definition: Wrapper.h:115
edm::detail::doIsProductEqual
Definition: WrapperDetail.h:153
cms::cuda::assert
assert(be >=bs)
gpuVertexFinder::soa
ZVertexSoA * soa
Definition: gpuVertexFinder.cc:24
edm::Wrapper::tableExaminer_
std::shared_ptr< soa::TableExaminerBase > tableExaminer_() const override
Definition: Wrapper.h:154
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:42
edm::Wrapper::dynamicTypeInfo_
std::type_info const & dynamicTypeInfo_() const override
Definition: Wrapper.h:53
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:36
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:39
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:127
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:110
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:675
edm::Wrapper::~Wrapper
~Wrapper() override
Definition: Wrapper.h:35
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:43
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:134
edm::Wrapper::swapProduct_
void swapProduct_(WrapperBase *newProduct) override
Definition: Wrapper.h:139
edm::Wrapper::isPresent_
bool isPresent_() const override
Definition: Wrapper.h:52
edm::detail::doSwapProduct
Definition: WrapperDetail.h:191
edm::Wrapper::present
bool present
Definition: Wrapper.h:76
edm::detail::getValueType
Definition: WrapperDetail.h:37
edm::detail::doMergeProduct
Definition: WrapperDetail.h:115
edm::Wrapper::hasIsProductEqual_
bool hasIsProductEqual_() const override
Definition: Wrapper.h:122
edm::Wrapper::operator->
T const * operator->() const
Definition: Wrapper.h:37
edm::Wrapper::obj
T obj
Definition: Wrapper.h:77
edm::Wrapper::valueTypeInfo_
std::type_info const & valueTypeInfo_() const override
Definition: Wrapper.h:100
edm::soa::MakeTableExaminer
Definition: Wrapper.h:147
edm::ProductID
Definition: ProductID.h:27
edm::soa::MakeTableExaminer::make
static std::shared_ptr< edm::soa::TableExaminerBase > make(void const *)
Definition: Wrapper.h:148
edm::WrapperBase::Emplace
Definition: WrapperBase.h:26