RDataFrame read custom class column


ROOT Version: 6.26/00
Platform: CentOS 8.5
Compiler: cling/c++


I’m trying to test RDataFrame in order to see if we can switch to using it instead of proof. For this we would need to be able to read branches of a TTree (which as far as I understand are called columns in RDataFrame) that are custom classes. I tried this both with cling and a small c++ program.
When I use cling I get this:

root [0] TClass::GetClass("myClass")->HasDictionary()
(bool) true
root [1] ROOT::RDataFrame d("myTree", "myFile.root")
(ROOT::RDataFrame &) A data frame built on top of the AnalysisTree dataset.
root [2] auto energyLambda = [&](myClass* cl) {std::vector<double> energies; for(Short_t i = 0; i < cl->GetMultiplicity(); ++i) { energies.push_back(cl->GetHit(i)->GetEnergy()); } return energies; };
root [3] auto myHist = d.Define("energies", energyLambda, {"myClass"}).Histo1D("energies");
root [4] myHist->Draw()
Error in <TTreeReaderValueBase::CreateProxy()>: The template argument type T of myClass* accessing branch myClass (which contains data of type myClass) is not known to ROOT. You will need to create a dictionary for it.
Error in <TGRSIint::HandleTermInput()>: std::runtime_error caught: An error was encountered while processing the data. TTreeReader status code is: 6

For a simple c++ program that does the same and is linked against the shared object library with that class I get:

Error in <TTreeReaderValueBase::CreateProxy()>: The template argument type T of myClass* accessing branch myClass (which contains data of type myClass) is not known to ROOT. You will need to create a dictionary for it.
terminate called after throwing an instance of 'std::runtime_error'
  what():  An error was encountered while processing the data. TTreeReader status code is: 6
Aborted (core dumped)

I tried looking through the tutorials, but the all only deal with very simple columns, not using custom classes. What is the right way of doing this so that ROOT recognizes that the dictionary exists?

Hi @vaubee ,

could you please try with (myClass &cl) instead of (myClass *cl)? That might be what’s confusing RDF and TTreeReader.

Cheers,
Enrico

Yes, that was the mistake! Thanks for the help

Good! The error message could have been better :sweat_smile:

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