Re: [ROOT] Problem reading a TRef'd object

From: Nick van Eijndhoven (
Date: Thu Jan 08 2004 - 09:44:15 MET

Hi John,
I think that if you first obtain back from the file the
pointer value of the class A object and use that in class B
then everything should be fine.


Dr. Nick van Eijndhoven

Org.:    Utrecht University, Faculty of Physics and Astronomy
Address: Princetonplein 5, NL-3584 CC Utrecht, The Netherlands
Phone:   +31-30-2532331(direct) +31-30-2531492(secr.)  Fax: +31-30-2518689
CERN:    +41-22-7679751(direct) +41-22-7675857(secr.)  Fax: +41-22-7679480
Offices: Buys Ballot laboratory Room 710 (Utrecht)   B23 1-020 (CERN)

John Pretz wrote:

> Hello everybody.
> I'm trying out TRef and I ran into the following problem:
> I have a class ClassA and a class ClassB.  ClassB has a TRef to ClassA.  I 
> want to write them both to disk.  I do it two possible ways.  One works.  
> The other doesn't.
> If I 
> 1.) Create ClassA
> 2.) Create ClassB
> 3.) Make ClassB::fTRef point to ClassA
> 4.) Write ClassA and ClassB to file
> alls well, and I can read them both back in just fine.
> If however, I do this:
> 1.) Create ClassA
> 2.) Write ClassA to file
> 3.) Create ClassB and make it's TRef point to ClassA
> 4.) Write ClassB to file
> I read in ClassA and ClassB only to find that ClassB's TRef points to 0.
> Is there a way to make this work for me?  I would really like to be able 
> to write ClassA to file before even creating the object that will point to 
> it.  I hunted around on this list's archives and couldn't find any 
> solutions.
> I included some code.  Just 'make' should compile all the code and run my 
> problem scripts.  (I'm using ROOT 3.10.02 on a RedHat 9 machine)
> Thanks in advance.
> John 

This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET