根-填充分支失败:内存驻留树

时间:2019-01-30 21:17:42

标签: c++ root-framework

我正在尝试合并树:

string filename_;
TList *list = new TList;

///Loop on all .root output files
for (int i = 1; i < 13; ++i) {
  string filename_ = "file_";
  string file_extension = ".root";
  stringstream ss;
  ss << i;
  string str = ss.str();
  filename_ = filename_+str+file_extension;
  const char* c_filename = filename_.c_str();
  TFile *file_adress = TFile::Open(c_filename);
  TTree *tree_adress = (TTree*)file_adress->Get("pulses");
  list->Add(tree_adress);
}

// Output tree:
TTree *TPulses = TTree::MergeTrees(list);

但是我遇到了这个错误,它是悄悄地显露的:

Error in <TTree::Fill>: Failed filling branch:pulses.pulse_time, nbytes=-1, entry=115710
 This error is symptomatic of a Tree created as a memory-resident Tree
 Instead of doing:
    TTree *T = new TTree(...)
    TFile *f = new TFile(...)
 you should do:
    TFile *f = new TFile(...)
    TTree *T = new TTree(...)

但是我在for循环中的TTree之前创建了TFile,所以我不明白。 有人有主意吗?

1 个答案:

答案 0 :(得分:0)

您看到的错误消息来自正在写入的TTree。据我了解您的代码,TFile *file_adressTTree *tree_adress已打开供您阅读,而您写入TTree *TPulses。我没有看到TFile::Open的默认设置(如果它是只读的READ或用来操纵内容的update),但是从您的输出中我声称TPulses没有得到在您打开的最后一个文件中创建的,而是在RAM中创建的,您用完了(see docs)。常见的模式是在创建TPulses之前先创建输出文件:

TFile* outputfile = TFile::Open("output.root", "recreate");
TTree* TPulses = TTree::MergeTrees(list);
// ...
TPulses->Write();
outputfile->Close();
delete outputfile;