Hi, all
I have came up with a strange problem with TTree::Fill(). I have a tree with some data and now I wat to pick out some of them to form a new tree. Here is my code:
void split()
{
TFile *input = new TFile(" input.root", “READ”);
TTree *original = (TTree *)input->Get(“Train”);
Double_t data1;
Double_t data2;
Double_t data3;
Int_t data4;
original->SetBranchAddress("data1", &data1);
original->SetBranchAddress("data2", &data2);
original->SetBranchAddress("data3", &data3);
original->SetBranchAddress("data4", &data4);
TTree *newtree = new TTree("Train", "My New Tree");
newtree->Branch("data1", &data1, "data1/D");
newtree->Branch("data2", &data2, "data2/D");
newtree->Branch("data3", &data3, "data3/D");
newtree->Branch("data4", &data4, "data4/I");
for(Int_t i = 0; i < original->GetEntries(); i++)
{
original->GetEntry(i);
if(data1 > 0.5) newtree->Fill();
}
}
When I load this macro in ROOT v5.14, ROOT gives out following error messages while i equals certain values:
Error in TTree::Fill: Failed filling branch: Train.data1, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:Train.data2, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:Train.data3, nbytes=-1
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(…)
Error in TTree::Fill: Failed filling branch:Train.data4, nbytes=-1
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(…)
I checked the value of the branches of the entries which induce the error, however they appears quite normal.
Thanks in advance for any help!