Skip to content

TChain cannot find branch of its own TTree if names differ #20248

@vepadulano

Description

@vepadulano

Check duplicate issues.

  • Checked for duplicates

Description

If a TChain is created with a name different than the TTree it holds, then FindBranch fails to find any branch if the name of the chain is passed. This is evident also by calling TChain::Scan

$: ./example
Error in <TTreeFormula::Compile>:  Bad numerical expression : "stepzerochain.value"
************************
*    Row   * stepzeroc *
************************
*        0 *           *
*        1 *           *
*        2 *           *
*        3 *           *
************************
Looking for branch 'stepzerochain.value' produces pointer 0x0

Reproducer

#include <TChain.h>
#include <TFile.h>
#include <TTree.h>

#include <memory>
#include <iostream>

void write_data(const char *name, const char *treename, int first, int last)
{
    auto file = std::make_unique<TFile>(name, "RECREATE");
    auto tree = std::make_unique<TTree>(treename, treename);

    int value{};
    tree->Branch("value", &value);

    for (value = first; value < last; ++value)
    {
        tree->Fill();
    }

    file->Write();
}

void run()
{
    // The TTree name is different than the name of the TChain that wraps it.
    write_data("stepzero_0.root", "events_zero", 3, 7);

    auto chain0 = std::make_unique<TChain>("stepzerochain");
    chain0->Add("stepzero_0.root?#events_zero");

    chain0->Scan("stepzerochain.value");
    std::cout << "Looking for branch 'stepzerochain.value' produces pointer " << chain0->FindBranch("stepzerochain.value") << "\n";
}

int main()
{
    run();
}

ROOT version

Any

Installation method

any

Operating system

any

Additional context

any

Metadata

Metadata

Labels

bugexperimentAffects an experiment / reported by its software & computimng expertsin:TTree

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions