-
Notifications
You must be signed in to change notification settings - Fork 4
Add tests for user-defined types #57
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
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ | |
| *.pcm | ||
| *.so | ||
| Nested*.cxx | ||
| User*.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| CXX=g++ | ||
| CXXFLAGS_ROOT=$(shell root-config --cflags) | ||
| ifeq ($(CXXFLAGS_ROOT),) | ||
| $(error cannot find root-config: make sure to source thisroot.sh) | ||
| ROOT_CONFIG ?= $(shell which root-config) | ||
| ifeq ($(ROOT_CONFIG),) | ||
| $(error Could not find root-config) | ||
| endif | ||
| CXXFLAGS=-Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS=$(shell root-config --libs) | ||
| ROOTCLING ?= $(shell which rootcling) | ||
| ifeq ($(ROOTCLING),) | ||
| $(error Could not find rootcling) | ||
| endif | ||
|
|
||
| CXX := $(shell $(ROOT_CONFIG) --cxx) | ||
| CXXFLAGS_ROOT := $(shell $(ROOT_CONFIG) --cflags) | ||
| CXXFLAGS := -Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS := $(shell $(ROOT_CONFIG) --libs) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: NestedMultiset.cxx libNestedMultiset.so | ||
| all: libNestedMultiset.so | ||
|
|
||
| NestedMultiset.cxx: NestedMultiset.hxx LinkDef.h | ||
| rootcling -f $@ $^ | ||
| $(ROOTCLING) -f $@ $^ | ||
|
|
||
| libNestedMultiset.so: NestedMultiset.cxx | ||
| $(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
|
||
| clean: | ||
| rm -f NestedMultiset.cxx NestedMultiset_rdict.pcm libNestedMultiset.so | ||
| $(RM) 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 |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| CXX=g++ | ||
| CXXFLAGS_ROOT=$(shell root-config --cflags) | ||
| ifeq ($(CXXFLAGS_ROOT),) | ||
| $(error cannot find root-config: make sure to source thisroot.sh) | ||
| ROOT_CONFIG ?= $(shell which root-config) | ||
| ifeq ($(ROOT_CONFIG),) | ||
| $(error Could not find root-config) | ||
| endif | ||
| CXXFLAGS=-Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS=$(shell root-config --libs) | ||
| ROOTCLING ?= $(shell which rootcling) | ||
| ifeq ($(ROOTCLING),) | ||
| $(error Could not find rootcling) | ||
| endif | ||
|
|
||
| CXX := $(shell $(ROOT_CONFIG) --cxx) | ||
| CXXFLAGS_ROOT := $(shell $(ROOT_CONFIG) --cflags) | ||
| CXXFLAGS := -Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS := $(shell $(ROOT_CONFIG) --libs) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: NestedSet.cxx libNestedSet.so | ||
| all: libNestedSet.so | ||
|
|
||
| NestedSet.cxx: NestedSet.hxx LinkDef.h | ||
| rootcling -f $@ $^ | ||
| $(ROOTCLING) -f $@ $^ | ||
|
|
||
| libNestedSet.so: NestedSet.cxx | ||
| $(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
|
||
| clean: | ||
| rm -f NestedSet.cxx NestedSet_rdict.pcm libNestedSet.so | ||
| $(RM) NestedSet.cxx NestedSet_rdict.pcm libNestedSet.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 |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| CXX=g++ | ||
| CXXFLAGS_ROOT=$(shell root-config --cflags) | ||
| ifeq ($(CXXFLAGS_ROOT),) | ||
| $(error cannot find root-config: make sure to source thisroot.sh) | ||
| ROOT_CONFIG ?= $(shell which root-config) | ||
| ifeq ($(ROOT_CONFIG),) | ||
| $(error Could not find root-config) | ||
| endif | ||
| CXXFLAGS=-Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS=$(shell root-config --libs) | ||
| ROOTCLING ?= $(shell which rootcling) | ||
| ifeq ($(ROOTCLING),) | ||
| $(error Could not find rootcling) | ||
| endif | ||
|
|
||
| CXX := $(shell $(ROOT_CONFIG) --cxx) | ||
| CXXFLAGS_ROOT := $(shell $(ROOT_CONFIG) --cflags) | ||
| CXXFLAGS := -Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS := $(shell $(ROOT_CONFIG) --libs) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: NestedUnorderedMultiset.cxx libNestedUnorderedMultiset.so | ||
| all: libNestedUnorderedMultiset.so | ||
|
|
||
| NestedUnorderedMultiset.cxx: NestedUnorderedMultiset.hxx LinkDef.h | ||
| rootcling -f $@ $^ | ||
| $(ROOTCLING) -f $@ $^ | ||
|
|
||
| libNestedUnorderedMultiset.so: NestedUnorderedMultiset.cxx | ||
| $(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
|
||
| clean: | ||
| rm -f NestedUnorderedMultiset.cxx NestedUnorderedMultiset_rdict.pcm libNestedUnorderedMultiset.so | ||
| $(RM) NestedUnorderedMultiset.cxx NestedUnorderedMultiset_rdict.pcm libNestedUnorderedMultiset.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 |
|---|---|---|
| @@ -1,20 +1,26 @@ | ||
| CXX=g++ | ||
| CXXFLAGS_ROOT=$(shell root-config --cflags) | ||
| ifeq ($(CXXFLAGS_ROOT),) | ||
| $(error cannot find root-config: make sure to source thisroot.sh) | ||
| ROOT_CONFIG ?= $(shell which root-config) | ||
| ifeq ($(ROOT_CONFIG),) | ||
| $(error Could not find root-config) | ||
| endif | ||
| CXXFLAGS=-Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS=$(shell root-config --libs) | ||
| ROOTCLING ?= $(shell which rootcling) | ||
| ifeq ($(ROOTCLING),) | ||
| $(error Could not find rootcling) | ||
| endif | ||
|
|
||
| CXX := $(shell $(ROOT_CONFIG) --cxx) | ||
| CXXFLAGS_ROOT := $(shell $(ROOT_CONFIG) --cflags) | ||
| CXXFLAGS := -Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS := $(shell $(ROOT_CONFIG) --libs) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: NestedUnorderedSet.cxx libNestedUnorderedSet.so | ||
| all: libNestedUnorderedSet.so | ||
|
|
||
| NestedUnorderedSet.cxx: NestedUnorderedSet.hxx LinkDef.h | ||
| rootcling -f $@ $^ | ||
| $(ROOTCLING) -f $@ $^ | ||
|
|
||
| libNestedUnorderedSet.so: NestedUnorderedSet.cxx | ||
| $(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
|
||
| clean: | ||
| rm -f NestedUnorderedSet.cxx NestedUnorderedSet_rdict.pcm libNestedUnorderedSet.so | ||
| $(RM) NestedUnorderedSet.cxx NestedUnorderedSet_rdict.pcm libNestedUnorderedSet.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 @@ | ||
| # User-defined Types | ||
|
|
||
| * [`class`]: user-defined class(es) | ||
| * [`enum`]: user-defined enum(s) |
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,12 @@ | ||
| #include <cstdint> | ||
| #include <string> | ||
| #include <variant> | ||
|
|
||
| #ifdef __CLING__ | ||
| #pragma link C++ class Base+; | ||
| #pragma link C++ class Nested+; | ||
| // ROOT does not (yet) support std::variant, but this line silences a warning | ||
| // that fVariant would not be saved (which is not true for RNTuple). | ||
| #pragma link C++ class std::variant<std::int32_t, std::string>; | ||
| #pragma link C++ class User+; | ||
| #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,26 @@ | ||
| ROOT_CONFIG ?= $(shell which root-config) | ||
| ifeq ($(ROOT_CONFIG),) | ||
| $(error Could not find root-config) | ||
| endif | ||
| ROOTCLING ?= $(shell which rootcling) | ||
| ifeq ($(ROOTCLING),) | ||
| $(error Could not find rootcling) | ||
| endif | ||
|
|
||
| CXX := $(shell $(ROOT_CONFIG) --cxx) | ||
| CXXFLAGS_ROOT := $(shell $(ROOT_CONFIG) --cflags) | ||
| CXXFLAGS := -Wall $(CXXFLAGS_ROOT) | ||
| LDFLAGS := $(shell $(ROOT_CONFIG) --libs) | ||
|
|
||
| .PHONY: all clean | ||
|
|
||
| all: libUserClass.so | ||
|
|
||
| UserClass.cxx: UserClass.hxx LinkDef.h | ||
| $(ROOTCLING) -f $@ $^ | ||
|
|
||
| libUserClass.so: UserClass.cxx | ||
| $(CXX) -shared -fPIC -o $@ $^ $(CXXFLAGS) $(LDFLAGS) | ||
|
|
||
| clean: | ||
| $(RM) UserClass.cxx UserClass_rdict.pcm libUserClass.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,20 @@ | ||
| # User-defined class(es) | ||
|
|
||
| ## Fields | ||
|
|
||
| * `f` of type `User` with the following subfields: | ||
| * `:_0` of type `Base` | ||
| * `fInt` of type `std::int32_t` | ||
| * `fString` of type `std::string` | ||
| * `fVariant` of type `std::variant<std::int32_t, std::string>` | ||
| * `fVector` of type `std::vector<std::int32_t>` | ||
| * `fNested` of type `Nested` | ||
| * `fInt` of type `std::int32_t` | ||
| * `VectorUser` of type `std::vector<User>` | ||
|
|
||
| with the default column types. | ||
|
|
||
| ## Entries | ||
|
|
||
| 1. Simple values | ||
| 2. Zero / empty values |
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,27 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| using Variant = std::variant<std::int32_t, std::string>; | ||
| using Vector = std::vector<std::int32_t>; | ||
|
|
||
| class Base { | ||
| public: | ||
| std::int32_t fInt; | ||
| }; | ||
|
|
||
| class Nested { | ||
| public: | ||
| std::int32_t fInt; | ||
| }; | ||
|
|
||
| class User : public Base { | ||
| public: | ||
| std::string fString; | ||
| Variant fVariant; | ||
| Vector fVector; | ||
| Nested fNested; | ||
| }; |
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,122 @@ | ||
| #include <ROOT/REntry.hxx> | ||
| #include <ROOT/RNTupleReader.hxx> | ||
|
|
||
| using ROOT::Experimental::REntry; | ||
| using ROOT::Experimental::RNTupleReader; | ||
|
|
||
| #include <TSystem.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <fstream> | ||
| #include <ostream> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <variant> | ||
| #include <vector> | ||
|
|
||
| #include "UserClass.hxx" | ||
|
|
||
| static void PrintUserMembers(const User &value, std::ostream &os, | ||
| std::string_view indent) { | ||
| os << indent << "\":_0\": {\n"; | ||
| os << indent << " \"fInt\": " << value.fInt << "\n"; | ||
| os << indent << "},\n"; | ||
| os << indent << "\"fString\": \"" << value.fString << "\",\n"; | ||
|
|
||
| os << indent << "\"fVariant\": "; | ||
| if (value.fVariant.index() == 0) { | ||
| os << std::get<std::int32_t>(value.fVariant); | ||
| } else if (value.fVariant.index() == 1) { | ||
| os << "\"" << std::get<std::string>(value.fVariant) << "\""; | ||
| } | ||
| os << ",\n"; | ||
|
|
||
| os << indent << "\"fVector\": ["; | ||
| bool first = true; | ||
| for (auto element : value.fVector) { | ||
| if (first) { | ||
| first = false; | ||
| } else { | ||
| os << ","; | ||
| } | ||
| os << "\n" << indent << " " << element; | ||
| } | ||
| if (!value.fVector.empty()) { | ||
| os << "\n" << indent; | ||
| } | ||
| os << "],\n"; | ||
|
|
||
| os << indent << "\"fNested\": {\n"; | ||
| os << indent << " \"fInt\": " << value.fNested.fInt << "\n"; | ||
| os << indent << "}\n"; | ||
| } | ||
|
|
||
| static void PrintUserValue(const REntry &entry, std::string_view name, | ||
| std::ostream &os, bool last = false) { | ||
| auto &value = *entry.GetPtr<User>(name); | ||
| os << " \"" << name << "\": {\n"; | ||
| PrintUserMembers(value, os, " "); | ||
| os << " }"; | ||
| if (!last) { | ||
| os << ","; | ||
| } | ||
| os << "\n"; | ||
| } | ||
|
|
||
| static void PrintUserVector(const REntry &entry, std::string_view name, | ||
| std::ostream &os, bool last = false) { | ||
| auto &vector = *entry.GetPtr<std::vector<User>>(name); | ||
| os << " \"" << name << "\": ["; | ||
| bool first = true; | ||
| for (const auto &element : vector) { | ||
| if (first) { | ||
| first = false; | ||
| } else { | ||
| os << ","; | ||
| } | ||
| os << "\n {\n"; | ||
| PrintUserMembers(element, os, " "); | ||
| os << " }"; | ||
| } | ||
| if (!vector.empty()) { | ||
| os << "\n "; | ||
| } | ||
| os << "]"; | ||
| if (!last) { | ||
| os << ","; | ||
| } | ||
| os << "\n"; | ||
| } | ||
|
|
||
| void read(std::string_view input = "types.user.class.root", | ||
| std::string_view output = "types.user.class.json") { | ||
| if (gSystem->Load("libUserClass") == -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"; | ||
|
|
||
| PrintUserValue(entry, "f", os); | ||
| PrintUserVector(entry, "Vector", 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.