Re: Read/Write of hash tables

Tioukov Valeri (valeri@d500na1.na.infn.it)
Tue, 6 Jul 1999 14:58:14 +0200 (MET DST)


This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--0-966490085-931265894=:15742
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi Fons,

In your macro the contents of the object (string) is equivalent to
its Hash() value, so it could not demonstrate the problem.

I attached to this mail the modified macro where I fill for each string
also fUniqueID to have in the object something different from it's Hash
parameter.

the output of the macro is:

root [0] .L f.C
root [1] hhh()
It was in the memory before storing to file
ID = 0 TObjString = aap 0
ID = 1 TObjString = aap 1
ID = 100 TObjString = aap 0
ID = 101 TObjString = aap 1
It is in the memory after restoring
ID = 0 TObjString = aap 0
ID = 1 TObjString = aap 1
ID = 0 TObjString = aap 0
ID = 1 TObjString = aap 1

As far as I understand there is no any bug here - it's just a mechanizm
how you store the objects to file: the objects of the same type with the
same Hash() parameter are always considered the same.

The question: if you have more then 1 hash tables with different objects
of the same type and Hash() is unique inside each table but could be the
same for objects from different tables how you store it?

Regards
Valeri

On Tue, 6 Jul 1999, Fons Rademakers wrote:

> Hi Valeri,
>
> I tried the following macro:
>
> {
> gROOT->Reset();
>
> char s[32];
>
> THashList *l = new THashList;
>
> for (int i = 0; i < 10; i++) {
> THashList *h = new THashList;
> l->Add(h);
> for (int j = 0; j < 10; j++) {
> sprintf(s, "aap %d", j);
> h->Add(new TObjString(s));
> }
> }
> }
>
> is that something like what you try doing?
> To store such a collection use something like:
>
> TFile x("hash.root","recreate")
> l.Write("l",TObject::kSingleKey)
>
> and to read it do:
>
> TFile x("hash1.root")
> THashList *l = (THashList*)x.Get("l")
> l->Print();
>
> or is this not what you want?
>
>
> Cheers, Fons.
>
>
>
>
> Tioukov Valeri wrote:
> >
> > Hi rooters,
> >
> > I have data structure organized as following:
> >
> > THashList of objects type A
> > where A is
> > THashList of objects type B
> >
> > The Hash() of objects B is unic inside A but could be the same for
> > B's from different A's.
> >
> > It worked perfectly before I tried to store and restore this staff.
> >
> > I note that after restoring the objects B with the same Hash() becomes
> > the first stored B.
> > So Hash() of any objects treated as the global one during the storing.
> >
> > But if I'd like to have the structure as described above and I want to
> > store it. Is it possible to do in the correct way?
> >
> > Best regards
> > Valeri
>
> --
> Org: CERN, European Laboratory for Particle Physics.
> Mail: 1211 Geneve 23, Switzerland
> E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248
> WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910
>

--0-966490085-931265894=:15742
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="f.C"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.OSF.3.95a.990706145814.15742C@d500na1.na.infn.it>
Content-Description:

dm9pZCBoaGgoKQ0Kew0KICB3KCk7DQogIHIoKTsNCn0NCg0Kdm9pZCB3KCkN
CnsNCiAgIGdST09ULT5SZXNldCgpOw0KDQogICBjaGFyIHNbMzJdOw0KICAg
VE9ialN0cmluZyAqb3M9MDsNCg0KICAgVEhhc2hMaXN0ICpsID0gbmV3IFRI
YXNoTGlzdDsNCg0KICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyOyBpKyspIHsN
CiAgICAgIFRIYXNoTGlzdCAqaCA9IG5ldyBUSGFzaExpc3Q7DQogICAgICBs
LT5BZGQoaCk7DQogICAgICBmb3IgKGludCBqID0gMDsgaiA8IDI7IGorKykg
ew0KICAgICAgICAgc3ByaW50ZihzLCAiYWFwICVkIiwgaik7DQoJIG9zID0g
bmV3IFRPYmpTdHJpbmcocyk7DQogICAgICAgICBvcy0+U2V0VW5pcXVlSUQo
MTAwKmkraik7DQogICAgICAgICBoLT5BZGQob3MpOw0KICAgICAgfQ0KICAg
fQ0KDQogICBwcmludGYoIkl0IHdhcyBpbiB0aGUgbWVtb3J5IGJlZm9yZSBz
dG9yaW5nIHRvIGZpbGVcbiIpOyANCiAgIGZvciAoaW50IGkgPSAwOyBpIDwg
MjsgaSsrKSB7DQogICAgIGggPSAoVEhhc2hMaXN0KikobC0+QXQoaSkpOw0K
ICAgICBmb3IgKGludCBqID0gMDsgaiA8IDI7IGorKykgew0KICAgICAgIG9z
ID0gKFRPYmpTdHJpbmcqKSggaC0+QXQoaikgKTsNCiAgICAgICBwcmludGYo
IklEID0gJWQgICIsIG9zLT5HZXRVbmlxdWVJRCgpKTsgICAgb3MtPlByaW50
KCk7DQogICAgIH0NCiAgIH0NCg0KICAgVEZpbGUgZigiZi5yb290IiwiUkVD
UkVBVEUiKTsNCiAgIGwtPldyaXRlKCJsIiwxKTsNCiAgIGYuQ2xvc2UoKTsN
Cn0NCg0Kdm9pZCByKCkNCnsNCiAgIGdST09ULT5SZXNldCgpOw0KICAgVEZp
bGUgZigiZi5yb290Iik7DQoNCiAgIFRIYXNoTGlzdCAqaDsNCiAgIFRPYmpT
dHJpbmcgb3M7DQoNCiAgIHByaW50ZigiSXQgaXMgaW4gdGhlIG1lbW9yeSBh
ZnRlciByZXN0b3JpbmdcbiIpOyANCiAgIGZvciAoaW50IGkgPSAwOyBpIDwg
MjsgaSsrKSB7DQogICAgIGggPSAoVEhhc2hMaXN0KikobC0+QXQoaSkpOw0K
ICAgICBmb3IgKGludCBqID0gMDsgaiA8IDI7IGorKykgew0KICAgICAgIG9z
ID0gKFRPYmpTdHJpbmcqKSggaC0+QXQoaikgKTsNCiAgICAgICBwcmludGYo
IklEID0gJWQgICIsIG9zLT5HZXRVbmlxdWVJRCgpKTsgICAgb3MtPlByaW50
KCk7DQogICAgIH0NCiAgIH0NCn0NCg==
--0-966490085-931265894=:15742--