Re: Retrieving elements from a TObjArray

From: Fons Rademakers <Fons.Rademakers_at_cern.ch>
Date: Sat, 29 Oct 2005 15:20:13 +0200


Dear Chiara,

   I assume you filled the objarray with the loop:

for (int i = 0; i < 10; i++) and not i++; i < 10. Anyway, to read the objarray do:

TObjArray *objarray;

file->GetObject(“array”,objarray);
AliTOFUncalib * element0 = (AliTOFUncalib*)objarray->At(0); AliTOFUncalib * element1 = (AliTOFUncalib*)objarray->At(1);

because objarray is now a pointer so the operator[] does not work (need to have a reference or object and not a pointer).

Cheers, Fons.

Chiara Zampolli wrote:
> Dear rooters,
>
>
>
> I have written a TObjArray made up of elements which are
> AliTOFUncalib class istances, each defined in this way:
>
>
>
> TObjArray UCdata(10);
>
> For (Int_t i =0; i ++; i < 10) {
>
> UCdata[i] = new AliTOFUncalib();
>
> AliTOFUncalib *ciccio = (AliTOFUncalib*)UCdata.At(i);
>
> ciccio->Set....
>
> ...
>
> }
>
> After writing the TObjArray in the root file with the name “array”, I
> retrieve it with:
>
>
>
> TObjArray* objarray;
>
> file->GetObject("array", "objarray");
>
>
>
> Now, I try to pick up each element of the array in this way:
>
>
>
> TFile * file = new TFile(…);
>
> TObjArray * objarray;
>
> file->GetObject(“array”,objarray);
>
> AliTOFUncalib * element0 = (AliTOFUncalib*)objarray[0];
>
> AliTOFUncalib * element1 = (AliTOFUncalib*)objarray[1];
>
>
>
> But this doesn’y work!!! There seems to be a problem with a sort of
> “conversion” from TObjArray type to AliTOFUncalib type…I have tried some
> other ways, but with no success.
>
>
>
> Could you help me? How can I retrieve the elements of the TObjArray
> which are of type AliTOFUncalib?
>
> Thank you a lot.
>
> Cheers,
>
> Chiara
>
>
>

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers_at_cern.ch              Phone: +41 22 7679248
WWW:    http://www.rademakers.org/fons/      Fax:   +41 22 7679480
Received on Sat Oct 29 2005 - 15:20:10 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET