Skip to content

Using TTree::Draw() together with TTreeFormula on TChain crashes for data member branches #19291

Open
@guitargeek

Description

@guitargeek

This is the underlying issue of https://its.cern.ch/jira/projects/ROOT/issues/ROOT-10390.

To reproduce, first create some input files:

// writeFiles.C

struct MyData {
    double fX;
    double fY;
};

void writeFile(int j) {
    std::unique_ptr<TFile> file{
        TFile::Open(("file_" + std::to_string(j) + ".root").c_str(),
                "RECREATE")
    };
    TTree *tree = new TTree("Events", "Events");

    MyData *data = new MyData();

    tree->Branch("data", &data);
    for (int i = 0; i < 10; ++i) {
        data->fX = i * (j + 0.1);
        data->fX = - i * (j + 0.1);
        tree->Fill();
    }
    tree->Write();
}

void writeFiles() {
  writeFile(1);
  writeFile(2);
}

Run this script afterwards:

// repro.C

struct MyData {
    double fX;
    double fY;
};

void repro()
{
   TChain c("Events");
   c.Add("file_1.root");
   c.Add("file_2.root");

   c.Print();

   // commenting this line out will avoid the crash
   c.Draw("data.fX","","goff");

   TTreeFormula form1{"form1", "data.fX", &c};
   TTreeFormula form2{"form2", "data.fY", &c};

   c.GetEntry(0);

   // commenting these lines out will avoid the crash
   form1.EvalInstance(0);
   form2.EvalInstance(0);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions