-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `RNTupleSingleProcessor` processes one single RNTuple, using the same interfaces as the `RNTupleChainProcessor` and `RNTupleJoinProcessor`. The point of adding this processor is that this way, the other processors can use a unified interface for loading entries, without having to know whether they are dealing with a single RNTuple or a composed one.
- Loading branch information
Showing
5 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,98 @@ | ||
#include "ntuple_test.hxx" | ||
|
||
#include <ROOT/RNTupleProcessor.hxx> | ||
|
||
class RNTupleProcessorTest : public testing::Test { | ||
protected: | ||
const std::string fFileName = "test_ntuple_processor.root"; | ||
const std::string fNTupleName = "ntuple"; | ||
|
||
void SetUp() override | ||
{ | ||
auto model = RNTupleModel::Create(); | ||
auto fldX = model->MakeField<float>("x"); | ||
auto fldY = model->MakeField<std::vector<float>>("y"); | ||
auto ntuple = RNTupleWriter::Recreate(std::move(model), fNTupleName, fFileName); | ||
|
||
for (unsigned i = 0; i < 5; i++) { | ||
*fldX = static_cast<float>(i); | ||
*fldY = {static_cast<float>(i), static_cast<float>(i * 2)}; | ||
ntuple->Fill(); | ||
} | ||
} | ||
}; | ||
|
||
TEST_F(RNTupleProcessorTest, Base) | ||
{ | ||
RNTupleOpenSpec ntuple{fNTupleName, fFileName}; | ||
auto proc = RNTupleProcessor::Create(ntuple); | ||
|
||
int nEntries = 0; | ||
|
||
for (const auto &entry : *proc) { | ||
EXPECT_FLOAT_EQ(static_cast<float>(proc->GetNEntriesProcessed()), *entry.GetPtr<float>("x")); | ||
|
||
std::vector<float> yExp{static_cast<float>(proc->GetNEntriesProcessed()), | ||
static_cast<float>(proc->GetNEntriesProcessed() * 2)}; | ||
EXPECT_EQ(yExp, *entry.GetPtr<std::vector<float>>("y")); | ||
|
||
EXPECT_EQ(proc->GetNEntriesProcessed(), proc->GetLocalEntryNumber()); | ||
++nEntries; | ||
} | ||
EXPECT_EQ(nEntries, 5); | ||
EXPECT_EQ(nEntries, proc->GetNEntriesProcessed()); | ||
} | ||
|
||
TEST_F(RNTupleProcessorTest, BaseWithModel) | ||
{ | ||
RNTupleOpenSpec ntuple{fNTupleName, fFileName}; | ||
|
||
auto model = RNTupleModel::Create(); | ||
auto fldX = model->MakeField<float>("x"); | ||
|
||
auto proc = RNTupleProcessor::Create(ntuple, *model); | ||
|
||
int nEntries = 0; | ||
|
||
for (const auto &entry : *proc) { | ||
EXPECT_FLOAT_EQ(static_cast<float>(proc->GetNEntriesProcessed()), *fldX); | ||
EXPECT_EQ(proc->GetNEntriesProcessed(), proc->GetLocalEntryNumber()); | ||
|
||
try { | ||
entry.GetPtr<std::vector<float>>("y"); | ||
FAIL() << "fields not present in the model passed to the processor shouldn't be readable"; | ||
} catch (const RException &err) { | ||
EXPECT_THAT(err.what(), testing::HasSubstr("invalid field name: y")); | ||
} | ||
++nEntries; | ||
} | ||
EXPECT_EQ(nEntries, 5); | ||
EXPECT_EQ(nEntries, proc->GetNEntriesProcessed()); | ||
} | ||
|
||
TEST_F(RNTupleProcessorTest, BaseWithBareModel) | ||
{ | ||
RNTupleOpenSpec ntuple{fNTupleName, fFileName}; | ||
|
||
auto model = RNTupleModel::CreateBare(); | ||
model->MakeField<float>("x"); | ||
|
||
auto proc = RNTupleProcessor::Create(ntuple, *model); | ||
|
||
int nEntries = 0; | ||
|
||
for (const auto &entry : *proc) { | ||
EXPECT_FLOAT_EQ(static_cast<float>(proc->GetNEntriesProcessed()), *entry.GetPtr<float>("x")); | ||
EXPECT_EQ(proc->GetNEntriesProcessed(), proc->GetLocalEntryNumber()); | ||
|
||
try { | ||
entry.GetPtr<std::vector<float>>("y"); | ||
FAIL() << "fields not present in the model passed to the processor shouldn't be readable"; | ||
} catch (const RException &err) { | ||
EXPECT_THAT(err.what(), testing::HasSubstr("invalid field name: y")); | ||
} | ||
++nEntries; | ||
} | ||
EXPECT_EQ(nEntries, 5); | ||
EXPECT_EQ(nEntries, proc->GetNEntriesProcessed()); | ||
} |