Logo ROOT   6.18/05
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 <cstring> // for memcpy
23#include <type_traits>
24
25namespace ROOT {
26namespace Experimental {
27
28namespace Detail {
29
30// clang-format off
31/**
32\class ROOT::Experimental::Detail::RColumnElement
33\ingroup NTuple
34\brief A column element points either to the content of an RFieldValue or into a memory mapped page.
35
36The content pointed to by fRawContent can be a single element or the first element of an array.
37Usually the on-disk element should map bitwise to the in-memory element. Sometimes that's not the case
38though, for instance on big endian platforms and for exotic physical columns like 8 bit float.
39
40This class does not provide protection around the raw pointer, fRawContent has to be managed correctly
41by the user of this class.
42*/
43// clang-format on
45protected:
46 /// Points to valid C++ data, either a single value or an array of values
48 /// Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
49 unsigned int fSize;
50
51 /// Indicates that *fRawContent is bitwise identical to the physical column element
53
54 virtual void DoSerialize(void* /* destination */, std::size_t /*count*/) const { }
55 virtual void DoDeserialize(void* /* source */, std::size_t /*count*/) const { }
56
57public:
59 : fRawContent(nullptr)
60 , fSize(0)
61 , fIsMappable(false)
62 {}
63 RColumnElementBase(void* rawContent, unsigned int size, bool isMappable)
64 : fRawContent(rawContent)
65 , fSize(size)
66 , fIsMappable(isMappable)
67 {}
68 RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
69 : fRawContent(static_cast<unsigned char *>(elemArray.fRawContent) + elemArray.fSize * at)
70 , fSize(elemArray.fSize)
71 , fIsMappable(elemArray.fIsMappable)
72 {}
73 RColumnElementBase(const RColumnElementBase& other) = default;
77 virtual ~RColumnElementBase() = default;
78
79 void Serialize(void *destination, std::size_t count) const {
80 if (!fIsMappable) {
81 DoSerialize(destination, count);
82 return;
83 }
84 std::memcpy(destination, fRawContent, fSize * count);
85 }
86
87 void Deserialize(void *source, std::size_t count) {
88 if (!fIsMappable) {
89 DoDeserialize(source, count);
90 return;
91 }
92 std::memcpy(fRawContent, source, fSize * count);
93 }
94
95 void* GetRawContent() const { return fRawContent; }
96 unsigned int GetSize() const { return fSize; }
97};
98
99/**
100 * Pairs of C++ type and column type, like float and EColumnType::kReal32
101 */
102template <typename CppT, EColumnType ColumnT>
104public:
105 static constexpr bool kIsMappable = false;
106 explicit RColumnElement(CppT* value) : RColumnElementBase(value, sizeof(CppT), kIsMappable)
107 {
108 static_assert(sizeof(CppT) != sizeof(CppT), "No column mapping for this C++ type");
109 }
110};
111
112
113template <>
115public:
116 static constexpr bool kIsMappable = true;
117 static constexpr size_t kSize = sizeof(float);
118 explicit RColumnElement(float* value) : RColumnElementBase(value, kSize, kIsMappable) {}
119};
120
121template <>
123public:
124 static constexpr bool kIsMappable = true;
125 static constexpr size_t kSize = sizeof(double);
126 explicit RColumnElement(double* value) : RColumnElementBase(value, kSize, kIsMappable) {}
127};
128
129template <>
130class RColumnElement<std::int32_t, EColumnType::kInt32> : public RColumnElementBase {
131public:
132 static constexpr bool kIsMappable = true;
133 static constexpr size_t kSize = sizeof(std::int32_t);
134 explicit RColumnElement(std::int32_t* value) : RColumnElementBase(value, kSize, kIsMappable) {}
135};
136
137template <>
138class RColumnElement<std::uint32_t, EColumnType::kInt32> : public RColumnElementBase {
139public:
140 static constexpr bool kIsMappable = true;
141 static constexpr size_t kSize = sizeof(std::uint32_t);
142 explicit RColumnElement(std::uint32_t* value) : RColumnElementBase(value, kSize, kIsMappable) {}
143};
144
145template <>
146class RColumnElement<std::int64_t, EColumnType::kInt64> : public RColumnElementBase {
147public:
148 static constexpr bool kIsMappable = true;
149 static constexpr size_t kSize = sizeof(std::int64_t);
150 explicit RColumnElement(std::int64_t* value) : RColumnElementBase(value, kSize, kIsMappable) {}
151};
152
153template <>
154class RColumnElement<std::uint64_t, EColumnType::kInt64> : public RColumnElementBase {
155public:
156 static constexpr bool kIsMappable = true;
157 static constexpr size_t kSize = sizeof(std::uint64_t);
158 explicit RColumnElement(std::uint64_t* value) : RColumnElementBase(value, kSize, kIsMappable) {}
159};
160
161template <>
163public:
164 static constexpr bool kIsMappable = true;
165 static constexpr size_t kSize = sizeof(ROOT::Experimental::ClusterSize_t);
167};
168
169template <>
171public:
172 static constexpr bool kIsMappable = true;
173 static constexpr size_t kSize = sizeof(char);
174 explicit RColumnElement(char* value) : RColumnElementBase(value, kSize, kIsMappable) {}
175};
176
177} // namespace Detail
178} // namespace Experimental
179} // namespace ROOT
180
181#endif
@ kSize
Definition: TStructNode.h:26
void Deserialize(void *source, std::size_t count)
virtual void DoSerialize(void *, std::size_t) const
RColumnElementBase(RColumnElementBase &&other)=default
virtual void DoDeserialize(void *, std::size_t) const
void * fRawContent
Points to valid C++ data, either a single value or an array of values.
RColumnElementBase(const RColumnElementBase &other)=default
RColumnElementBase & operator=(const RColumnElementBase &other)=delete
void Serialize(void *destination, std::size_t count) const
RColumnElementBase(const RColumnElementBase &elemArray, std::size_t at)
RColumnElementBase(void *rawContent, unsigned int size, bool isMappable)
unsigned int fSize
Size of the C++ value pointed to by fRawContent (not necessarily equal to the on-disk element size)
bool fIsMappable
Indicates that *fRawContent is bitwise identical to the physical column element.
Pairs of C++ type and column type, like float and EColumnType::kReal32.
RClusterSize ClusterSize_t
Definition: RNTupleUtil.hxx:57
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Wrap the 32bit integer in a struct in order to avoid template specialization clash with std::uint32_t...
Definition: RNTupleUtil.hxx:47