Re: Read/Write of hash tables

From: Tioukov Valeri (valeri@d500na1.na.infn.it)
Date: Tue Jul 06 1999 - 14:58:14 MEST


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
> 


void hhh()
{
  w();
  r();
}

void w()
{
   gROOT->Reset();

   char s[32];
   TObjString *os=0;

   THashList *l = new THashList;

   for (int i = 0; i < 2; i++) {
      THashList *h = new THashList;
      l->Add(h);
      for (int j = 0; j < 2; j++) {
         sprintf(s, "aap %d", j);
	 os = new TObjString(s);
         os->SetUniqueID(100*i+j);
         h->Add(os);
      }
   }

   printf("It was in the memory before storing to file\n"); 
   for (int i = 0; i < 2; i++) {
     h = (THashList*)(l->At(i));
     for (int j = 0; j < 2; j++) {
       os = (TObjString*)( h->At(j) );
       printf("ID = %d  ", os->GetUniqueID());    os->Print();
     }
   }

   TFile f("f.root","RECREATE");
   l->Write("l",1);
   f.Close();
}

void r()
{
   gROOT->Reset();
   TFile f("f.root");

   THashList *h;
   TObjString os;

   printf("It is in the memory after restoring\n"); 
   for (int i = 0; i < 2; i++) {
     h = (THashList*)(l->At(i));
     for (int j = 0; j < 2; j++) {
       os = (TObjString*)( h->At(j) );
       printf("ID = %d  ", os->GetUniqueID());    os->Print();
     }
   }
}



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:35 MET