Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RColumnElement.cxx
Go to the documentation of this file.
1/// \file RColumnElement.cxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2019-08-11
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
17
18#include <TError.h>
19
20#include <algorithm>
21#include <bitset>
22#include <cstdint>
23#include <memory>
24#include <utility>
25
26std::unique_ptr<ROOT::Experimental::Detail::RColumnElementBase>
28 switch (type) {
30 return std::make_unique<RColumnElement<float, EColumnType::kReal32>>(nullptr);
32 return std::make_unique<RColumnElement<double, EColumnType::kReal64>>(nullptr);
34 return std::make_unique<RColumnElement<char, EColumnType::kChar>>(nullptr);
36 return std::make_unique<RColumnElement<std::uint8_t, EColumnType::kByte>>(nullptr);
38 return std::make_unique<RColumnElement<std::int8_t, EColumnType::kInt8>>(nullptr);
40 return std::make_unique<RColumnElement<std::int16_t, EColumnType::kInt16>>(nullptr);
42 return std::make_unique<RColumnElement<std::int32_t, EColumnType::kInt32>>(nullptr);
44 return std::make_unique<RColumnElement<std::int64_t, EColumnType::kInt64>>(nullptr);
46 return std::make_unique<RColumnElement<bool, EColumnType::kBit>>(nullptr);
48 return std::make_unique<RColumnElement<ClusterSize_t, EColumnType::kIndex>>(nullptr);
50 return std::make_unique<RColumnElement<RColumnSwitch, EColumnType::kSwitch>>(nullptr);
51 default:
52 R__ASSERT(false);
53 }
54 // never here
55 return nullptr;
56}
57
59 switch (type) {
61 return 32;
63 return 64;
65 return 8;
67 return 8;
69 return 8;
71 return 16;
73 return 32;
75 return 64;
77 return 1;
79 return 32;
81 return 64;
82 default:
83 R__ASSERT(false);
84 }
85 // never here
86 return 0;
87}
88
90 switch (type) {
92 return "Real32";
94 return "Real64";
96 return "Char";
98 return "Byte";
100 return "Int8";
102 return "Int16";
104 return "Int32";
106 return "Int64";
108 return "Bit";
110 return "Index";
112 return "Switch";
113 default:
114 return "UNKNOWN";
115 }
116}
117
119 ROOT::Experimental::EColumnType::kSwitch>::Pack(void *dst, void *src,
120 std::size_t count) const
121{
122 auto srcArray = reinterpret_cast<ROOT::Experimental::RColumnSwitch *>(src);
123 auto uint64Array = reinterpret_cast<std::uint64_t *>(dst);
124 for (std::size_t i = 0; i < count; ++i) {
125 uint64Array[i] =
126 (static_cast<std::uint64_t>(srcArray[i].GetTag()) << 44) | (srcArray[i].GetIndex() & 0x0fffffffffff);
127#if R__LITTLE_ENDIAN == 0
128 uint64Array[i] = RByteSwap<8>::bswap(uint64Array[i]);
129#endif
130 }
131}
132
135 std::size_t count) const
136{
137 auto uint64Array = reinterpret_cast<std::uint64_t *>(src);
138 auto dstArray = reinterpret_cast<ROOT::Experimental::RColumnSwitch *>(dst);
139 for (std::size_t i = 0; i < count; ++i) {
140#if R__LITTLE_ENDIAN == 1
141 const auto value = uint64Array[i];
142#else
143 const auto value = RByteSwap<8>::bswap(uint64Array[i]);
144#endif
146 ClusterSize_t{static_cast<RClusterSize::ValueType>(value & 0x0fffffffffff)}, (value >> 44));
147 }
148}
149
151 void *dst, void *src, std::size_t count) const
152{
153 bool *boolArray = reinterpret_cast<bool *>(src);
154 char *charArray = reinterpret_cast<char *>(dst);
155 std::bitset<8> bitSet;
156 std::size_t i = 0;
157 for (; i < count; ++i) {
158 bitSet.set(i % 8, boolArray[i]);
159 if (i % 8 == 7) {
160 char packed = bitSet.to_ulong();
161 charArray[i / 8] = packed;
162 }
163 }
164 if (i % 8 != 0) {
165 char packed = bitSet.to_ulong();
166 charArray[i / 8] = packed;
167 }
168}
169
171 void *dst, void *src, std::size_t count) const
172{
173 bool *boolArray = reinterpret_cast<bool *>(dst);
174 char *charArray = reinterpret_cast<char *>(src);
175 std::bitset<8> bitSet;
176 for (std::size_t i = 0; i < count; i += 8) {
177 bitSet = charArray[i / 8];
178 for (std::size_t j = i; j < std::min(count, i + 8); ++j) {
179 boolArray[j] = bitSet[j % 8];
180 }
181 }
182}
183
184
186 void *dst, void *src, std::size_t count) const
187{
188 std::int64_t *int64Array = reinterpret_cast<std::int64_t *>(src);
189 std::int32_t *int32Array = reinterpret_cast<std::int32_t *>(dst);
190 for (std::size_t i = 0; i < count; ++i) {
191 int32Array[i] = int64Array[i];
192#if R__LITTLE_ENDIAN == 0
193 int32Array[i] = RByteSwap<4>::bswap(int32Array[i]);
194#endif
195 }
196}
197
199 void *dst, void *src, std::size_t count) const
200{
201 std::int32_t *int32Array = reinterpret_cast<std::int32_t *>(src);
202 std::int64_t *int64Array = reinterpret_cast<std::int64_t *>(dst);
203 for (std::size_t i = 0; i < count; ++i) {
204 int64Array[i] = int32Array[i];
205#if R__LITTLE_ENDIAN == 0
206 int64Array[i] = RByteSwap<8>::bswap(int64Array[i]);
207#endif
208 }
209}
#define R__ASSERT(e)
Definition TError.h:117
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
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
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)
static std::string GetTypeName(EColumnType type)
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-...
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
Helper templated class for swapping bytes; specializations for N={2,4,8} are provided below.
Definition Byteswap.h:124