Hi,
You don’t need SetBranchStatus: RDataFrame will not read a branch if you don’t use it in your analysis.
So somewhere you are reading that branch…maybe in a Snapshot where you don’t specify the column names (so all of them are used?)
You can also run the program inside a dubugger (e.g. gdb) to get a complete stacktrace and check who uses that branch exactly, or make a small reproducer in which you delete all dataframe commands except the one causing problems and the ones it depends on.
In any case we need to investigate what’s going on a bit more
Please post here either a stacktrace or a minimal reproducer.
Cheers,
Enrico
// 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.
Thank you for your quick reply with a standalone reproducer, this makes things much simpler
From what I can see (haven’t had time to play with your macro yet) you are reporting two bugs: branch “c” is causing an error even if it’s a valid branch of a relatively simple type, and it is somehow causing the error even if it’s not used in the analysis.
We’ll open a jira ticket and you will be able to follow the progress on the fixes there (will post a link here as soon as we get around to this).
Thanks for investigating this problem and filing the bug report.
In case anyone else is having this problem and finds this post, the temporary workaround that I am currently using is to recompile ROOT with the line in RDFInterfaceUtils.cxx:
if (branch->IsA() == TBranch::Class()) {
replaced with:
if (branch->IsA() == TBranch::Class() || branch->IsA() == TBranchObject::Class())
This fixes my immediate problem (can’t load trees containing this kind of branch into RDataFrame) so that I can continue development. But it is not a fix for the bug since an attempt to actually read the problematic branch itself causes a crash.