Creating RNtuple with an array of shared_pointer Fields?

Hi all,

I’ve decided to try the new RNTuple feature and I am trying to rewrite my analysis code, which is based on TTree.

I have the code where I create a lot of TBranches in a for loop:

std::vector<float> _resolutions = {0, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300};
std::vector<float> _results(15);

for (size_t i = 0; i < _resolutions.size(); i++){
    auto name = ("result"+std::to_string( int(_resolutions[i]) ) ).c_str();
     _tree->Branch( name, &(_results[i]) );
. . .

Is it possible to achieve something similar using RNTuples?

Or should each element of _results be an explicitly separate variable?


ROOT Version: 6.28

Hi Bohdan,

Great that you try out RNTuple!

One way to transform the code to RNTuple is

using ROOT::Experimental::RNTupleModel;

std::vector<float> _resolutions = ...
std::vector<std::shared_ptr<float>> _results(15);

auto model = RNTupleModel::Create();
model->AddField(std::make_unique<ROOT::Experimental::RField<float>>(name /* field name */));
model->GetDefaultEntry().BindValue(name, _results[0]);

/* And so on for the other fields */

This code uses the latest RNTuple interfaces which will be released in ROOT 6.32. If you need code for ROOT 6.28, please let me know; the interface works differently there.

Hi @jblomer,

Thanks for the info!
My software stack still uses v6.28, so it would be helpful to see how it is done there.
6.28/04 or 6.28/10

If it is too much of a difference, I can wait until the new release with ROOT 6.32

Looking into it, the difference is rather substantial, and things improved meanwhile. Please let me know by private message if you’d like to continue with the experiments on the 6.28 branch. Otherwise I’d suggest to continue on the master branch or on 6.32 once released.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.