Introduce TClonesArray::ConstructedAt which
always returns an already constructed object. If the slot is being used for the
first time, it calls the default constructor otherwise it returns the object as
is (unless a string is passed as the 2nd argument to the function in which case,
it also calls Clear(second_argument) on the object).
This allows to replace code like:
for (int i = 0; i < ev->Ntracks; i++) {
new(a[i]) TTrack(x,y,z,...);
...
...
}
...
a.Delete(); // or a.Clear("C")
with the simpler and more efficient:
for (int i = 0; i < ev->Ntracks; i++) {
TTrack *track = (TTrack*)a.ConstructedAt(i);
track->Set(x,y,z,....);
...
...
}
...
a.Clear();
even in case where the TTrack class allocates memory.