Skip to content

TChain as a friend of TTree gets stuck after the first file #16804

Closed
@lmoureaux

Description

@lmoureaux

Check duplicate issues.

  • Checked for duplicates

Description

When a TChain is added as a friend to a TTree , branches coming from the TChain are no longer updated after switching to the second file in the chain.

Reproducer

The attached macro reproduces the issue. Save it bugDemo.C and run it. The correct behavior is to always print true, but we get some false.

The code first constructs two trees with an index branch. The index is the entry number, going from 0 to 10 in the first file and 10 to 20 in the second one. Then, a longer tree is constructed with 20 empty entries. The two files containing the entry number as merged into a chain and attached as a friend to the empty tree.

Iterating over the long tree yields the correct value of index until the 10th entry, than a constant 9 (the last value in the first file). Correct behavior is 0 to 20. This can be obtained by wrapping the long tree in a TChain.

The underlying issue is that TTree::LoadTree lacks the following code present in TChain::LoadTree:

root/tree/tree/src/TChain.cxx

Lines 1407 to 1434 in 2cc4b70

while ((frelement = (TChainElement*) fnext())) {
void* addr = frelement->GetBaddress();
if (addr) {
TBranch* br = fTree->GetBranch(frelement->GetName());
TBranch** pp = frelement->GetBranchPtr();
if (pp) {
// FIXME: What if br is zero here?
*pp = br;
}
if (br) {
if (!frelement->GetCheckedType()) {
Int_t res = CheckBranchAddressType(br, TClass::GetClass(frelement->GetBaddressClassName()),
(EDataType) frelement->GetBaddressType(), frelement->GetBaddressIsPtr());
if ((res & kNeedEnableDecomposedObj) && !br->GetMakeClass()) {
br->SetMakeClass(true);
}
frelement->SetDecomposedObj(br->GetMakeClass());
frelement->SetCheckedType(true);
}
// FIXME: We may have to tell the branch it should
// not be an owner of the object pointed at.
br->SetAddress(addr);
if (TestBit(kAutoDelete)) {
br->SetAutoDelete(true);
}
}
}
}

ROOT version

Seen in:

  • ROOT 6.30/04 (anaconda)
  • ROOT 6.28/04 (LCG 104)

I couldn't find any code change in master in the relevant areas.

Installation method

anaconda and LCG 104

Operating system

Linux (CentOS 9, Ubuntu 22.04, Ubuntu 24.04)

Additional context

Possibly related to the following Jira tickets:

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions