Skip to content

[DF] Bad interaction between Alias and TTree sub-branches #11207

@eguiraud

Description

@eguiraud

First reported at https://root-forum.cern.ch/t/question-about-aliases-in-rdataframe/51155 .

Reproducer:

#include <ROOT/RDataFrame.hxx>
#include <TTree.h>

int main() {
  TTree t("t", "t");
  auto x = std::make_pair(42, 84);
  // This is a weird way to build a tree, but for the purposes of this test
  // we we just need to mock a TTree with branches "topbranch" and
  // "topbranch.something" where `something` must not be a data member of the type of "topbranch"
  // (otherwise things "happen" to work due to the order in which we do substitutions in RDF, see below).
  t.Branch("topbranch", &x);
  t.Branch("topbranch", &x, "a/I:b/I");
  t.Fill();

  auto df = ROOT::RDataFrame(t).Alias("alias", "topbranch");
  // Here we transform `"alias.a == 42"` into `[](std::pair<int, int> &var0) { return var0.a == 42; }`,
  // which is not valid C++.
  return df.Filter("alias.a == 42").Count().GetValue();
}

which yields:

input_line_8:2:45: error: no member named 'a' in 'std::pair<int, int>'
auto func0(pair<int,int>& var0){return var0.a == 42
                                       ~~~~ ^
terminate called after throwing an instance of 'std::runtime_error'
  what():
RDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of the crash
 All RDF objects that have not run an event loop yet should be considered in an invalid state.

fish: Job 1, './repro2' terminated by signal SIGABRT (Abort)

The solution is to perform alias substitution in the expression first and then, in a second pass, substitute branch names with dummy variable names (var0).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions