Re: [ROOT] About TTree::Branch

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Jun 10 2002 - 19:17:14 MEST


Hi David,

Your observations are correct. Some comments on your findings:
When creating the Tree, I assume that the user creates the real
instance of the Event object (likely calling a non default 
constructor). The already created Event object is used by 
TTree::Branch to compute the various internal offsets.

When reading the Tree, the assumption is that you do not want
to create an Event object first (you can do it if you like).
However, in general, it is better to simply set the pointer
to null. Typically you may want to browse your Tree interactively
with TBrowser and histogram some variables. The asymmetry between
writing and reading is due to the fact that Root supports reading
a Tree without having the original classes.

Concerning your points 3 and 4, I would need a simple example
reproducing this problem.

Rene Brun



On Thu, 6 Jun 2002 david.chamont@poly.in2p3.fr wrote:

> Hi rooters,
> 
> After a round with branches, I want to report
> about several behaviors which I find suspect. I work
> with g++ 2.95.2 under Linux redhat 6.1, and the
> class I try to make persistent is basically something
> like this :
> 
>    template <class T>
>    class MyArray
>     {
>      ...
>      private:
>        int size
>        T * elements ; // [size]
>      ...
>     } ;
> 
> I have added many display in MyArray and T constructors
> and destructors to track where I go. Here are the
> behaviors which disturb me :
> 
> 1) If I call TTree::Branch on a null pointer to MyArray
>       I observe that a MyArray is contructed,
>       a T is contructed, a T is destructed, and that's all.
>       The MyArray destructor has not been called, yet
>       the pointer is still null. Isn't it a memory leak ?
> 
> 2) If i call TTree::SetBranchAddress on a null pointer,
>       I observe that a MyArray is constructed
>       and the pointer is not any more null. This difference of
>       behavior with TTree::Branch is on purpose ? Is it
>       necessary for ROOT, or just expected to help the user ?
>       In my case, it does not help, since my strategy is to
>       attach the branch to the pointer at the moment, and
>       affect later the good value to the pointer.
> 
> 3) If I fill the tree wih an empty array (size and elements
>       attributes are null), put it in a file, and later open the
>       file and I get the corresponding entry, the size is
>       correctly set to 0, but the pointer is left unchanged.
>       If I get another entry, the tree
>       try to delete the pointer and crash.
> 
> 4) i tried to solve 3) by setting AutoDelete to kFALSE
>      on the branch, but I observed no effect. the T destructors
>      are still called. i misunderstood the role of AutoDelete ?
>      it is not expected to avoid calls to destructors between
>      two calls to GetEntry ?
> 
> David C.
> 
> 



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