RE: TClonesArray and stl containers

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Tue, 25 Jul 2006 16:32:31 -0500


> I would still be curious to know what sort of classes (if any) cannot be
> stored in TClonesArrays.

There is no longer any restriction. However, it is more efficient to avoid the case where you have a data member which is a pointer to something.

Cheers,
Philippe

-----Original Message-----
From: Mark Messier [mailto:messier_at_indiana.edu] Sent: Tuesday, July 25, 2006 4:14 PM
To: Philippe Canal
Cc: roottalk_at_pcroot.cern.ch
Subject: RE: [ROOT] TClonesArray and stl containers

Dear Philippe,

Thanks for the quick reply. The .pdf I downloaded was the "Collection Classes" (V5.12) file posted here:
http://root.cern.ch/root/doc/RootDoc.html.

I would still be curious to know what sort of classes (if any) cannot be stored in TClonesArrays.

Cheers,
Mark

On Tue, 2006-07-25 at 17:03, Philippe Canal wrote:
> > Q: Can I correctly store Track objects in a TClonesArray?
>
> Yes.
>
> > However, the .pdf documentation for TClonesArrays says that object must
> > be of the same class and same size,
>
> This is obsolete. Which pdf file did you download?
>
> Cheers,
> Philippe
>
> -----Original Message-----
> From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch]
> On Behalf Of Mark Messier
> Sent: Tuesday, July 25, 2006 1:47 PM
> To: roottalk_at_pcroot.cern.ch
> Subject: [ROOT] TClonesArray and stl containers
>
> 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 - 23:35:50 MEST

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