A problem with TTree::Fill()

From: Stephen Liu <phoenix.liu_at_gmail.com>
Date: Tue, 1 May 2007 13:04:56 +0800


Hi, all

I have came up with a strange problem with TTree::Fill(). I have a tree with some data and now I want 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 run 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!

liuk
2007.4.30 Received on Tue May 01 2007 - 07:05:04 CEST

This archive was generated by hypermail 2.2.0 : Tue May 01 2007 - 11:50:01 CEST