forked from root-project/rntuple-validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.C
More file actions
86 lines (76 loc) · 2.13 KB
/
Copy pathread.C
File metadata and controls
86 lines (76 loc) · 2.13 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
#include <ROOT/REntry.hxx>
#include <ROOT/RNTupleReader.hxx>
#include <TSystem.h>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <ostream>
#include <set>
#include <string>
#include <string_view>
using Multiset = std::multiset<std::multiset<std::int32_t>>;
static void PrintNestedMultisetValue(const ROOT::REntry &entry,
std::string_view name, std::ostream &os,
bool last = false) {
Multiset &value = *entry.GetPtr<Multiset>(name);
os << " \"" << name << "\": [";
bool outerFirst = true;
for (auto inner : value) {
if (outerFirst) {
outerFirst = false;
} else {
os << ",";
}
os << "\n [";
bool innerFirst = true;
for (auto element : inner) {
if (innerFirst) {
innerFirst = false;
} else {
os << ",";
}
os << "\n " << element;
}
if (!inner.empty()) {
os << "\n ";
}
os << "]";
}
if (!value.empty()) {
os << "\n ";
}
os << "]";
if (!last) {
os << ",";
}
os << "\n";
}
void read(std::string_view input = "types.multiset.nested.root",
std::string_view output = "types.multiset.nested.json") {
if (gSystem->Load("libNestedMultiset") == -1)
throw std::runtime_error("could not find the required ROOT dictionaries, "
"please make sure to run `make` first");
std::ofstream os(std::string{output});
os << "[\n";
auto reader = ROOT::RNTupleReader::Open("ntpl", input);
auto &entry = reader->GetModel().GetDefaultEntry();
bool first = true;
for (auto index : *reader) {
reader->LoadEntry(index);
if (first) {
first = false;
} else {
os << ",\n";
}
os << " {\n";
PrintNestedMultisetValue(entry, "Index32", os);
PrintNestedMultisetValue(entry, "Index64", os);
PrintNestedMultisetValue(entry, "SplitIndex32", os);
PrintNestedMultisetValue(entry, "SplitIndex64", os, /*last=*/true);
os << " }";
// Newline is intentionally missing, may need to print a comma before the
// next entry.
}
os << "\n";
os << "]\n";
}