Re: [ROOT] TTree deleting branch object even with SetAutoDelete(kFALSE)andSetCanDelete(kFALSE)

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Nov 11 2003 - 10:04:44 MET


Hi John,

Sorry for the delay. At a first glance, I had the impression that your mail
was only a comment and had no questions ::)

In your example, you do not use the automatic schema evolution Streamer.
See the difference in the generated code when doing
 rootcint -f junk1.cxx -c MyClass.h
and
 rootcint -f junk2.cxx -c MyClass.h+
or
 rootcint -f junk3.cxx -c MyClass.h LinkDef.h
where LinkDef.h contains:
#pragma link C++ class MyClass+;

The "+" is ESSENTIAL to use the automatic schema Streamer

In the above, you will see that junk2.cxx and junk3.cxx are identical
and use the auto Streamer, but not junk1.cxx

Rene Brun

> Frankland John wrote:
> 
> Hello again
> 
> I think I have localised my "problem". Now I have to ask some stupid questions
> and wait to get roundly chastised for my ignorance. Let's go!
> 
> For streaming member pointers I rely heavily on the very clear reply given by
> Rene to Paolo Adragna
> (http://root.cern.ch/root/roottalk/roottalk03/2707.html).
> If a class contains a member pointer which may or may not point to a valid
> object (i.e. initialised to 0 in the default ctor) then the comment field is
> "//" and
> when reading the object the class' default ctor is called (pointer initialised
> to 0) and then
> in the automatic streamer for the class R__b >> fPointer is used, which I
> suppose
> creates an object for fPointer to point to and then fills it from the buffer
> R__b.
> So any class with a "//" member pointer is obliged to call its ctor when one
> of its
> objects is read - even if e.g. in a TTree we use
> TBranch::SetAutoDelete(kFALSE)
> or TStreamerInfo::SetCanDelete(kFALSE).
> OK fine.
> But now, let's suppose that I decide that in fact fPointer can point to a
> valid
> object all the time, i.e. I initialise it in the ctor with fPointer = new
> SomeClass();
> Then I put "//->" in the comment field of fPointer, and the automatic streamer
> should use fPointer->Streamer(); In this case, when I read in an object of my
> class,
> ROOT should just call the streamer for the class - it must not call the
> default ctor
> otherwise it will create a new SomeClass() object everytime. This is part of
> the message
> we are giving with "//->" yes ?? The other part is of course that the
> automatic streamer
> should change. However, I have just realised that in all the automatic
> streamers of
> all my classes the only member pointers with "//->" comment fields which
> actually
> have "fPointer->Streamer()" are TClonesArray pointers.
> As an example you will find attached MyClass with the dictionary generated
> with the command
> rootcint -v -f MyClass_Dict.C -c -p MyClass.h
> Now tell me that all this is normal !!!
> Yours,
> John
> 
Frankland John wrote:
> 
>    Part 1.1.1    Type: Plain Text (text/plain)
>              Encoding: 7bit
> 
>                 Name: MyClass.C
>    MyClass.C    Type: Plain Text (text/plain)
>             Encoding: 7bit
> 
>                 Name: MyClass.h
>    MyClass.h    Type: Plain Text (text/plain)
>             Encoding: 7bit
> 
>                      Name: MyClass_Dict.C
>    MyClass_Dict.C    Type: Plain Text (text/plain)
>                  Encoding: 7bit
> 
>                      Name: MyClass_Dict.h
>    MyClass_Dict.h    Type: Plain Text (text/plain)
>                  Encoding: 7bit



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