Reading objects in TObjectBranch without new/delete?

From: stefan kluth (skluth@mh1.lbl.gov)
Date: Thu Oct 28 1999 - 01:54:37 MEST


Hello,

As far as I understand, the normal procedure for ROOT when reading objects
e.g. of type A in a TObjectBranch of a TTree is to delete the previous
object pointed to by the pointer contained in TObjectBranch::fAddress and
creating a new object using its default ctor A::A(). Then it is filled
using the Streamer member function of the object A::Streamer(...).

Is it possible to arrange it so that ROOT does not delete the existing
object, and just calls the Streamer A::Streamer again to overwrite the
contents?

This should work ok for objects with "constant memory footprint", i.e.
those which don't allocate memory from the heap themselves. 

One interesting application would be that one could have several
TObjectBranch'es holding the *same* type of objects, which in turn contain
non-static pointers to TClonesArrays holding identical types of objects. 

Currently, one can only have one TObjectBranch containig objects with
a static pointer to one TClonesArray to reuse memory. If one would have
several branches, reading the next branch would overwrite the data from a
previously read branch in the one shared TClonesArray. 

For example, one could read several TObjectBranches of the Event
class containig different events. Of course, one would not do this with an
"event", but one could imagine storing and retrieving several objects of
the same type containg lists of e.g. tracks reconstructed in different
ways. 

cheers, Stefan

---Stefan Kluth---------------Lynen Fellow----------------|\--|\-------
-  LBNL, MS 50A 2160       -  phone:  +1 510 495 2376  -  |/  |/      -
-  1 Cyclotron Rd.         -  fax:    +1 510 495 2957  -  |\/\|\/\|'  -
---Berkeley, CA94720, USA-----e-mail: SKluth@lbl.gov------|/\/|/\/|----



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:41 MET