-
Notifications
You must be signed in to change notification settings - Fork 3
Add tests for std::[unordered_][multi]set
#39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e390940
Add test for `std::set`
enirolf 8e2efd4
Add test for `std::unordered_set`
enirolf fcb348b
Add test for `std::multiset`
enirolf e9ee6aa
Add test for `std::unordered_multiset`
enirolf 5e573e3
Automatically create and load dictionaries
enirolf 016171c
Slightly reword and fix grammar
enirolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
*.json | ||
*.root | ||
|
||
# Ignore files related to dictionary generation | ||
*.pcm | ||
Nested*.cxx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# `std::multiset` | ||
|
||
* [`fundamental`](fundamental): `std::multiset<std::int32_t>` | ||
* [`nested`](nested): `std::multiset<std::multiset<std::int32_t>>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# `std::multiset<std::int32_t>` | ||
|
||
## Fields | ||
|
||
* `[Split]Index{32,64}` | ||
|
||
with the corresponding column type for the offset column of the collection parent field. | ||
All child fields use the default column encoding `Int32`. | ||
|
||
## Entries | ||
|
||
1. Single-element sets, with ascending values | ||
2. Empty sets | ||
3. Increasing number of elements in the set: | ||
one element in the first field, two elements in the second field, etc. | ||
hahnjo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <ROOT/REntry.hxx> | ||
#include <ROOT/RNTupleReader.hxx> | ||
|
||
using ROOT::Experimental::REntry; | ||
using ROOT::Experimental::RNTupleReader; | ||
|
||
#include <cstdint> | ||
#include <fstream> | ||
#include <ostream> | ||
#include <set> | ||
#include <string> | ||
#include <string_view> | ||
|
||
using Multiset = std::multiset<std::int32_t>; | ||
|
||
static void PrintMultisetValue(const REntry &entry, std::string_view name, | ||
std::ostream &os, bool last = false) { | ||
Multiset &value = *entry.GetPtr<Multiset>(name); | ||
os << " \"" << name << "\": ["; | ||
bool first = true; | ||
for (auto element : value) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
os << ","; | ||
} | ||
os << "\n " << element; | ||
} | ||
if (!value.empty()) { | ||
os << "\n "; | ||
} | ||
os << "]"; | ||
if (!last) { | ||
os << ","; | ||
} | ||
os << "\n"; | ||
} | ||
|
||
void read(std::string_view input = "types.multiset.fundamental.root", | ||
std::string_view output = "types.multiset.fundamental.json") { | ||
std::ofstream os(std::string{output}); | ||
os << "[\n"; | ||
|
||
auto reader = 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"; | ||
|
||
PrintMultisetValue(entry, "Index32", os); | ||
PrintMultisetValue(entry, "Index64", os); | ||
PrintMultisetValue(entry, "SplitIndex32", os); | ||
PrintMultisetValue(entry, "SplitIndex64", os, /*last=*/true); | ||
|
||
os << " }"; | ||
// Newline is intentionally missing, may need to print a comma before the | ||
// next entry. | ||
} | ||
os << "\n"; | ||
os << "]\n"; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#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 <cstdint> | ||
#include <memory> | ||
#include <set> | ||
#include <string_view> | ||
|
||
using Multiset = std::multiset<std::int32_t>; | ||
|
||
static std::shared_ptr<Multiset> MakeMultisetField(RNTupleModel &model, | ||
std::string_view name, | ||
EColumnType indexType) { | ||
auto field = std::make_unique<RField<Multiset>>(name); | ||
field->SetColumnRepresentatives({{indexType}}); | ||
model.AddField(std::move(field)); | ||
return model.GetDefaultEntry().GetPtr<Multiset>(name); | ||
} | ||
|
||
void write(std::string_view filename = "types.multiset.fundamental.root") { | ||
auto model = RNTupleModel::Create(); | ||
|
||
// Non-split index encoding | ||
auto Index32 = MakeMultisetField(*model, "Index32", EColumnType::kIndex32); | ||
auto Index64 = MakeMultisetField(*model, "Index64", EColumnType::kIndex64); | ||
|
||
// Split index encoding | ||
auto SplitIndex32 = | ||
MakeMultisetField(*model, "SplitIndex32", EColumnType::kSplitIndex32); | ||
auto SplitIndex64 = | ||
MakeMultisetField(*model, "SplitIndex64", EColumnType::kSplitIndex64); | ||
|
||
RNTupleWriteOptions options; | ||
options.SetCompression(0); | ||
auto writer = | ||
RNTupleWriter::Recreate(std::move(model), "ntpl", filename, options); | ||
|
||
// First entry: single-element sets, with ascending values | ||
*Index32 = {1}; | ||
*Index64 = {2}; | ||
*SplitIndex32 = {3}; | ||
*SplitIndex64 = {4}; | ||
writer->Fill(); | ||
|
||
// Second entry: empty sets | ||
*Index32 = {}; | ||
*Index64 = {}; | ||
*SplitIndex32 = {}; | ||
*SplitIndex64 = {}; | ||
writer->Fill(); | ||
|
||
// Third entry: increasing number of elements in the set | ||
*Index32 = {1}; | ||
*Index64 = {2, 3}; | ||
*SplitIndex32 = {4, 5, 6}; | ||
*SplitIndex64 = {7, 8, 9, 10}; | ||
writer->Fill(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <cstdint> | ||
#include <set> | ||
|
||
#ifdef __CLING__ | ||
#pragma link C++ class std::multiset<std::multiset<std::int32_t>>+; | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CXX=g++ | ||
CXXFLAGS_ROOT=$(shell root-config --cflags) | ||
ifeq ($(CXXFLAGS_ROOT),) | ||
$(error cannot find root-config: make sure to source thisroot.sh) | ||
endif | ||
CXXFLAGS=-Wall $(CXXFLAGS_ROOT) | ||
LDFLAGS=$(shell root-config --libs) | ||
|
||
.PHONY: all clean | ||
|
||
all: NestedMultiset.cxx libNestedMultiset.so | ||
|
||
NestedMultiset.cxx: NestedMultiset.hxx LinkDef.h | ||
rootcling -f $@ $^ | ||
|
||
libNestedMultiset.so: NestedMultiset.cxx | ||
$(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
||
clean: | ||
rm -f NestedMultiset.cxx NestedMultiset_rdict.pcm libNestedMultiset.so |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <set> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# `std::multiset<std::multiset<std::int32_t>>` | ||
|
||
## Fields | ||
|
||
* `[Split]Index{32,64}` | ||
|
||
with the corresponding column type for the offset column of the two collection parent fields. | ||
All child fields use the default column encoding `Int32`. | ||
|
||
## Entries | ||
|
||
1. Single-element sets, with ascending values | ||
2. Empty sets | ||
3. Increasing number of elements in the outer set, with arbitrary lengths of the inner sets | ||
|
||
## Dictionaries | ||
|
||
These tests require ROOT dictionaries, which can be generated with the provided `Makefile` in this directory. This will create a `libNestedMultiset` shared object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <ROOT/REntry.hxx> | ||
#include <ROOT/RNTupleReader.hxx> | ||
|
||
using ROOT::Experimental::REntry; | ||
using ROOT::Experimental::RNTupleReader; | ||
|
||
#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 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 = 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"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.