-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwrite.C
More file actions
71 lines (60 loc) · 2.1 KB
/
write.C
File metadata and controls
71 lines (60 loc) · 2.1 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
#include <ROOT/RField.hxx>
#include <ROOT/RNTupleModel.hxx>
#include <ROOT/RNTupleUtil.hxx>
#include <ROOT/RNTupleWriteOptions.hxx>
#include <ROOT/RNTupleWriter.hxx>
using ROOT::Experimental::EColumnType;
using ROOT::Experimental::RField;
using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleWriteOptions;
using ROOT::Experimental::RNTupleWriter;
#include <memory>
#include <string>
#include <string_view>
static std::shared_ptr<std::string> MakeStringField(RNTupleModel &model,
std::string_view name,
EColumnType indexType) {
auto field = std::make_unique<RField<std::string>>(name);
field->SetColumnRepresentatives({{indexType, EColumnType::kChar}});
model.AddField(std::move(field));
return model.GetDefaultEntry().GetPtr<std::string>(name);
}
void write(std::string_view filename = "types.string.root") {
auto model = RNTupleModel::Create();
// Non-split index encoding
auto Index32 = MakeStringField(*model, "Index32", EColumnType::kIndex32);
auto Index64 = MakeStringField(*model, "Index64", EColumnType::kIndex64);
// Split index encoding
auto SplitIndex32 =
MakeStringField(*model, "SplitIndex32", EColumnType::kSplitIndex32);
auto SplitIndex64 =
MakeStringField(*model, "SplitIndex64", EColumnType::kSplitIndex64);
RNTupleWriteOptions options;
options.SetCompression(0);
auto writer =
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options);
// First entry: one character strings, with ascending values
*Index32 = "a";
*Index64 = "b";
*SplitIndex32 = "c";
*SplitIndex64 = "d";
writer->Fill();
// Second entry: empty strings
*Index32 = "";
*Index64 = "";
*SplitIndex32 = "";
*SplitIndex64 = "";
writer->Fill();
// Third entry: Unicode characters as UTF-8
*Index32 = "🐣";
*Index64 = "🐣";
*SplitIndex32 = "🐣";
*SplitIndex64 = "🐣";
writer->Fill();
// Fourth entry: increasing length of strings
*Index32 = "a";
*Index64 = "bc";
*SplitIndex32 = "def";
*SplitIndex64 = "ghij";
writer->Fill();
}