Re: [ROOT] Writing if more than one list refs the same object.

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Nov 14 2001 - 14:57:45 MET


Hi Thomas,

If you had tried your own example, you could have seen that name3 is written
and read only once in case you write an object MyClass, eg myc.Write();

However, in case you write separately list1 and list2, then in this case,
you write and read two copies of name3.

We introduce recently in 3.02 two new classes TRef and TRefArray that
address this particular problem.
You can create, eg, a TRefArray object that contains only references to
other objects in some lists. If the same object is referenced many times
from a TRef or TRefArray, this object will be written only once.

I suggest you look into TRefArray.
Note that the new version of $ROOTSYS/test/Event illustrates the use
of these two classes.

Rene Brun

Thomas Bretz wrote:
> 
> Hi rooter,
> 
> think about the follwoing class and macro:
> 
> -----------------
> class MyClass : public TObject
> {
>    TList *list1;
>    TList *list2;
> 
>    void AddToList1(TObject *obj) { list1->Add(obj); }
>    void AddToList2(TObject *obj) { list2->Add(obj); }
> }
> 
> MyClass myc;
> 
> TNamed name1("name1", "");
> TNamed name2("name2", "");
> TNamed name3("name3", "");
> 
> myc.AddToList1(&name1);
> myc.AddToList2(&name2);
> 
> myc.AddToList1(&name3);
> myc.AddToList2(&name3);
> 
> -----------------
> 
> Now I want to store the object myc in a root-file, but I don't want to
> store the object name3 twice. If I read back myc from the file I want to
> have name3 only once in the memory. Is it possible with root to do this?
> 
> Thanks a lot,
> Thomas.



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