trees and files

From: Chiara Zampolli <Chiara.Zampolli_at_bo.infn.it>
Date: Mon, 24 Sep 2007 11:25:40 +0200


Dear rooters,

   I have a doubt concerning the relationship between files and trees.    I have written a class where one member function is:



void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){

// creating the tree with the trees for calibration
// collecting them from reference data (from file)
// from minrun to maxrun

//TH1::AddDirectory(0);

 Float_t p[CHENTRIESSMALL];
 Int_t nentries;
 TFile *filefinal = new
TFile("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileoutFinal.root","RECREATE");  fTree = new TTree("TOFCalib","Tree for TOF Calibration");  fTree->Branch("nentries",&nentries,"nentries/I");  fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");  Char_t filename[100];
 for (Int_t irun = minrun;irun<=maxrun;irun++){    

sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);

   TFile *file = new TFile(filename,"READ");    TTree *tree = (TTree*)file->Get("T");    tree->SetBranchAddress("nentries",&nentries);    tree->SetBranchAddress("TOFentries",p); fTree->CopyEntries(tree);    delete tree;
   delete file;
   file = 0x0;
   fNruns++;
 }

//delete filefinal;
//filefinal=0x0;

 AliInfo(Form("Number of runs being analyzed %i",fNruns)); }


where fTree is a private member. The problem is that if I don't create the filefinal file (that is completely useless, I don't need it, but still it can't be deleted in case I create it, because - holding the fTree, I guess - otherwise root crashes), I get the following message:

...
E-TTree::Fill: Failed filling branch:TOFCalib.nentries, 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(...)
...

Now, the fTree should not be written in any file, for this reason I didn't open any file before creating it. But then, probably because I open files from which to retrieve some other trees, I get this error. What should I do to avoid this problem without creating any filefinal file? Thank you in advance for your help.
Cheers,

      Chiara Received on Mon Sep 24 2007 - 11:24:10 CEST

This archive was generated by hypermail 2.2.0 : Wed Sep 26 2007 - 17:50:02 CEST