Re: A question about TClonesArray

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Thu, 10 Nov 2005 18:10:23 +0100 (MET)


Hi Datao,

On Thu, 10 Nov 2005, Datao Gong wrote:

> Hi, Guys,
> When i read a piece of code writte by other people, i think i might
> misunderstand something about TClonesArray.
>
> This code increase TClonesArray size on demand. It should not change the
> content which has been filled in.
>
> My question are embeded in the comments.
>
> if(theMaxSize < 10) theMaxSize = 10;
> else if(theMaxSize < 30) theMaxSize = 30;
> else if(theMaxSize < 100) theMaxSize = 100;
> else if(theMaxSize < 250) theMaxSize = 250;
> else theMaxSize *= 2;

You can omit these statements. TClonesArray::ExpandCreatefast will do it automatically fot you.

>
> theData->ExpandCreateFast(theMaxSize); //increase Size

ok

>
> theData->Clear(); //Clear the TClonesArray, Does this mean the orignal
> //infomation are lost after that!?

Information in the existing objects is still there, but the pointers to the objects are gone.
Les objects will be reused (refilled in place) by the next new with placement.

>
> for(Int_t entry = 0; entry < theSize; ++entry) theData->AddrAt(entry);
> //AddrAt(Int_t) just return the Object* in specified slot, so it
> //does nothing here?

AddrAt simply returns the pointer to the object in the slot entry.

>
> BTW, this code works. But i just do not know why.
>

Yes, this should work. What is the problem ?

Rene Brun

> Thanks,
>
> Datao
>
Received on Thu Nov 10 2005 - 18:11:05 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET