Re: TDirectory::Get...

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Mon, 18 Apr 2005 17:42:40 +0200 (MEST)


Hi Thomas,

When the TFile estructor is closed (or TFile::Close) the objects registered in the list of objects in memory for this file are automatically deleted.
You can see this list via TDirectory::GetList(). For example, by default, TH1 and TTrees are automatically registered to this list when you call TFile::Get. If you want to disable this feature, call TH1::AddDirectory(kFALSE). For all other objects, your assumption is true.

for more details, see teh chapter about "Object Ownership" in teh Users guide.

Rene brun

On
Mon, 18
Apr 2005, Thomas Bretz wrote:

> Hi,
>
> there is something which is not clear to me, maybe you can help:
> If I get an object using TDirectory::Get, is this object still valid
> when the file is closed?
>
> Would the following work?
>
> TObject *ReadObject(const char *filename, const char *objname)
> {
> TFile f(filename, "READ");
> return f.Get(objname);
> }
>
> void main()
> {
> TObject *o = ReadObject("myfile.root", "MyObject");
> // Do something with it
> delete o;
> }
>
> Thanks,
> Thomas.
>
Received on Mon Apr 18 2005 - 17:42:44 MEST

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