TClonesArray and stl containers

From: Mark Messier <messier_at_indiana.edu>
Date: Tue, 25 Jul 2006 14:46:58 -0400


Hi ROOT,

I was wondering if someone could clarify the restrictions on the use of TClonesArray for me. I apologize in advance if the answer to this question is in the documentation; I couldn't find it.

Suppose I have a class that looks like this:

class Track : public TObject {
public:
  std::vector<TrackPoint> fPoints;
};

where:

class TrackPoint : public TObject {
public:
  float fX, fY, fZ;
};

Notice that the "TrackPoints" are fixed size and stored in Track by value. Q: Can I correctly store Track objects in a TClonesArray?

The web documentation for TClonesArray says that the objects stored must all be of the same class, which would imply that I could store this particular class in a TClonesArray so long as I don't mix other TObjects into the array.

However, the .pdf documentation for TClonesArrays says that object must be of the same class and same size, which implies to me that this class cannot be stored correctly as the size of the std::vector<> may vary.

My simple tests of this seem to indicate that its OK to store this class in a TClonesArray, but if the incorrect behavior is resulting in unpredictable memory corruption my simple tests cannot be guaranteed to fail, so I don't have much confidence in the test results.

It would be useful to me if the documentation of TClonesArrays contained some examples of classes that can and cannot correctly stored.

Thanks in advance for any replies.

Cheers,
Mark

-- 
Mark Messier                                 e-mail: messier_at_indiana.edu
Department of Physics            http://www.physics.indiana.edu/~messier
Indiana University                                 Phone: (812) 855-0236
Bloomington, IN 47405                                Fax: (812) 855-0440
Received on Tue Jul 25 2006 - 20:47:07 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:00 MET