-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add GH16805 RNTupleProcessor regression test #22644
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
Open
matildamarjamaki
wants to merge
3
commits into
root-project:master
Choose a base branch
from
matildamarjamaki:gh16805-rntuple-processor-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+154
−0
Open
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 |
|---|---|---|
|
|
@@ -798,3 +798,157 @@ TEST_F(RNTupleProcessorTest, PrintStructureJoinedChainAsymmetric) | |
| " +-----------------------------+\n"; | ||
| EXPECT_EQ(exp2, os2.str()); | ||
| } | ||
|
|
||
| // This test is a translation using RNTupleProcessor of the test | ||
| // introduced by https://github.com/root-project/root/pull/19322, | ||
| // to ensure that the TTree friendship mechanism works equivalently | ||
| // with the RNTuple join mechanism. | ||
| class GH16805ProcessorTest : public testing::Test { | ||
| protected: | ||
| const std::vector<std::string> fStepZeroFiles{ | ||
| "gh16805_rntuple_stepzero_0.root", | ||
| "gh16805_rntuple_stepzero_1.root" | ||
| }; | ||
|
|
||
| const std::vector<std::string> fFriendFiles{ | ||
| "gh16805_rntuple_friend_0.root", | ||
| "gh16805_rntuple_friend_1.root", | ||
| "gh16805_rntuple_friend_2.root" | ||
|
Comment on lines
+814
to
+816
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure consistency between terms, I would be in favor to use only "join" when talking about RNTuple, instead of "friends". |
||
| }; | ||
|
|
||
| const std::string fStepOneFile = "gh16805_rntuple_stepone.root"; | ||
|
|
||
| void WriteStepZero(const std::string &fileName, int begin, int end) | ||
| { | ||
| auto model = ROOT::RNTupleModel::Create(); | ||
|
|
||
| auto br1 = model->MakeField<int>("stepZeroBr1"); | ||
| auto br2 = model->MakeField<int>("stepZeroBr2"); | ||
|
|
||
| auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "stepzero", fileName); | ||
|
|
||
| for (int i = begin; i < end; ++i) { | ||
| *br1 = i; | ||
| *br2 = 2 * i; | ||
| writer->Fill(); | ||
| } | ||
| } | ||
|
|
||
| void WriteStepOne(const std::string &fileName, int begin, int end) | ||
| { | ||
| auto model = ROOT::RNTupleModel::Create(); | ||
|
|
||
| auto br1 = model->MakeField<int>("stepOneBr1"); | ||
|
|
||
| auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "stepone", fileName); | ||
|
|
||
| for (int i = begin; i < end; ++i) { | ||
| *br1 = i; | ||
| writer->Fill(); | ||
| } | ||
| } | ||
|
|
||
| void WriteFriend(const std::string &fileName, int begin, int end) | ||
| { | ||
| auto model = ROOT::RNTupleModel::Create(); | ||
|
|
||
| auto br1 = model->MakeField<int>("friendBr1"); | ||
| auto br2 = model->MakeField<int>("friendBr2"); | ||
|
|
||
| auto writer = ROOT::RNTupleWriter::Recreate(std::move(model), "topLevelFriend", fileName); | ||
|
|
||
| for (int i = begin; i < end; ++i) { | ||
| *br1 = i; | ||
| *br2 = 2 * i; | ||
| writer->Fill(); | ||
| } | ||
| } | ||
|
|
||
| void SetUp() override | ||
| { | ||
| WriteStepZero(fStepZeroFiles[0], 0, 10); | ||
| WriteStepZero(fStepZeroFiles[1], 10, 20); | ||
|
|
||
| WriteFriend(fFriendFiles[0], 200, 207); | ||
| WriteFriend(fFriendFiles[1], 207, 214); | ||
| WriteFriend(fFriendFiles[2], 214, 220); | ||
|
|
||
| WriteStepOne(fStepOneFile, 100, 120); | ||
| } | ||
|
|
||
| void TearDown() override | ||
| { | ||
| for (const auto &f : fStepZeroFiles) | ||
| std::remove(f.c_str()); | ||
|
|
||
| for (const auto &f : fFriendFiles) | ||
| std::remove(f.c_str()); | ||
|
|
||
| std::remove(fStepOneFile.c_str()); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(GH16805ProcessorTest, JoinReading) | ||
| { | ||
| std::vector<RNTupleOpenSpec> stepOneSpecs{ | ||
| {"stepone", fStepOneFile} | ||
| }; | ||
|
|
||
| std::vector<RNTupleOpenSpec> stepZeroSpecs{ | ||
| {"stepzero", fStepZeroFiles[0]}, | ||
| {"stepzero", fStepZeroFiles[1]} | ||
| }; | ||
|
|
||
| std::vector<RNTupleOpenSpec> friendSpecs{ | ||
| {"topLevelFriend", fFriendFiles[0]}, | ||
| {"topLevelFriend", fFriendFiles[1]}, | ||
| {"topLevelFriend", fFriendFiles[2]} | ||
| }; | ||
|
|
||
| auto stepOneProc = | ||
| RNTupleProcessor::CreateChain(stepOneSpecs, "stepone"); | ||
|
|
||
| auto stepZeroProc = | ||
| RNTupleProcessor::CreateChain(stepZeroSpecs, "stepzero"); | ||
|
|
||
| auto friendProc = | ||
| RNTupleProcessor::CreateChain(friendSpecs, "topLevelFriend"); | ||
|
|
||
| auto joinedWithFriend = | ||
| RNTupleProcessor::CreateJoin( | ||
| std::move(stepOneProc), | ||
| std::move(friendProc), | ||
| {} | ||
| ); | ||
|
|
||
| auto joinedAll = | ||
| RNTupleProcessor::CreateJoin( | ||
| std::move(joinedWithFriend), | ||
| std::move(stepZeroProc), | ||
| {} | ||
| ); | ||
|
|
||
| auto stepOneBr1 = joinedAll->RequestField<int>("stepOneBr1"); | ||
| auto friendBr1 = joinedAll->RequestField<int>("topLevelFriend.friendBr1"); | ||
| auto friendBr2 = joinedAll->RequestField<int>("topLevelFriend.friendBr2"); | ||
| auto stepZeroBr1 = joinedAll->RequestField<int>("stepzero.stepZeroBr1"); | ||
| auto stepZeroBr2 = joinedAll->RequestField<int>("stepzero.stepZeroBr2"); | ||
|
|
||
| std::size_t i = 0; | ||
|
|
||
| for (auto idx : *joinedAll) { | ||
| EXPECT_EQ(i, idx); | ||
|
|
||
| EXPECT_EQ(static_cast<int>(i), *stepZeroBr1); | ||
| EXPECT_EQ(static_cast<int>(2 * i), *stepZeroBr2); | ||
| EXPECT_EQ(static_cast<int>(100 + i), *stepOneBr1); | ||
| EXPECT_EQ(static_cast<int>(200 + i), *friendBr1); | ||
| EXPECT_EQ(static_cast<int>(2 * (200 + i)), *friendBr2); | ||
|
|
||
| ++i; | ||
| } | ||
|
|
||
| EXPECT_EQ(20u, i); | ||
| EXPECT_EQ(20u, joinedAll->GetNEntriesProcessed()); | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it would be good to reference the original context for the TTree equivalent test. Maybe add a comment just before the class name