A TTree with a friend TChain doesn't propagate all errors happening in the chain

未关闭
#23,936 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp
领域
data

调研方向

Start with the friend-loading block in TTree::GetEntry (tree/tree/src/TTree.cxx), where the return value of LoadTreeFriend is checked, and with TTree::LoadTreeFriend itself. Build the reproducer root_friend_missing_file_bug.C from the issue, which uses a TChain friend pointing to a missing file. Done means events.GetEntry(0) returns a negative value on that failure, and the return-code convention for missing entries (-2) is kept. The sign and value conventions need a maintainer decision first.

由索引模型根据 Issue 内容生成。

描述

bug in:TTree
Check duplicate issues.
  • Checked for duplicates
Description

When a TTree has a friend TChain, the tree's GetEntry() does not return an error if the chain encounters one. This is caused by code in TTree::GetEntry(), which fails to return forward failures signaled by LoadTreeFriend():

   if ( t->LoadTreeFriend(entry,this) >= 0 ) { // Returns < 0 on error
      nb = t->GetEntry(t->GetReadEntry(),getall);
   } else nb = 0; // Error path; I think this should be -1 for `LoadTreeFriend` errors except on missing entries (-2)
}
if (nb < 0) return nb; // Zero is rightfully not an error: it appears when no branch in the friend is enabled

The important point for reproduction is to make LoadTreeFriend fail. With TChain, this is trivially achieved with a file that cannot be loaded or doesn't contain the input tree. With TTree, this is only potentially possible in a very contrived scenario with friends of friends and a custom fNotify.

Reproducer

Run with root -l -q root_friend_missing_file_bug.C.

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

#include <stdio.h>

void root_friend_missing_file_bug()
{
    // Setup: 1-event main file
    {
        TFile f("main.root", "RECREATE");
        TTree t("events", "events");
        int x = 0;
        t.Branch("x", &x);
        t.Fill();
        f.Write();
    }

    TFile f("main.root", "READ");
    auto &events = *f.Get<TTree>("events"); // Repro also works with a TChain here

    TChain corrections("aux");
    corrections.Add("/ThisFileDoesNotExist.root");
    // Repro also works with branches in corrections
    events.AddFriend(&corrections);

    // The tree returns 4, i.e., doesn't report the missing file.
    printf("events.GetEntry(0)      = %d (failure if <= 0)\n", events.GetEntry(0));

    // The chain does return an error-ish value (0, inconsistent with the TTree API that
    // would return -1, but changing it would be a breaking change).
    printf("corrections.GetEntry(0) = %d (failure if <= 0)\n", corrections.GetEntry(0));
}
ROOT version

6.38.00, but code confirmed identical in master.

   ------------------------------------------------------------------
  | Welcome to ROOT 6.38.00                        https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Feb 03 2026, 21:14:06                 |
  | From tags/6-38-00@6-38-00                                        |
  | With g++ (GCC) 15.2.0 std202302                                  |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------
Installation method

LCG 109

Operating system

lxplus

Additional context

I wanted to identify the origin of errors and handle them appropriately based on their category (unrecoverable tree/file not found vs transient network issues for which a retry can work).

Full disclosure: this bug was found and investigated with the help of AI. I take full responsibility for the report.

主要语言
C++
星标
3.3k
派生
1.6k
平均合并
2 天 10 小时
30 天内合并 PR
200

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

root-project/root 的其他 Issue

查看 root-project/root 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。