RE: [ROOT] Segmentation fault. Cause: Closing a TFile

From: Pierre-Luc Drouin (pldrouin@physics.carleton.ca)
Date: Wed Jul 02 2003 - 18:50:22 MEST


Hi,

In my code, tbuf is appended to myfile, but not ctbuf, since I call
ctdir->cd() I before create it. The TFile associated with ctbuf is
supposed to be the one that contains ctdir.

Thank you

Pierre-Luc Drouin

On Wed, 2 Jul 2003, Philippe Canal wrote:

> Hi Pierre-Luc,
> 
> When you close a file, all the objects 'Appended' to this file are deleted.
> In particular, histogram and trees are automatically appended to the current
> directory.  Hence, 'myfile->Close();' as the side-effect of deleting ctbuf.
> 
> You might want to (re)read the chapter on object ownership in the ROOT Users
> Guide.
> 
> Note that your code is missing (at least in this copy/pasted version) and
> essential
> 	myfile->Write();
> without which the tree is not fully written/flushed to the file.
> 
> Cheers,
> Philippe
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Pierre-Luc Drouin
> Sent: Wednesday, July 02, 2003 11:03 AM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] Segmentation fault. Cause: Closing a TFile
> 
> 
> Hello,
> 
> I've to open a TFile, get a TTree instance from it, and copy this TTree
> with some selections to a new TTree object and then to close the TFile. My
> code is the following:
> 
> 	    TTree *tbuf, *ctbuf;
>             TDirectory* fluxdir= \\A pointer to a TDirectory in a TFile
>             TDirectory *ctdir;
> 
> 	    TFile *myfile=new TFile("myfile.root","READ");
> 
> 
>           tbuf=dynamic_cast<TTree*>(myfile->Get("mytree"));
> 
> 	    ctdir=fluxdir->mkdir("Event Info");
> 	    ctdir->cd();
> 
> 	    ctbuf=tbuf->CopyTree(allcuts);
> 
> 	    myfile->Close();
> 	    gROOT->Delete(cardbuf[i][filenameindex]);
> 
> 
> I get a segmentation fault when I try to ctbuf->Draw() further in the
> code. Since gDirectory==ctdir in the code, I don't understand how ctbuf
> could depend on myfile. When I comment the last two lines in the code,
> everything works fine
> 
> Thank you
> 
> Pierre-Luc Drouin
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET