I have a class that I am using in my event which has a TRefArray on each object of a TClonesArray. The referenced objects are being added using the TRefArray::Add() method.
But the code is not behaving as I would expect. For the first event, everything looks fine. I see the right number of objects from the ref array in my analysis script.
But for subsequent events after the first, something gets very screwy, and not all the object references are being saved. So I get error messages like …
Error in <TRefArray::At>: index 3 out of bounds (size: 3, this: 0x364bd00)
Even though I add 30 objects to this array in my sim program, when I go to read the events back, ROOT says the size of the array is only 3!
I think I am doing the right thing in my class for clearing this data between events …
Is the simParticleContribs array the TClonesArray or the TRefArray. Is the TRefArray also clearer? In Clear why call Delete on the array?
Cheers,
Philippe.[/quote]
simParticleContribs is the TRefArray (I can provide the header file if needed). It lives in an object that is within a TClonesArray in my event model class.
My understanding was that I need to call Delete() on the TRefArray pointer to avoid a memory leak and possible IO corruption/problems; I ran into problems before when I didn’t do this. I have another class that uses a TRefArray and calls Delete() and it seems to work okay. But here I have something a bit more complicated (the TRefArray can have 1-30+ references in it), and it is not behaving at all how I would expect.