Logo ROOT  
Reference Guide
RColumnElement.hxx
Go to the documentation of this file.
1 /// \file ROOT/RColumnElement.hxx
2 /// \ingroup NTuple ROOT7
3 /// \author Jakob Blomer <jblomer@cern.ch>
4 /// \date 2018-10-09
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_RColumnElement
17 #define ROOT7_RColumnElement
18 
19 #include <ROOT/RColumnModel.hxx>
20 #include <ROOT/RNTupleUtil.hxx>
21 
22 #include <TError.h>
23 
24 #include <cstring> // for memcpy
25 #include <cstdint>
26 #include <memory>
27 #include <type_traits>
28 
29 namespace ROOT {
30 namespace Experimental {
31 
32 namespace Detail {
33 
34 // clang-format off
35 /**
36 \class ROOT::Experimental::Detail::RColumnElement
37 \ingroup NTuple
38 \brief A column element points either to the content of an RFieldValue or into a memory mapped page.
39 
40 The content pointed to by fRawContent can be a single element or the first element of an array.
41 Usually the on-disk element should map bitwise to the in-memory element. Sometimes that's not the case
42 though, for instance on big endian platforms and for exotic physical columns like 8 bit float.
43 
44 This class does not provide protection around the raw pointer, fRawContent has to be managed correctly
45 by the user of this class.
46 */
47 // clang-format on
49 protected:
50  /// Points to valid C++ data, either a single value or an array of values
51  void* fRawContent;
52  /// Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
53  std::size_t fSize;
54 
55 public:
57  : fRawContent(nullptr)
58  , fSize(0)
59  {}
60  RColumnElementBase(void *rawContent, std::size_t size) : fRawContent(rawContent), fSize(size)
61  {}
62  RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
63  : fRawContent(static_cast<unsigned char *>(elemArray.fRawContent) + elemArray.fSize * at)
64  , fSize(elemArray.fSize)
65  {}
66  RColumnElementBase(const RColumnElementBase& other) = default;
70  virtual ~RColumnElementBase() = default;
71 
72  static std::unique_ptr<RColumnElementBase> Generate(EColumnType type);
73  static std::size_t GetBitsOnStorage(EColumnType type);
74 
75  /// Write one or multiple column elements into destination
76  void WriteTo(void *destination, std::size_t count) const {
77  std::memcpy(destination, fRawContent, fSize * count);
78  }
79 
80  /// Set the column element or an array of elements from the memory location source
81  void ReadFrom(void *source, std::size_t count) {
82  std::memcpy(fRawContent, source, fSize * count);
83  }
84 
85  /// Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout
86  virtual bool IsMappable() const { R__ASSERT(false); return false; }
87  virtual std::size_t GetBitsOnStorage() const { R__ASSERT(false); return 0; }
88 
89  /// If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-memory page
90  virtual void Pack(void *destination, void *source, std::size_t count) const
91  {
92  std::memcpy(destination, source, count);
93  }
94 
95  /// If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-storage page
96  virtual void Unpack(void *destination, void *source, std::size_t count) const
97  {
98  std::memcpy(destination, source, count);
99  }
100 
101  void *GetRawContent() const { return fRawContent; }
102  std::size_t GetSize() const { return fSize; }
103 };
104 
105 /**
106  * Pairs of C++ type and column type, like float and EColumnType::kReal32
107  */
108 template <typename CppT, EColumnType ColumnT>
110 public:
111  explicit RColumnElement(CppT* value) : RColumnElementBase(value, sizeof(CppT))
112  {
113  // Do not allow this template to be instantiated unless there is a specialization. The assert needs to depend
114  // on the template type or else the static_assert will always fire.
115  static_assert(sizeof(CppT) != sizeof(CppT), "No column mapping for this C++ type");
116  }
117 };
118 
119 
120 template <>
122 public:
123  static constexpr bool kIsMappable = true;
124  static constexpr std::size_t kSize = sizeof(float);
125  static constexpr std::size_t kBitsOnStorage = kSize * 8;
126  explicit RColumnElement(float *value) : RColumnElementBase(value, kSize) {}
127  bool IsMappable() const final { return kIsMappable; }
128  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
129 };
130 
131 template <>
133 public:
134  static constexpr bool kIsMappable = true;
135  static constexpr std::size_t kSize = sizeof(double);
136  static constexpr std::size_t kBitsOnStorage = kSize * 8;
137  explicit RColumnElement(double *value) : RColumnElementBase(value, kSize) {}
138  bool IsMappable() const final { return kIsMappable; }
139  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
140 };
141 
142 template <>
143 class RColumnElement<std::uint8_t, EColumnType::kByte> : public RColumnElementBase {
144 public:
145  static constexpr bool kIsMappable = true;
146  static constexpr std::size_t kSize = sizeof(std::uint8_t);
147  static constexpr std::size_t kBitsOnStorage = kSize * 8;
148  explicit RColumnElement(std::uint8_t *value) : RColumnElementBase(value, kSize) {}
149  bool IsMappable() const final { return kIsMappable; }
150  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
151 };
152 
153 template <>
154 class RColumnElement<std::int32_t, EColumnType::kInt32> : public RColumnElementBase {
155 public:
156  static constexpr bool kIsMappable = true;
157  static constexpr std::size_t kSize = sizeof(std::int32_t);
158  static constexpr std::size_t kBitsOnStorage = kSize * 8;
159  explicit RColumnElement(std::int32_t *value) : RColumnElementBase(value, kSize) {}
160  bool IsMappable() const final { return kIsMappable; }
161  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
162 };
163 
164 template <>
165 class RColumnElement<std::uint32_t, EColumnType::kInt32> : public RColumnElementBase {
166 public:
167  static constexpr bool kIsMappable = true;
168  static constexpr std::size_t kSize = sizeof(std::uint32_t);
169  static constexpr std::size_t kBitsOnStorage = kSize * 8;
170  explicit RColumnElement(std::uint32_t *value) : RColumnElementBase(value, kSize) {}
171  bool IsMappable() const final { return kIsMappable; }
172  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
173 };
174 
175 template <>
176 class RColumnElement<std::int64_t, EColumnType::kInt64> : public RColumnElementBase {
177 public:
178  static constexpr bool kIsMappable = true;
179  static constexpr std::size_t kSize = sizeof(std::int64_t);
180  static constexpr std::size_t kBitsOnStorage = kSize * 8;
181  explicit RColumnElement(std::int64_t *value) : RColumnElementBase(value, kSize) {}
182  bool IsMappable() const final { return kIsMappable; }
183  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
184 };
185 
186 template <>
187 class RColumnElement<std::uint64_t, EColumnType::kInt64> : public RColumnElementBase {
188 public:
189  static constexpr bool kIsMappable = true;
190  static constexpr std::size_t kSize = sizeof(std::uint64_t);
191  static constexpr std::size_t kBitsOnStorage = kSize * 8;
192  explicit RColumnElement(std::uint64_t *value) : RColumnElementBase(value, kSize) {}
193  bool IsMappable() const final { return kIsMappable; }
194  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
195 };
196 
197 template <>
199 public:
200  static constexpr bool kIsMappable = true;
201  static constexpr std::size_t kSize = sizeof(ROOT::Experimental::ClusterSize_t);
202  static constexpr std::size_t kBitsOnStorage = kSize * 8;
203  explicit RColumnElement(ClusterSize_t *value) : RColumnElementBase(value, kSize) {}
204  bool IsMappable() const final { return kIsMappable; }
205  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
206 };
207 
208 template <>
210 public:
211  static constexpr bool kIsMappable = true;
212  static constexpr std::size_t kSize = sizeof(ROOT::Experimental::RColumnSwitch);
213  static constexpr std::size_t kBitsOnStorage = kSize * 8;
214  explicit RColumnElement(RColumnSwitch *value) : RColumnElementBase(value, kSize) {}
215  bool IsMappable() const final { return kIsMappable; }
216  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
217 };
218 
219 template <>
221 public:
222  static constexpr bool kIsMappable = true;
223  static constexpr std::size_t kSize = sizeof(char);
224  static constexpr std::size_t kBitsOnStorage = kSize * 8;
225  explicit RColumnElement(char *value) : RColumnElementBase(value, kSize) {}
226  bool IsMappable() const final { return kIsMappable; }
227  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
228 };
229 
230 template <>
232 public:
233  static constexpr bool kIsMappable = false;
234  static constexpr std::size_t kSize = sizeof(bool);
235  static constexpr std::size_t kBitsOnStorage = 1;
236  explicit RColumnElement(bool *value) : RColumnElementBase(value, kSize) {}
237  bool IsMappable() const final { return kIsMappable; }
238  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
239 
240  void Pack(void *dst, void *src, std::size_t count) const final;
241  void Unpack(void *dst, void *src, std::size_t count) const final;
242 };
243 
244 } // namespace Detail
245 } // namespace Experimental
246 } // namespace ROOT
247 
248 #endif
ROOT::Experimental::Detail::RColumnElement< double, EColumnType::kReal64 >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:138
ROOT::Experimental::Detail::RColumnElement::RColumnElement
RColumnElement(CppT *value)
Definition: RColumnElement.hxx:111
ROOT::Experimental::EColumnType::kReal64
@ kReal64
ROOT::Experimental::EColumnType::kIndex
@ kIndex
ROOT::Experimental::Detail::RColumnElement< ClusterSize_t, EColumnType::kIndex >::RColumnElement
RColumnElement(ClusterSize_t *value)
Definition: RColumnElement.hxx:203
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase()
Definition: RColumnElement.hxx:56
ROOT::Experimental::Detail::RColumnElementBase::fSize
std::size_t fSize
Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
Definition: RColumnElement.hxx:53
ROOT::Experimental::Detail::RColumnElement< RColumnSwitch, EColumnType::kSwitch >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:215
ROOT::Experimental::Detail::RColumnElementBase::~RColumnElementBase
virtual ~RColumnElementBase()=default
ROOT::Experimental::EColumnType::kSwitch
@ kSwitch
ROOT::Experimental::Detail::RColumnElement< char, EColumnType::kByte >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:226
ROOT::Experimental::Detail::RColumnElementBase::Generate
static std::unique_ptr< RColumnElementBase > Generate(EColumnType type)
Definition: RColumnElement.cxx:27
ROOT::Experimental::Detail::RColumnElement< char, EColumnType::kByte >::RColumnElement
RColumnElement(char *value)
Definition: RColumnElement.hxx:225
ROOT::Experimental::Detail::RColumnElementBase::GetSize
std::size_t GetSize() const
Definition: RColumnElement.hxx:102
ROOT::Experimental::Detail::RColumnElement< ClusterSize_t, EColumnType::kIndex >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:205
uint8_t
uint8_t
Definition: Converters.cxx:858
ROOT::Experimental::Detail::RColumnElement< float, EColumnType::kReal32 >::RColumnElement
RColumnElement(float *value)
Definition: RColumnElement.hxx:126
ROOT::Experimental::Detail::RColumnElement< float, EColumnType::kReal32 >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:127
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase(RColumnElementBase &&other)=default
ROOT::Experimental::Detail::RColumnElementBase::Pack
virtual void Pack(void *destination, void *source, std::size_t count) const
If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-...
Definition: RColumnElement.hxx:90
ROOT::Experimental::Detail::RColumnElement< double, EColumnType::kReal64 >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:139
ROOT::Experimental::Detail::RColumnElementBase::GetRawContent
void * GetRawContent() const
Definition: RColumnElement.hxx:101
ROOT::Experimental::EColumnType::kInt64
@ kInt64
bool
ROOT::Experimental::EColumnType::kInt32
@ kInt32
ROOT::Experimental::Detail::RColumnElementBase::operator=
RColumnElementBase & operator=(const RColumnElementBase &other)=delete
ROOT::Experimental::EColumnType::kBit
@ kBit
ROOT::Experimental::Detail::RColumnElement< char, EColumnType::kByte >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:227
ROOT::Experimental::Detail::RColumnElementBase::fRawContent
void * fRawContent
Points to valid C++ data, either a single value or an array of values.
Definition: RColumnElement.hxx:51
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
Definition: RColumnElement.hxx:62
ROOT::Experimental::EColumnType::kReal32
@ kReal32
ROOT::Experimental::Detail::RColumnElement
Pairs of C++ type and column type, like float and EColumnType::kReal32.
Definition: RColumnElement.hxx:109
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::RColumnElement
RColumnElement(bool *value)
Definition: RColumnElement.hxx:236
ROOT::Experimental::Detail::RColumnElement< RColumnSwitch, EColumnType::kSwitch >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:216
RColumnModel.hxx
ROOT::Experimental::Detail::RColumnElementBase::ReadFrom
void ReadFrom(void *source, std::size_t count)
Set the column element or an array of elements from the memory location source.
Definition: RColumnElement.hxx:81
ROOT::Experimental::Detail::RColumnElement< RColumnSwitch, EColumnType::kSwitch >::RColumnElement
RColumnElement(RColumnSwitch *value)
Definition: RColumnElement.hxx:214
ROOT::Experimental::Detail::RColumnElement< ClusterSize_t, EColumnType::kIndex >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:204
ROOT::Experimental::EColumnType
EColumnType
Definition: RColumnModel.hxx:36
ROOT::Experimental::EColumnType::kByte
@ kByte
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase(const RColumnElementBase &other)=default
double
double
Definition: Converters.cxx:921
RNTupleUtil.hxx
kSize
@ kSize
Definition: TStructNode.h:26
ROOT::Experimental::RClusterSize
Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...
Definition: RNTupleUtil.hxx:58
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase(void *rawContent, std::size_t size)
Definition: RColumnElement.hxx:60
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::Pack
void Pack(void *dst, void *src, std::size_t count) const final
If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-...
ROOT::Experimental::ClusterSize_t
RClusterSize ClusterSize_t
Definition: RNTupleUtil.hxx:70
ROOT::Experimental::Detail::RColumnElement< double, EColumnType::kReal64 >::RColumnElement
RColumnElement(double *value)
Definition: RColumnElement.hxx:137
ROOT::Experimental::Detail::RColumnElementBase::Unpack
virtual void Unpack(void *destination, void *source, std::size_t count) const
If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-...
Definition: RColumnElement.hxx:96
ROOT::Experimental::RColumnSwitch
Holds the index and the tag of a kSwitch column.
Definition: RNTupleUtil.hxx:74
ROOT::Experimental::Detail::RColumnElementBase::GetBitsOnStorage
virtual std::size_t GetBitsOnStorage() const
Definition: RColumnElement.hxx:87
ROOT::Experimental::Detail::RColumnElement< float, EColumnType::kReal32 >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:128
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::IsMappable
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:237
type
int type
Definition: TGX11.cxx:121
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:238
ROOT::Experimental::Detail::RColumnElementBase
Definition: RColumnElement.hxx:48
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::Unpack
void Unpack(void *dst, void *src, std::size_t count) const final
If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-...
ROOT::Experimental::Detail::RColumnElementBase::IsMappable
virtual bool IsMappable() const
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Definition: RColumnElement.hxx:86
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Experimental::Detail::RColumnElementBase::WriteTo
void WriteTo(void *destination, std::size_t count) const
Write one or multiple column elements into destination.
Definition: RColumnElement.hxx:76
TError.h