Re: [ROOT] saving pointers

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Dec 21 2001 - 17:58:11 MET


Hi Clark,

Clark McGrew wrote:
> 
> Merry Christmas Everyone,
> 
> I have a relatively detailed question about how pointers to objects are
> saved in the output file and I tried picking apart the makecint streamer
> code, but I can't exactly follow what is happening. Say I have a self
> referential class hierarchy that looks something like this:
> 
> class TParent TObject {
>   public:
>    TDaughter *fDaughter1;
>    TDaughter *fDaughter2;
> };
> 
> class TDaughter : TObject {
>   public:
>    TParent *fParent;
>    TDaughter *fSibling;
> }
> 
> And it gets filled like this:
> 
> TParent p = new TParent;
> TDaugher d1 = new TDaughter, d2 = new TDaughter;
> 
> // Insert the daughters with back pointers to the parent.
> p->fDaughter1 = d1; d1->fParent = p;
> p->fDaughter2 = d2; d2->fParent = p;
> 
> // Set the siblings for the daughters.
> d1->fSibling = d2; d2->fSibling = d1;
> 
> At some point the parent class will be placed into a tree and saved to a
> file.  Are all of the self referential pointers written, and then
> restored when the classes is read?  Do I need to write a specialized
> streamer so that only one copy of d1, and d2 are saved to the file?
> 

No, you do not need a special Streamer. ROOT will do that automatically for you.
Your pointers will be restored when reading. If multiple pointers point to the
same object, only one copy of the object is written.

See ROOT Users Guide: chapter discussing Streamers.
This assumes that you use the production version of ROOT 3.02 and that
you have specified the option "+" in the #pragma statement of your LinkDef.h
file.

Rene Brun


> In particular, before saving "(p->d2 == p->d1->fSibling)" is true.
> 
> is
> 
> Thanks,
> Clark
> 
> --
> Clark McGrew                    State University of New York, Stony Brook
> (clark.mcgrew@sunysb.edu)       631-632-8299 (office)



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:13 MET