Hi Chiara,
TObject/TFile::Write and TFile::GetObject only writing/read one top level object. In other it will not work with a C-Style array. Please use a TObjArray (or TClonesArray, or std::vector) instead.
Cheers,
Philippe.
-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch]
On Behalf Of chiara zampolli
Sent: Saturday, November 26, 2005 10:00 AM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] writing/reading arrays to/from a file
Dear rooters,
I have a problem similar to the one I had some days ago. As before, I am trying to write/read an array of objects to/from a file, but in this case the array is not the data member of a class (so that when writing the object of the class, I write the array), but it is exactly what I have to write. Here you find some code lines which explain what I would like to do (see also the attached testchsim.C):
void testchsim()
{
AliTOFChSim *ch;
ch = new AliTOFChSim[1000];
ch[0].SetMaxToT(3); ch[0].SetMinToT(4); ch[4].SetMaxToT(2); ch[4].SetMaxToT(5);
where AliTOFChSim inherits from TObject (it is a class I have defined, where the MaxToT and MinToT are two data members - you can find it in the attached files). As you can see from the output of the macro:
root [15] .x testchsim.C
ch[1] = 0x9f9afe8
max 0 = 3 min 0 = 4 max 4 = 5 min 4 = 0 max 0 = 3 min 0 = 4 max 4 = -0.0618096 min 4 = 1.1992e-11 max 4 = -0.0618096 min 4 = 1.1992e-11
when trying to read back my array, its elements seem to be empty (apart from the first one, element zero). What am I doing wrong?
Thank you for your help.
Cheers,
Chiara Received on Wed Nov 30 2005 - 23:50:57 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:14 MET