Re: Problems reading a TTree of TMap(s)

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jun 16 1997 - 09:01:19 MEST


James M White wrote:
> 
> Greetings,
>         I have a somewhat complicated question (problem) with a
> TTree.  I'm trying to store into a TTree a TMap that maps TObjStrings
> to complex objects.  These complex objects come in 4 flavors:
>   1) Objects that contain simple Int_t(s) and Float_t(s).
>   2) Objects that contain (among other things) TH1(s).
>   3) Objects that contain TMap(s) that map TObjStrings to the equivalent
>      of your TObjNum.  (I use this as a histogram for TObjString(s))
>   4) Objects that contain (among other things) TMap(s) that map
>      TObjString(s) to Objects like (3) above.  (These are used as 2D
>      TObjString histograms)
> These 4 objects are all built of a common ABC and all of my access to
> them are trough the virtual methods in the ABC.
> 
>         I have been able to create and store these TMap of complex
> objects successfully (I think), and I can successfully retrieve any one
> of the TMaps using the GetEvent() method.  The trouble comes when I
> call the GetEvent() method the second time.  The TMap returned by
> the second call to GetEvent() has some problems:
>   The objects of type (1) above are always correct.
> 
>   The objects of type (2) above are always correct but I get the
>    following warning: "Warning in <TH1::Build>:Replacing existing
>    histogram: RunOutFloatHistogram".
> 
>   The objects of types (3) and (4) are slightly mangled.  (some of the
>    TObjNum(s) contain values that are off by +- 1 and sometime the
>    TObjString(s) are not correct)
> 
> Again the problem never occurs on the first call to GetEvent() no
> matter what event number I ask for and it always occurs on subsequent
> calls to GetEvent().
> 
> I'm not sure where to look for my problem.  Could it be because I'm
> having some problems with destructors?  When is TH1::Build() called
> and should I make the equivalent of it for objects (3) and (4)?  I've
> looked at the code and I'm not sure exactly what it does. Any help
> would be appreciated.
>                                 Jim White

This is clearly a problem related to your destructors. You must take care
of deleting all objects created in your constructors.
When you call GetEvent for the second time, Root takes care of deleting
the object created by the previous call to GetEvent.
If one of the members is a pointer to another object (like an histogram)
you must explictely delete this object. In case of histograms, Root
is protected to prevent the creation of two histograms with the same
name in the same list/directory.

Histograms with strings is an important feature that we want to add
to the basic Root during this summer.

Rene Brun



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:19 MET