-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwrite.C
More file actions
162 lines (150 loc) · 6.19 KB
/
Copy pathwrite.C
File metadata and controls
162 lines (150 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <ROOT/RField.hxx>
#include <ROOT/RNTupleModel.hxx>
#if __has_include(<ROOT/RNTupleTypes.hxx>)
#include <ROOT/RNTupleTypes.hxx>
#else
#include <ROOT/RNTupleUtil.hxx>
#endif
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>
#include <cstdint>
#include <limits>
#include <memory>
#include <string_view>
template <typename T>
static std::shared_ptr<T> MakeFundamentalField(ROOT::RNTupleModel &model,
std::string_view name,
ROOT::ENTupleColumnType type) {
auto field = std::make_unique<ROOT::RField<T>>(name);
field->SetColumnRepresentatives({{type}});
model.AddField(std::move(field));
return model.GetDefaultEntry().GetPtr<T>(name);
}
void write(std::string_view filename = "types.fundamental.integer.root") {
auto model = ROOT::RNTupleModel::Create();
auto Int8 = MakeFundamentalField<std::int8_t>(*model, "Int8",
ROOT::ENTupleColumnType::kInt8);
auto UInt8 = MakeFundamentalField<std::uint8_t>(
*model, "UInt8", ROOT::ENTupleColumnType::kUInt8);
// Non-split integer encoding
auto Int16 = MakeFundamentalField<std::int16_t>(
*model, "Int16", ROOT::ENTupleColumnType::kInt16);
auto UInt16 = MakeFundamentalField<std::uint16_t>(
*model, "UInt16", ROOT::ENTupleColumnType::kUInt16);
auto Int32 = MakeFundamentalField<std::int32_t>(
*model, "Int32", ROOT::ENTupleColumnType::kInt32);
auto UInt32 = MakeFundamentalField<std::uint32_t>(
*model, "UInt32", ROOT::ENTupleColumnType::kUInt32);
auto Int64 = MakeFundamentalField<std::int64_t>(
*model, "Int64", ROOT::ENTupleColumnType::kInt64);
auto UInt64 = MakeFundamentalField<std::uint64_t>(
*model, "UInt64", ROOT::ENTupleColumnType::kUInt64);
// Split integer encoding
auto SplitInt16 = MakeFundamentalField<std::int16_t>(
*model, "SplitInt16", ROOT::ENTupleColumnType::kSplitInt16);
auto SplitUInt16 = MakeFundamentalField<std::uint16_t>(
*model, "SplitUInt16", ROOT::ENTupleColumnType::kSplitUInt16);
auto SplitInt32 = MakeFundamentalField<std::int32_t>(
*model, "SplitInt32", ROOT::ENTupleColumnType::kSplitInt32);
auto SplitUInt32 = MakeFundamentalField<std::uint32_t>(
*model, "SplitUInt32", ROOT::ENTupleColumnType::kSplitUInt32);
auto SplitInt64 = MakeFundamentalField<std::int64_t>(
*model, "SplitInt64", ROOT::ENTupleColumnType::kSplitInt64);
auto SplitUInt64 = MakeFundamentalField<std::uint64_t>(
*model, "SplitUInt64", ROOT::ENTupleColumnType::kSplitUInt64);
ROOT::RNTupleWriteOptions options;
options.SetCompression(0);
auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "ntpl",
filename, options);
// First entry: ascending values
*Int8 = 1;
*UInt8 = 2;
*Int16 = 3;
*UInt16 = 4;
*Int32 = 5;
*UInt32 = 6;
*Int64 = 7;
*UInt64 = 8;
*SplitInt16 = 9;
*SplitUInt16 = 10;
*SplitInt32 = 11;
*SplitUInt32 = 12;
*SplitInt64 = 13;
*SplitUInt64 = 14;
writer->Fill();
// Second entry: values in each byte (to validate split encoding)
static constexpr std::uint8_t Value8 = 0x12; // = 18
static constexpr std::uint16_t Value16 = 0x1234; // = 4660
static constexpr std::uint32_t Value32 = 0x12345678; // = 305419896
static constexpr std::uint64_t Value64 =
0x123456780112358c; // = 1311768464885691788
*Int8 = Value8;
*UInt8 = Value8;
*Int16 = Value16;
*UInt16 = Value16;
*Int32 = Value32;
*UInt32 = Value32;
*Int64 = Value64;
*UInt64 = Value64;
*SplitInt16 = Value16;
*SplitUInt16 = Value16;
*SplitInt32 = Value32;
*SplitUInt32 = Value32;
*SplitInt64 = Value64;
*SplitUInt64 = Value64;
writer->Fill();
// Third entry: negative values for signed integer types (to validate zigzag
// encoding)
static constexpr std::int8_t NegativeValue8 = 0x92; // = -110
static constexpr std::int16_t NegativeValue16 = 0x9234; // = -28108
static constexpr std::int32_t NegativeValue32 = 0x92345678; // = -1842063752
static constexpr std::int64_t NegativeValue64 =
0x923456780112358c; // = -7911603571969084020
*Int8 = NegativeValue8;
*UInt8 = Value8;
*Int16 = NegativeValue16;
*UInt16 = Value16;
*Int32 = NegativeValue32;
*UInt32 = Value32;
*Int64 = NegativeValue64;
*UInt64 = Value64;
*SplitInt16 = NegativeValue16;
*SplitUInt16 = Value16;
*SplitInt32 = NegativeValue32;
*SplitUInt32 = Value32;
*SplitInt64 = NegativeValue64;
*SplitUInt64 = Value64;
writer->Fill();
// Fourth entry: minimum (lowest) values
*Int8 = std::numeric_limits<std::int8_t>::lowest();
*UInt8 = std::numeric_limits<std::uint8_t>::lowest();
*Int16 = std::numeric_limits<std::int16_t>::lowest();
*UInt16 = std::numeric_limits<std::uint16_t>::lowest();
*Int32 = std::numeric_limits<std::int32_t>::lowest();
*UInt32 = std::numeric_limits<std::uint32_t>::lowest();
*Int64 = std::numeric_limits<std::int64_t>::lowest();
*UInt64 = std::numeric_limits<std::uint64_t>::lowest();
*SplitInt16 = std::numeric_limits<std::int16_t>::lowest();
*SplitUInt16 = std::numeric_limits<std::uint16_t>::lowest();
*SplitInt32 = std::numeric_limits<std::int32_t>::lowest();
*SplitUInt32 = std::numeric_limits<std::uint32_t>::lowest();
*SplitInt64 = std::numeric_limits<std::int64_t>::lowest();
*SplitUInt64 = std::numeric_limits<std::uint64_t>::lowest();
writer->Fill();
// Fifth entry: maximum values
*Int8 = std::numeric_limits<std::int8_t>::max();
*UInt8 = std::numeric_limits<std::uint8_t>::max();
*Int16 = std::numeric_limits<std::int16_t>::max();
*UInt16 = std::numeric_limits<std::uint16_t>::max();
*Int32 = std::numeric_limits<std::int32_t>::max();
*UInt32 = std::numeric_limits<std::uint32_t>::max();
*Int64 = std::numeric_limits<std::int64_t>::max();
*UInt64 = std::numeric_limits<std::uint64_t>::max();
*SplitInt16 = std::numeric_limits<std::int16_t>::max();
*SplitUInt16 = std::numeric_limits<std::uint16_t>::max();
*SplitInt32 = std::numeric_limits<std::int32_t>::max();
*SplitUInt32 = std::numeric_limits<std::uint32_t>::max();
*SplitInt64 = std::numeric_limits<std::int64_t>::max();
*SplitUInt64 = std::numeric_limits<std::uint64_t>::max();
writer->Fill();
}