Re: Reading objects in TObjectBranch without new/delete?

From: stefan kluth (skluth@mh1.lbl.gov)
Date: Fri Oct 29 1999 - 00:51:00 MEST


On Thu, 28 Oct 1999, Fons Rademakers wrote:

>   this is called a destructor which can be explicitely called like:
> 
> obj->~TObject();
Hm, yes, as long as there is no need for different actions between really
deleting an object and just "clearing" it so it can be used again by a
Streamer for input. Take the case of a class containing a pointer to a
TClonesArray:

class A : public TObject {

public:

A() { _array= new TClonesArray( "bla", 50 ); }

virtual ~A() { delete _array; }

virtual Clear() { _array->Clear(); }

private:

UInt_t _nent;         // Number of entries in _array
TClonesArray* _array; // Array of objects of type bla

ClassDef(A,1)

}

I don't want a static pointer to TClonesArray, because I want to have
several instances of A each holding a TClonesArray for IO of several lists
of objects called "bla". Before reading a new entry, I want to clear the
TClonesArray's, but at the end of reading the tree I may want to really
delete the As, including their TClonesArray's. 

Thus, I think there is a case for having a separate virtual function
"Clear()" to allow for clearing instead of deleting; if you accept the
idea of reusing top level objects in branches that is. 

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