TClonesArray::AddAt

Pasha Murat (murat@cdfsga.fnal.gov)
Wed, 24 Dec 1997 05:22:52 GMT


Hi Steve,

you understand everything correctly however what you are observing is not
a bug but something intentionally put into design (which is not what is called
"design feature"). TClonesArray is designed to behave very much like
a regular array of pointers to *the same* objects and not like STL container.
It is optimised for handling arrays of clones as its name states. In particular
it means that all your track objects should have the *same* length.
You can't insert new pointers in the middle of TClonesArray, however [] operator
is smart enough to expand TClonesArray if necessary so you can't overwrite
(write out of) it.

Run-time message you are getting says that the corresponding virtual Add*
methods of TSeqCollection from which TClonesArray is derived have been
explicitly defined for TClonesArray to overwtrite corresponding methods
of TObjArray (which is also a base class for TClonesArray). You may want
to use TObjArray instead of TClonesArray to get more container-like and
less array-like behaviour.

Regards, Pasha.
--------------------------------------------------------------------------------
Stephen_Eichblatt writes:
>
> Hello,
>
> I am building a class to use in ROOT. I want to use a TClonesArray
> to store an array of my subclass.
> >From reading the documentation, i see that the TClonesArray::AddAt
> is the method i want to use to add elements.
> eg:
>
> fTracks->AddAt((TObject *)track,i);
>
> where fTracks is a TClonesArray* .
>
> When i use it, i get the run-time message:
>
> Warning in <TClonesArray::AddAt>: may not use this method
>
>
> I then decided that TClonesArray::AddLast would suit my needs, but
> i get a similar run-time error.
> Similarly for AddAfter & AddFirst.
>
> In the end, i do it like the Event / Track example, using the
>
> TClonesArray &tracks = *fTracks;
> new(tracks[fNtrack++]) Track(random);
>
> which works. Is this a bug or am i misunderstanding the documentation?
>
> I am using Linux version 1.03/06.
>
> Thank you very much.
>
> Steve Eichblatt
> eichblatt@fnal.gov