Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RColumnElementBase.hxx
Go to the documentation of this file.
1/// \file ROOT/RColumnElementBase.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_RColumnElementBase
17#define ROOT7_RColumnElementBase
18
19#include "RtypesCore.h"
20#include <ROOT/RError.hxx>
21#include <ROOT/RFloat16.hxx>
22#include <ROOT/RNTupleUtil.hxx>
23
24#include <Byteswap.h>
25#include <TError.h>
26
27#include <cstring> // for memcpy
28#include <cstddef> // for std::byte
29#include <cstdint>
30#include <memory>
31#include <string>
32#include <type_traits>
33#include <typeinfo>
34#include <utility>
35
37
38// clang-format off
39/**
40\class ROOT::Experimental::Internal::RColumnElementBase
41\ingroup NTuple
42\brief A column element encapsulates the translation between basic C++ types and their column representation.
43
44Usually the on-disk element should map bitwise to the in-memory element. Sometimes that's not the case
45though, for instance on big endian platforms or for bools.
46
47There is a template specialization for every valid pair of C++ type and column representation.
48These specialized child classes are responsible for overriding `Pack()` / `Unpack()` for packing / unpacking elements
49as appropriate.
50*/
51// clang-format on
53protected:
54 /// Size of the C++ value that corresponds to the on-disk element
55 std::size_t fSize;
56 std::size_t fBitsOnStorage;
57
58 explicit RColumnElementBase(std::size_t size, std::size_t bitsOnStorage = 0)
59 : fSize(size), fBitsOnStorage(bitsOnStorage ? bitsOnStorage : 8 * size)
60 {
61 }
62
63public:
64 RColumnElementBase(const RColumnElementBase &other) = default;
68 virtual ~RColumnElementBase() = default;
69
70 /// If CppT == void, use the default C++ type for the given column type
71 template <typename CppT = void>
72 static std::unique_ptr<RColumnElementBase> Generate(EColumnType type);
73 static std::string GetTypeName(EColumnType type);
74 /// Most types have a fixed on-disk bit width. Some low-precision column types
75 /// have a range of possible bit widths. Return the minimum and maximum allowed
76 /// bit size per type.
77 static std::pair<std::uint16_t, std::uint16_t> GetValidBitRange(EColumnType type);
78
79 /// Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout
80 virtual bool IsMappable() const
81 {
82 R__ASSERT(false);
83 return false;
84 }
85
86 /// If the on-storage layout and the in-memory layout differ, packing creates an on-disk page from an in-memory page
87 virtual void Pack(void *destination, const void *source, std::size_t count) const
88 {
89 std::memcpy(destination, source, count);
90 }
91
92 /// If the on-storage layout and the in-memory layout differ, unpacking creates a memory page from an on-storage page
93 virtual void Unpack(void *destination, const void *source, std::size_t count) const
94 {
95 std::memcpy(destination, source, count);
96 }
97
98 std::size_t GetSize() const { return fSize; }
99 std::size_t GetBitsOnStorage() const { return fBitsOnStorage; }
100 std::size_t GetPackedSize(std::size_t nElements = 1U) const { return (nElements * fBitsOnStorage + 7) / 8; }
101}; // class RColumnElementBase
102
103// All supported C++ in-memory types
104enum class EColumnCppType {
105 kChar,
106 kBool,
107 kByte,
108 kUint8,
109 kUint16,
110 kUint32,
111 kUint64,
112 kInt8,
113 kInt16,
114 kInt32,
115 kInt64,
116 kFloat,
117 kDouble,
120};
121
122std::unique_ptr<RColumnElementBase> GenerateColumnElement(EColumnCppType cppType, EColumnType colType);
123
124template <typename CppT>
125std::unique_ptr<RColumnElementBase> RColumnElementBase::Generate(EColumnType type)
126{
127 if constexpr (std::is_same_v<CppT, char>)
129 else if constexpr (std::is_same_v<CppT, bool>)
131 else if constexpr (std::is_same_v<CppT, std::byte>)
133 else if constexpr (std::is_same_v<CppT, std::uint8_t>)
135 else if constexpr (std::is_same_v<CppT, std::uint16_t>)
137 else if constexpr (std::is_same_v<CppT, std::uint32_t>)
139 else if constexpr (std::is_same_v<CppT, std::uint64_t>)
141 else if constexpr (std::is_same_v<CppT, std::int8_t>)
143 else if constexpr (std::is_same_v<CppT, std::int16_t>)
145 else if constexpr (std::is_same_v<CppT, std::int32_t>)
147 else if constexpr (std::is_same_v<CppT, std::int64_t>)
149 else if constexpr (std::is_same_v<CppT, float>)
151 else if constexpr (std::is_same_v<CppT, double>)
153 else if constexpr (std::is_same_v<CppT, ClusterSize_t>)
155 else if constexpr (std::is_same_v<CppT, RColumnSwitch>)
157 else
158 static_assert(!sizeof(CppT), "Unsupported Cpp type");
159}
160
161template <>
162std::unique_ptr<RColumnElementBase> RColumnElementBase::Generate<void>(EColumnType type);
163
164} // namespace ROOT::Experimental::Internal
165
166#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
A column element encapsulates the translation between basic C++ types and their column representation...
RColumnElementBase & operator=(const RColumnElementBase &other)=delete
RColumnElementBase(std::size_t size, std::size_t bitsOnStorage=0)
virtual bool IsMappable() const
Derived, typed classes tell whether the on-storage layout is bitwise identical to the memory layout.
virtual void Pack(void *destination, const 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::string GetTypeName(EColumnType type)
std::size_t fSize
Size of the C++ value that corresponds to the on-disk element.
RColumnElementBase(const RColumnElementBase &other)=default
RColumnElementBase & operator=(RColumnElementBase &&other)=default
virtual void Unpack(void *destination, const 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-...
static std::unique_ptr< RColumnElementBase > Generate(EColumnType type)
If CppT == void, use the default C++ type for the given column type.
std::size_t GetPackedSize(std::size_t nElements=1U) const
static std::pair< std::uint16_t, std::uint16_t > GetValidBitRange(EColumnType type)
Most types have a fixed on-disk bit width.
RColumnElementBase(RColumnElementBase &&other)=default
std::unique_ptr< RColumnElementBase > GenerateColumnElement(EColumnCppType cppType, EColumnType colType)