Re: [ROOT] Repeatability of commands

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Oct 02 2002 - 18:38:08 MEST


Hi David,

Your statement  fFile->Close();
will automatically delete all objects in memory related to the file,
including the Tree. So when calling 
delete fTree; you delete an already deleted object.

Note that you can alos delete the statement fFile->Close();
The statement "delete fFile" will automatically close the file
if it is not yet closed.

Also replace:
 THenaEvent *fRaw = new THenaEvent();
by
 THenaEvent *fRaw = 0;

The TTree::GetEntry statement will create the object.

Rene Brun

On Wed, 2 Oct 2002, [iso-8859-1] Lindelöf David wrote:

> Hello,
> 
> I have observed a very peculiar behaviour which I hope someone can help 
> explain. I have a macro that runs like this:
> 
> {
> TFile *fFile = new TFile("somefilename");
> TTree *fTree = (TTree*) fFile->Get("EventsTree");
> TBranch *b_Events=fTree->GetBranch("Event");
> THenaEvent *fRaw = new THenaEvent();            //THenaEvent is a custom 
> class written for holding data
> b_Events->SetAddress(&fRaw);
> fFile->Close();
> delete fFile;
> delete fRaw;
> delete b_Events;
> }
> 
> The macro runs fine but:
> 
> 1) How do I get rid of the TTree?? Running
>          delete fTree
> yields only a segmentation violation.
> 
> 2) When I afterwards type
>          fFile = new TFile("samefilename")
> I get a segmentation violation, but running it a *second* time works fine.
> 
> I am experimenting with all this in order to be able to run a set of 
> analysis macros on a huge amount of files. So far it always hangs when it 
> reaches the second file.
> 
> Any help would be greatly appreciated.
> 
> David Lindelof
> EP-Division
> CERN
> 1211 Geneva 23
> Switzerland
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:12 MET