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 <type_traits>
27 
28 namespace ROOT {
29 namespace Experimental {
30 
31 namespace Detail {
32 
33 // clang-format off
34 /**
35 \class ROOT::Experimental::Detail::RColumnElement
36 \ingroup NTuple
37 \brief A column element points either to the content of an RFieldValue or into a memory mapped page.
38 
39 The content pointed to by fRawContent can be a single element or the first element of an array.
40 Usually the on-disk element should map bitwise to the in-memory element. Sometimes that's not the case
41 though, for instance on big endian platforms and for exotic physical columns like 8 bit float.
42 
43 This class does not provide protection around the raw pointer, fRawContent has to be managed correctly
44 by the user of this class.
45 */
46 // clang-format on
48 protected:
49  /// Points to valid C++ data, either a single value or an array of values
50  void* fRawContent;
51  /// Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
52  std::size_t fSize;
53 
54 public:
56  : fRawContent(nullptr)
57  , fSize(0)
58  {}
59  RColumnElementBase(void *rawContent, std::size_t size) : fRawContent(rawContent), fSize(size)
60  {}
61  RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
62  : fRawContent(static_cast<unsigned char *>(elemArray.fRawContent) + elemArray.fSize * at)
63  , fSize(elemArray.fSize)
64  {}
65  RColumnElementBase(const RColumnElementBase& other) = default;
69  virtual ~RColumnElementBase() = default;
70 
72 
73  /// Write one or multiple column elements into destination
74  void WriteTo(void *destination, std::size_t count) const {
75  std::memcpy(destination, fRawContent, fSize * count);
76  }
77 
78  /// Set the column element or an array of elements from the memory location source
79  void ReadFrom(void *source, std::size_t count) {
80  std::memcpy(fRawContent, source, fSize * count);
81  }
82 
83  /// Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout
84  virtual bool IsMappable() const { R__ASSERT(false); return false; }
85  virtual std::size_t GetBitsOnStorage() const { R__ASSERT(false); return 0; }
86 
87  /// If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-memory page
88  virtual void Pack(void *destination, void *source, std::size_t count) const
89  {
90  std::memcpy(destination, source, count);
91  }
92 
93  /// If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-storage page
94  virtual void Unpack(void *destination, void *source, std::size_t count) const
95  {
96  std::memcpy(destination, source, count);
97  }
98 
99  void *GetRawContent() const { return fRawContent; }
100  std::size_t GetSize() const { return fSize; }
101 };
102 
103 /**
104  * Pairs of C++ type and column type, like float and EColumnType::kReal32
105  */
106 template <typename CppT, EColumnType ColumnT>
108 public:
109  explicit RColumnElement(CppT* value) : RColumnElementBase(value, sizeof(CppT))
110  {
111  // Do not allow this template to be instantiated unless there is a specialization. The assert needs to depend
112  // on the template type or else the static_assert will always fire.
113  static_assert(sizeof(CppT) != sizeof(CppT), "No column mapping for this C++ type");
114  }
115 };
116 
117 
118 template <>
120 public:
121  static constexpr bool kIsMappable = true;
122  static constexpr std::size_t kSize = sizeof(float);
123  static constexpr std::size_t kBitsOnStorage = kSize * 8;
124  explicit RColumnElement(float *value) : RColumnElementBase(value, kSize) {}
125  bool IsMappable() const final { return kIsMappable; }
126  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
127 };
128 
129 template <>
131 public:
132  static constexpr bool kIsMappable = true;
133  static constexpr std::size_t kSize = sizeof(double);
134  static constexpr std::size_t kBitsOnStorage = kSize * 8;
135  explicit RColumnElement(double *value) : RColumnElementBase(value, kSize) {}
136  bool IsMappable() const final { return kIsMappable; }
137  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
138 };
139 
140 template <>
141 class RColumnElement<std::uint8_t, EColumnType::kByte> : public RColumnElementBase {
142 public:
143  static constexpr bool kIsMappable = true;
144  static constexpr std::size_t kSize = sizeof(std::uint8_t);
145  static constexpr std::size_t kBitsOnStorage = kSize * 8;
146  explicit RColumnElement(std::uint8_t *value) : RColumnElementBase(value, kSize) {}
147  bool IsMappable() const final { return kIsMappable; }
148  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
149 };
150 
151 template <>
152 class RColumnElement<std::int32_t, EColumnType::kInt32> : public RColumnElementBase {
153 public:
154  static constexpr bool kIsMappable = true;
155  static constexpr std::size_t kSize = sizeof(std::int32_t);
156  static constexpr std::size_t kBitsOnStorage = kSize * 8;
157  explicit RColumnElement(std::int32_t *value) : RColumnElementBase(value, kSize) {}
158  bool IsMappable() const final { return kIsMappable; }
159  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
160 };
161 
162 template <>
163 class RColumnElement<std::uint32_t, EColumnType::kInt32> : public RColumnElementBase {
164 public:
165  static constexpr bool kIsMappable = true;
166  static constexpr std::size_t kSize = sizeof(std::uint32_t);
167  static constexpr std::size_t kBitsOnStorage = kSize * 8;
168  explicit RColumnElement(std::uint32_t *value) : RColumnElementBase(value, kSize) {}
169  bool IsMappable() const final { return kIsMappable; }
170  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
171 };
172 
173 template <>
174 class RColumnElement<std::int64_t, EColumnType::kInt64> : public RColumnElementBase {
175 public:
176  static constexpr bool kIsMappable = true;
177  static constexpr std::size_t kSize = sizeof(std::int64_t);
178  static constexpr std::size_t kBitsOnStorage = kSize * 8;
179  explicit RColumnElement(std::int64_t *value) : RColumnElementBase(value, kSize) {}
180  bool IsMappable() const final { return kIsMappable; }
181  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
182 };
183 
184 template <>
185 class RColumnElement<std::uint64_t, EColumnType::kInt64> : public RColumnElementBase {
186 public:
187  static constexpr bool kIsMappable = true;
188  static constexpr std::size_t kSize = sizeof(std::uint64_t);
189  static constexpr std::size_t kBitsOnStorage = kSize * 8;
190  explicit RColumnElement(std::uint64_t *value) : RColumnElementBase(value, kSize) {}
191  bool IsMappable() const final { return kIsMappable; }
192  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
193 };
194 
195 template <>
197 public:
198  static constexpr bool kIsMappable = true;
199  static constexpr std::size_t kSize = sizeof(ROOT::Experimental::ClusterSize_t);
200  static constexpr std::size_t kBitsOnStorage = kSize * 8;
201  explicit RColumnElement(ClusterSize_t *value) : RColumnElementBase(value, kSize) {}
202  bool IsMappable() const final { return kIsMappable; }
203  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
204 };
205 
206 template <>
208 public:
209  static constexpr bool kIsMappable = true;
210  static constexpr std::size_t kSize = sizeof(ROOT::Experimental::RColumnSwitch);
211  static constexpr std::size_t kBitsOnStorage = kSize * 8;
212  explicit RColumnElement(RColumnSwitch *value) : RColumnElementBase(value, kSize) {}
213  bool IsMappable() const final { return kIsMappable; }
214  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
215 };
216 
217 template <>
219 public:
220  static constexpr bool kIsMappable = true;
221  static constexpr std::size_t kSize = sizeof(char);
222  static constexpr std::size_t kBitsOnStorage = kSize * 8;
223  explicit RColumnElement(char *value) : RColumnElementBase(value, kSize) {}
224  bool IsMappable() const final { return kIsMappable; }
225  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
226 };
227 
228 template <>
230 public:
231  static constexpr bool kIsMappable = false;
232  static constexpr std::size_t kSize = sizeof(bool);
233  static constexpr std::size_t kBitsOnStorage = 1;
234  explicit RColumnElement(bool *value) : RColumnElementBase(value, kSize) {}
235  bool IsMappable() const final { return kIsMappable; }
236  std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
237 
238  void Pack(void *dst, void *src, std::size_t count) const final;
239  void Unpack(void *dst, void *src, std::size_t count) const final;
240 };
241 
242 } // namespace Detail
243 } // namespace Experimental
244 } // namespace ROOT
245 
246 #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:136
ROOT::Experimental::Detail::RColumnElement::RColumnElement
RColumnElement(CppT *value)
Definition: RColumnElement.hxx:109
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:201
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase()
Definition: RColumnElement.hxx:55
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:52
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:213
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:224
ROOT::Experimental::Detail::RColumnElement< char, EColumnType::kByte >::RColumnElement
RColumnElement(char *value)
Definition: RColumnElement.hxx:223
ROOT::Experimental::Detail::RColumnElementBase::GetSize
std::size_t GetSize() const
Definition: RColumnElement.hxx:100
ROOT::Experimental::Detail::RColumnElement< ClusterSize_t, EColumnType::kIndex >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:203
uint8_t
uint8_t
Definition: Converters.cxx:858
ROOT::Experimental::Detail::RColumnElement< float, EColumnType::kReal32 >::RColumnElement
RColumnElement(float *value)
Definition: RColumnElement.hxx:124
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:125
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:88
ROOT::Experimental::Detail::RColumnElement< double, EColumnType::kReal64 >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:137
ROOT::Experimental::Detail::RColumnElementBase::GetRawContent
void * GetRawContent() const
Definition: RColumnElement.hxx:99
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:225
ROOT::Experimental::Detail::RColumnElementBase::fRawContent
void * fRawContent
Points to valid C++ data, either a single value or an array of values.
Definition: RColumnElement.hxx:50
ROOT::Experimental::Detail::RColumnElementBase::RColumnElementBase
RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
Definition: RColumnElement.hxx:61
ROOT::Experimental::EColumnType::kReal32
@ kReal32
ROOT::Experimental::Detail::RColumnElement
Pairs of C++ type and column type, like float and EColumnType::kReal32.
Definition: RColumnElement.hxx:107
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::RColumnElement
RColumnElement(bool *value)
Definition: RColumnElement.hxx:234
ROOT::Experimental::Detail::RColumnElement< RColumnSwitch, EColumnType::kSwitch >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:214
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:79
ROOT::Experimental::Detail::RColumnElement< RColumnSwitch, EColumnType::kSwitch >::RColumnElement
RColumnElement(RColumnSwitch *value)
Definition: RColumnElement.hxx:212
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:202
ROOT::Experimental::EColumnType
EColumnType
Definition: RColumnModel.hxx:35
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:52
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:59
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:64
ROOT::Experimental::Detail::RColumnElement< double, EColumnType::kReal64 >::RColumnElement
RColumnElement(double *value)
Definition: RColumnElement.hxx:135
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:94
ROOT::Experimental::Detail::RColumnElementBase::Generate
static RColumnElementBase Generate(EColumnType type)
Definition: RColumnElement.cxx:25
ROOT::Experimental::RColumnSwitch
Holds the index and the tag of a kSwitch column.
Definition: RNTupleUtil.hxx:68
ROOT::Experimental::Detail::RColumnElementBase::GetBitsOnStorage
virtual std::size_t GetBitsOnStorage() const
Definition: RColumnElement.hxx:85
ROOT::Experimental::Detail::RColumnElement< float, EColumnType::kReal32 >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:126
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:235
type
int type
Definition: TGX11.cxx:121
ROOT::Experimental::Detail::RColumnElement< bool, EColumnType::kBit >::GetBitsOnStorage
std::size_t GetBitsOnStorage() const final
Definition: RColumnElement.hxx:236
ROOT::Experimental::Detail::RColumnElementBase
Definition: RColumnElement.hxx:47
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:84
ROOT
VSD Structures.
Definition: StringConv.hxx:21
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:74
TError.h