Error message in TTree::Fill

From: Hajime Nanjo <nanjo_at_scphys.kyoto-u.ac.jp>
Date: Tue, 25 Oct 2005 01:51:06 +0900


Dear ROOTers,

I received an error message like,
"Error in <TTree::Fill>: Failed filling branch:t2.random, nbytes=-1" when I call TTree::Fill() within a write-protected TFile. (Here I don't want to save the newly created TTree object.)

Does TTree really fail in filling variables? Is it really an error?

I think is is not a case of an error.
If so, could you stop the error message?

Best Regards,
Hajime

////////////////////////////////////////////////////////////////////
[environment]
////////////////////////////////////////////////////////////////////
gcc 3.4.3
ROOT Version 4.04/02

////////////////////////////////////////////////////////////////////
[complie and run]
////////////////////////////////////////////////////////////////////
g++ -o tree1 tree1.C `root-config --cflags` `root-config --libs` ./tree1

////////////////////////////////////////////////////////////////////
[source code]
////////////////////////////////////////////////////////////////////

#include "TApplication.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1.h"
#include "TPad.h"
#include "TRandom.h"

int main(int argc, char** argv)
{
  TApplication theApp("App", &argc, argv);   gApplication->Init();   

  {
    TFile f("tree1.root","recreate");
    TTree t1("t1","a simple Tree with simple variables");     Float_t px, py, pz;
    Double_t random;
    Int_t ev;

    t1.Branch("px",&px,"px/F");
    t1.Branch("py",&py,"py/F");
    t1.Branch("pz",&pz,"pz/F");
    t1.Branch("random",&random,"random/D");
    t1.Branch("ev",&ev,"ev/I");
    

    //fill the tree
    for (Int_t i=0;i<10000;i++) {

      gRandom->Rannor(px,py);
      pz = px*px + py*py;
      random = gRandom->Rndm();
      ev = i;
      t1.Fill();

    }
    t1.Write();
    f.Close();
  }   
  //----------------------------------------------------
  

  {
    TFile *f = new TFile("tree1.root","read");     TTree *t1 = (TTree*)f->Get("t1");   

    //---------------------------

    TTree t2("t2","a simple Tree with simple variables");     Float_t px, py, pz;
    Double_t random;
    Int_t ev;
    t2.Branch("px",&px,"px/F");
    t2.Branch("py",&py,"py/F");
    t2.Branch("pz",&pz,"pz/F");
    t2.Branch("random",&random,"random/D");
    t2.Branch("ev",&ev,"ev/I");
    

    //fill the tree
    for (Int_t i=0;i<10000;i++) {

      gRandom->Rannor(px,py);
      pz = px*px + py*py;
      random = gRandom->Rndm();
      ev = i;
      t2.Fill();

    }
    TH1D his1("his1","his1",50,-5,5);
    TH1D his2("his2","his2",50,-5,5);
    his2.SetLineColor(4);

    t1->Draw("px>>his1");
    t2.Draw("px>>his2","","same");
    gPad->Modified();
    gPad->Print("px.ps");
    f->Close();
  }

  return 0;
}
////////////////////////////////////////////////////////////////////
Received on Mon Oct 24 2005 - 18:51:15 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET