Skip to content
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

Cannot access subfields through RNTupleProcessor #16856

Open
1 task done
enirolf opened this issue Nov 7, 2024 · 0 comments
Open
1 task done

Cannot access subfields through RNTupleProcessor #16856

enirolf opened this issue Nov 7, 2024 · 0 comments
Assignees

Comments

@enirolf
Copy link
Contributor

enirolf commented Nov 7, 2024

Check duplicate issues.

  • Checked for duplicates

Description

Subfields that have been registered through RNTupleModel::RegisterModel cannot be accessed through the RNTupleProcessor when it has been created with such a model. To enable this, the subfield's RFieldContext will need to be somehow linked to that of its parent, so its fieldId can be properly retrieved in the processor's ConnectField method.

Reproducer

using ROOT::Experimental::RFieldBase;
using ROOT::Experimental::RNTupleModel;
using ROOT::Experimental::RNTupleOpenSpec;
using ROOT::Experimental::RNTupleProcessor;
using ROOT::Experimental::RNTupleWriter;

struct MyStruct {
  float a;
};

void ntuple_proc_subfields() {
  {
    auto model = RNTupleModel::Create();
    auto myStruct = model->MakeField<MyStruct>("struct");
    auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple",
                                          "ntuple_proc_subfields1.root");
    *myStruct = MyStruct{1.f};
    ntuple->Fill();
  }
  {
    auto model = RNTupleModel::Create();
    auto myStruct = model->MakeField<MyStruct>("struct", MyStruct{2.f});
    auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple",
                                          "ntuple_proc_subfields2.root");
    *myStruct = MyStruct{2.f};
    ntuple->Fill();
  }

  auto model = RNTupleModel::Create();
  auto structField = RFieldBase::Create("struct", "MyStruct").Unwrap();
  model->AddField(std::move(structField));
  model->RegisterSubfield("struct.a");

  std::vector<RNTupleOpenSpec> ntuples = {{"ntuple", "ntuple_proc_subfields1.root"},
                                          {"ntuple", "ntuple_proc_subfields2.root"}};

  auto proc = RNTupleProcessor::CreateChain(ntuples, std::move(model));
  for (const auto &entry : *proc) {
    std::cout << entry.GetPtr<float>("struct.a") << std::endl;
  }
}

Currently this throws an RException with the message field "a" not found in current RNTuple. It should run and print the values instead.

ROOT version

any

Installation method

any

Operating system

any

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant