RE: [ROOT] TTree pointer structure question

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Aug 13 2003 - 00:39:46 MEST


Hi Brant,

This is a case where the TRef class can be helpful. Objects that are pointed
to by a raw pointer are save uniquely in a 'single I/O operation'.  By
definition when the TTree is split there is one I/O operation per end
branch.  When reading, each I/O operation is separate from the other and are
ignorant of what happened in the other (as far as raw pointer operation is
concerned).  So it is the
expected result that you would get duplicate object in your case when you
split the tree.

You have at least 3 possible solution.
a) Do not split the branch at all
	this would prevent reading only part of the tree
b) make use of myclass *p;
	this require p to never be null and would still lead to you b's and c's to
be read several time (but not duplicated in memory)
c) use TRef instead of raw pointer.
	you should still have one single raw pointer to each object (so that they
can actually be saved).  this 'raw pointer' can be the one you gave at the
construction of the branch.
	So if you store a1 in a split branch (and rely on a1 to save the other
object) you would have something like:
   a1 has a pointer to b1. b1 has a TRef to a1.
   a1 has a pointer to c1. c1 has a TRef to a1.
   c1 has a TRef to b1.
   c1 has a pointer to b2.

See details in the User's Guide and at the presentation done at CHEP2003 and
the last ROOT workshop.

Cheers,
Philippe.


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of brant c.
Sent: Tuesday, August 12, 2003 2:49 PM
To: root talk
Subject: [ROOT] TTree pointer structure question


Hello

I have a problem using a TTree a TObject-derived class.
The structure of the object is admittedly rather complicated:
there are three TObject-derived classes, A, B, and C.
A a1;  B b1,b2; C c1;
a1 has a pointer to b1. b1 has a pointer to a1.
a1 has a pointer to c1.  c1 has a pointer to a1.
c1 has a pointer to b1.
c1 has a pointer to b2.

all other pointers are null, and for a given use of A, some of the
pointers listed above may also be null (i.e. if c1 hasn't been created yet)

Storing a1 in a TFile works perfectly, with all the pointer structure
preserved and recreated on reading from the file.
However, storing a1 in a branch of a TTree (splitting set to 99) doesn't
work properly.
reading a1 from the TTree results in additional objects being created,
including a duplicate of a1 and a duplicate of b2.  Since my destructors
aren't designed to handle a garbled structure like that, this results in
memory leaks on a TTree::Draw() or on looping over the TTree.

Does this sound like a problem with my code?  If so, any thoughts as to
what I might have done wrong?

If, as I would like to think, my code works properly (the pointer
structure is correct before I write it to the TTree, and reading from a
TFile works), is this a known problem?  If not i'll try to reduce it to
the simplest case and post the code that reproduces the error.

Running  3.05/07 for linuxdeb with gcc 3.3.1

Thanks,
    Brant Carlson



#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



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