[ROOT] Question about TClonesArray and copy

From: Thomas Bretz (tbretz@astro.uni-wuerzburg.de)
Date: Fri Sep 12 2003 - 18:01:59 MEST


Dear all,

I want to copy a TClonesArray from array1 to array2:

class MyClass:public TObject { public: Double_t d; };

TClonesArray a1("MyClass", 20);
TClonesArray a2("MyClass", 10);

// call "new (a1[i]) MyClass;" for all entries in a1 and a2

Is it enough to do:
a2.ExpandCreate(a1.GetEntriesFast());
memcpy(&a2, &a1, sizeof(a1));

or must I do something like:
const Int_t n = a1.GetEntriesFast();
a2.InitSize(n);
for (int i=0; i<n; i++)
    a2.d = a1.d;

BTW: MyClass contains plain values (basic data types) _only_.

Thanks in advance,
Thomas.



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET