Hi @eguiraud,
Thanks for your suggestions. I have written an minimal example that demonstrates the problem and attached it to this message.
example_tbranchobject_problem.C (1.5 KB)
// This script produces the following output:
//
// root [0]
// Processing example_tbranchobject_problem.C...
// a is a TBranchElement
// b is a TBranchElement
// c is a TBranchObject
// terminate called after throwing an instance of 'std::runtime_error'
// what(): GetBranchNames: unsupported branch type
#include "TFile.h"
#include "TTree.h"
#include "ROOT/RDataFrame.hxx"
void createtree() {
TFile tfile("examplefile.root", "RECREATE");
TTree tree("tree", "tree");
auto a = TVector3();
auto b = TVector3();
auto c = new TVector3();
tree.Branch("a", &a);
tree.Branch("b", &b);
tree.Branch("c", "TVector3", &c, 32000, 0); // This method of creating a branch creates a branch of type "TBranchObject". If this line is commented out the script runs as expected.
for (int ii = 0; ii < 10; ++ii) {
a.SetX(ii);
b.SetX(2*ii);
c->SetX(3*ii);
tree.Fill();
}
tree.Write();
tfile.Close();
return;
}
void checktype() {
TFile tfile("examplefile.root", "READ");
auto tree = (TTree*)tfile.Get("tree");
for (auto br : *tree->GetListOfBranches()) {
std::cout << br->GetName() << " is a " << br->IsA()->GetName() << std::endl;
}
}
void readtree() {
ROOT::RDataFrame rdf("tree", "examplefile.root");
auto ha = rdf.Define("aval", "a.X()").Histo1D("aval");
auto hb = rdf.Define("bval", "b.X()").Histo1D("bval");
std::cout << "mu(a):" << ha->GetMean() << std::endl;
std::cout << "mu(b):" << hb->GetMean() << std::endl;
}
void example_tbranchobject_problem() {
createtree();
checktype();
readtree();
return;
}
I know that in this example script I can “fix” this script by changing the way that the “c” branch is defined such that it is written as a “TBranchElement” type. However, in my real world example I have a file provided by the T2K experiment that has a branch as type “TBranchObject” and is not possible for me to change the input file format.
Many thanks,
Dave.