How to write a branch of `RVec<std::array<`?

Hi @cxwx1,

thanks for reaching out!

This is another case of missing dictionaries for your custom collection class, as it has also happened in the past, for example here and here.

So you need to generate dictionaries for your class. I did it like this:

#include <TFile.h>
#include <TTree.h>
#include <ROOT/RVec.hxx>
#include <array>
#include <vector>
#include <TInterpreter.h>

void p1_tree() {
  TFile f("p1_tree.root", "RECREATE");
  TTree t("t", "t");
  std::vector<float> a = {1,2,3};
  t.Branch("a", &a);
  gInterpreter->GenerateDictionary("ROOT::RVec<vector<float> >","vector;ROOT/RVec.hxx");
  ROOT::RVec<std::vector<float>> b = {{1,2,3},{4,5,6}};
  t.Branch("b", &b);
  t.Fill();
  b.push_back({7, 8, 9});
  t.Fill();
  t.Write();
  f.Close();
}
2 Likes