Skip to content

Commit

Permalink
[ntuple] Handle processors created from bare models
Browse files Browse the repository at this point in the history
  • Loading branch information
enirolf committed Jul 8, 2024
1 parent 508a2b8 commit fcf76de
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
17 changes: 11 additions & 6 deletions tree/ntuple/v7/src/RNTupleProcessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,19 @@ ROOT::Experimental::Internal::RNTupleProcessor::RNTupleProcessor(const std::vect
model->Freeze();
fEntry = model->CreateEntry();

// Use the value pointers from the model's in the entry managed by the processor. This way, the pointers returned by
// RNTupleModel::MakeField can be used in the processor loop to access the corresponding field values.
for (const auto &value : model->GetDefaultEntry()) {
for (const auto &value : *fEntry) {
auto &field = value.GetField();
auto token = fEntry->GetToken(field.GetFieldName());
auto valuePtr = value.GetPtr<void>();
fEntry->BindValue(token, valuePtr);
fFieldContexts.emplace_back(field.Clone(field.GetFieldName()), fEntry->GetToken(field.GetFieldName()));

// If the model has a default entry, use the value pointers from the entry in the entry managed by the
// processor. This way, the pointers returned by RNTupleModel::MakeField can be used in the processor loop to
// access the corresponding field values.
if (!model->IsBare()) {
auto valuePtr = model->GetDefaultEntry().GetPtr<void>(token);
fEntry->BindValue(token, valuePtr);
}

fFieldContexts.emplace_back(field.Clone(field.GetFieldName()), token);
}

ConnectFields();
Expand Down
29 changes: 28 additions & 1 deletion tree/ntuple/v7/test/ntuple_processor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(RNTupleProcessor, Basic)
EXPECT_EQ(nEntries, 10);
}

TEST(RNTupleProcessor, BasicWithModel)
TEST(RNTupleProcessor, WithModel)
{
FileRaii fileGuard("test_ntuple_processor_basic_with_model.root");
{
Expand Down Expand Up @@ -68,6 +68,33 @@ TEST(RNTupleProcessor, BasicWithModel)
}
}

TEST(RNTupleProcessor, WithBareModel)
{
FileRaii fileGuard("test_ntuple_processor_basic_with_model.root");
{
auto model = RNTupleModel::Create();
auto fldX = model->MakeField<float>("x");
auto fldY = model->MakeField<float>("y");
auto fldZ = model->MakeField<float>("z");
auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", fileGuard.GetPath());

for (unsigned i = 0; i < 10; ++i) {
*fldX = static_cast<float>(i);
*fldY = static_cast<float>(i) * 2.f;
*fldZ = static_cast<float>(i) * 3.f;
ntuple->Fill();
}
}

auto model = RNTupleModel::CreateBare();
model->MakeField<float>("y");
std::vector<RNTupleSourceSpec> ntuples = {{"ntuple", fileGuard.GetPath()}};

for (const auto &entry : RNTupleProcessor(ntuples, std::move(model))) {
EXPECT_EQ(static_cast<float>(entry.GetGlobalEntryIndex()) * 2.f, *entry->GetPtr<float>("y"));
}
}

TEST(RNTupleProcessor, SimpleChain)
{
FileRaii fileGuard1("test_ntuple_processor_simple_chain1.root");
Expand Down

0 comments on commit fcf76de

Please sign in to comment.