【发布时间】:2015-09-27 15:16:31
【问题描述】:
瞄准; 我想比较两个具有相同结构的ROOTTTree 对象的内容(但显然内容不同)。最好的方法似乎是使用AddFriend。
问题; 我收到此错误消息;
Error: illegal pointer to class object t3 0x0 1681 makeFriends.C:6:
*** Interpreter error recovered ***
到目前为止我所尝试的;
在成功运行this page 底部的示例后,我决定将其缩减为仅阅读和添加朋友部分,因为我已经在第一次运行时创建了tree3.root 和tree3f.root。所以我有一个名为 tree3.C 的文件,其中包含:
// Function to read the two files and add the friend
void tree3r() {
TFile *f = new TFile("tree3.root");
TTree *t3 = (TTree*)f->Get("t3");
// Add the second tree to the first tree as a friend
t3->AddFriend("t3f","tree3f.root");
// Draw pz which is in the first tree and use pt
// in the condition. pt is in the friend tree.
//t3->Draw("pz","pt>5");
}
当从根提示符加载 (root[] .L tree3.C) 并运行 (root[] tree3r()) 时,这按预期工作。
因此,我将副本放在包含我的两个根文件 plainMaskOutput.root 和 DNMaskOutput.root 的文件夹中,并更改了副本中的字符串以匹配我的文件名。所以我有;
// Function to read the two files and add the friend
void tree3r() {
TFile *f = new TFile("plainMaskOutput.root");
TTree *t3 = (TTree*)f->Get("t3");
// Add the second tree to the first tree as a friend
t3->AddFriend("t3f","DNMaskOutput.root");
// Draw pz which is in the first tree and use pt
// in the condition. pt is in the friend tree.
//t3->Draw("pz","pt>5");
}
这给出了上面的错误。我不明白为什么这些事情的行为不同?为什么他们不能只是朋友?
【问题讨论】:
-
这不是
C......new???在C??? -
我重新标记为
C++。 -
有没有办法检查结果?例如,您的方法
Get没有返回nullptr。 -
这root.cern.ch/phpBB3/viewtopic.php?t=12407 对您有帮助吗?看起来他们正在讨论完全相同的问题。尝试在上面添加
f->ls();并重新检查。这个链接root.cern.ch/phpBB3/viewtopic.php?f=3&t=12180也值得一看。 -
对C style casts保持警惕,他们可能不会做你期望他们做的事。而是尽可能使用更安全(更明确)的
static_cast
标签: c++ pointers tree root-framework