[ROOT] Removing TH1 from a list

From: Mike Kordosky (kordosky@mail.hep.utexas.edu)
Date: Thu Apr 05 2001 - 21:20:13 MEST


Hi,

I wrote to this mailing list a month or so ago about removing TObjects
from a file.  It was suggested that I do the following:

// obj is preexisting and derived from TObject

gDirectory->GetList()->Remove(obj);

This does indeed remove the objects, so that when I close the file, they
are not deleted.  However, there is an addtional snag. If my object
derives from TH1, then when ~TH1() is eventually called, it looks at
TH1::fDirectory.  If fDirectory != 0 , it tries to remove the object from
its directory, (which doesn't exist). I know how to remove a histogram
from a directory via TH1::SetDirectory(), but TH1 seems to be a very
special case (along with TTree maybe?) where this is step is needed. Is
there any way around this, besides lots of IsA ==
TXXX::Class() statements?  If not, are there other classes that have
similar caveats?

mike kordosky



This archive was generated by hypermail 2b29 : Fri Jun 08 2001 - 11:51:22 MEST