Home | News | Documentation | Download

How can I create an RDataFrame from a TTree containing a branch of type "TBranchObject"?

I am trying to analyze a TTree with RDataFrame but when I try to eg make a histogram it raises an exception std::runtime_error with the error message:

“GetBranchNames : unsupported branch type”

that gets raised from code inside RDFInterfaceUtils.cxx. The problem is due to a single branch in the tree that is of type “TBranchObject”.

I don’t care about this particular branch and I tried SetBranchStatus(“name”, 0) but this still failed with the same error.

Is there a workaround that will allow me to read this TTree with a TDataFrame?


_ROOT Version: 6.14/03
_Platform: Linux/Ubuntu
_Compiler: gcc 5.4.0


I guess @eguiraud can help you.

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 :smile:

Please post here either a stacktrace or a minimal reproducer.
Cheers,
Enrico

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.

1 Like

Thank you for your quick reply with a standalone reproducer, this makes things much simpler :smile:

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).

Cheers,
Enrico

Hi Dave,
thanks for reporting and providing the reproducer. We acknowledge the bug: a ticket has been opened https://sft.its.cern.ch/jira/browse/ROOT-9731.

Cheers,
Danilo

1 Like

Hi,

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())

and #include <TBranchObject.h>.

See attached patch file:
0001-Fix-for-Bug-ROOT-9731.patch.txt (1.1 KB)

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.

thanks,
Dave.

1 Like

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

In case someone stumbles upon this post, reading TBranchObjects with RDF/TTreeReader was fixed in v6.22/02 and v6.24.