Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
29namespace ROOT {
30namespace Experimental {
31
32namespace 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
40The content pointed to by fRawContent can be a single element or the first element of an array.
41Usually the on-disk element should map bitwise to the in-memory element. Sometimes that's not the case
42though, for instance on big endian platforms and for exotic physical columns like 8 bit float.
43
44This class does not provide protection around the raw pointer, fRawContent has to be managed correctly
45by the user of this class.
46*/
47// clang-format on
49protected:
50 /// Points to valid C++ data, either a single value or an array of values
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
55public:
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 */
108template <typename CppT, EColumnType ColumnT>
110public:
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
120template <>
122public:
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
131template <>
133public:
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
142template <>
143class RColumnElement<std::uint8_t, EColumnType::kByte> : public RColumnElementBase {
144public:
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
153template <>
154class RColumnElement<std::int32_t, EColumnType::kInt32> : public RColumnElementBase {
155public:
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
164template <>
165class RColumnElement<std::uint32_t, EColumnType::kInt32> : public RColumnElementBase {
166public:
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
175template <>
176class RColumnElement<std::int64_t, EColumnType::kInt64> : public RColumnElementBase {
177public:
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
186template <>
187class RColumnElement<std::uint64_t, EColumnType::kInt64> : public RColumnElementBase {
188public:
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
197template <>
199public:
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;
204 bool IsMappable() const final { return kIsMappable; }
205 std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
206};
207
208template <>
210public:
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;
215 bool IsMappable() const final { return kIsMappable; }
216 std::size_t GetBitsOnStorage() const final { return kBitsOnStorage; }
217};
218
219template <>
221public:
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
230template <>
232public:
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
double
uint8_t
#define R__ASSERT(e)
Definition TError.h:120
int type
Definition TGX11.cxx:121
@ kSize
Definition TStructNode.h:26
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-...
static std::unique_ptr< RColumnElementBase > Generate(EColumnType type)
void WriteTo(void *destination, std::size_t count) const
Write one or multiple column elements into destination.
RColumnElementBase(RColumnElementBase &&other)=default
virtual bool IsMappable() const
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
void * fRawContent
Points to valid C++ data, either a single value or an array of values.
RColumnElementBase(void *rawContent, std::size_t size)
RColumnElementBase(const RColumnElementBase &other)=default
RColumnElementBase & operator=(const RColumnElementBase &other)=delete
std::size_t fSize
Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
void ReadFrom(void *source, std::size_t count)
Set the column element or an array of elements from the memory location source.
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-...
RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
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-...
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-...
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
bool IsMappable() const final
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
Pairs of C++ type and column type, like float and EColumnType::kReal32.
Holds the index and the tag of a kSwitch column.
RClusterSize ClusterSize_t
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...