Dear Rooters,
I encounter the following problems using ROOT files : I have created a class
TStint, which contains just an Int_t. This class TStint derives from
TObject, so it can be saved into a file. The code for this extremely short
class is given in the joined files TStint.h and TStint.cpp. I have compiled
and linked the class Stint and then I have tried the following macro
testf3.C ;
{
TFile f1("litstat1.root","RECREATE");
TStint stia(1);
stia.Write("sti");
stia.Set(2);
stia.Write("sti");
f1.Close();
Int_t i1;
TFile f3("litstat1.root","READ");
TIter nextkey3(f3.GetListOfKeys());
TKey *key3;
TStint *stic;
while (key3 = (TKey *)nextkey3()) {
stic = (TStint *)key3->ReadObj();
i1 = stic->Get();
cout << "i1 : " << i1 << endl;
}
f3.Close();
}
Running this macro, one gets :
root[0] .x testf3.C
i1 : 2
i1 : 1
root[1]
The file is read in reverse order. Why ?
In addition, I have tried the following macro testf4.C, which tries to read
2 files at the same time :
{
TFile f1("litstat1.root","RECREATE");
TStint stia(1);
stia.Write("sti");
stia.Set(2);
stia.Write("sti");
f1.Close();
TFile f2("litstat2.root","RECREATE");
TStint stib(3);
stib.Write("sti");
stib.Set(4);
stib.Write("sti");
f2.Close();
Int_t i1,i2;
TStint *stic;
TStint *stid;
TKey *key3;
TKey *key4;
TFile f3("litstat1.root","READ");
TIter nextkey3(f3.GetListOfKeys());
TFile f4("litstat2.root","READ");
TIter nextkey4(f4.GetListOfKeys());
while (key3 = (TKey *)nextkey3()) {
key4 = (TKey *)nextkey4();
stic = (TStint *)key3->ReadObj();
stid = (TStint *)key4->ReadObj();
i1 = stic->Get();
i2 = stid->Get();
cout << "i1 : " << i1 << " i2 : " << i2 << endl;
}
f3.Close();
f4.Close();
}
Here the result is entirely wrong. It gives :
root[0] .x testf4.C
i1 : 4 i2 : 4
i1 : 3 i2 : 3
root[1]
File f4 is read twice and in reverse order, and file f3 is not read ? What
am I doing wrong ? I use ROOT 2.23/12 on Windows NT.
Thanks a lot if you can help me.
F.X. Gentit
DAPNIA/SPP CEN Saclay
tel : 01 69 08 30 38 fax : 01 69 08 64 28
web : http://home.cern.ch/~gentit/
<<TStint.h>> <<TStint.cpp>> <<testf3.C>> <<testf4.C>>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:22 MET