Re: [ROOT] Saving and loading TExMaps....

From: Edward Moyse (edward.moyse@cern.ch)
Date: Mon Jun 23 2003 - 09:24:39 MEST


Hi Rene,

Thanks! Is there any other way to achieve the same effect in current code? I 
guess I could iterate through TExMap and put value and keys into a normal 
TTree, then read them back in again. Is there an easier way to do it?

The problem is that whilst I can check out and compile the CVS code, the 
analysis I'm writing needs to be used by lots of other people.

Cheers,

Ed

P.S. If there are other classes that are not designed to be persistent, could 
you print an error message if the Write() method is used? It's pretty 
confusing that TExMap has a method which does nothing, but returns no error

On Monday 23 June 2003 9:13 am, you wrote:
> Hi Ed,
>
> TExMap was not designed to be persistent.
> I have modified the class such that your example works.
> Now in CVS.
>
> Rene Brun
>
> Edward Moyse wrote:
> > > The problem is you didn't write your TExMap in the file, so it's normal
> > > you can't get it back afterwards ;-)
> >
> > Oops! ;-)
> >
> > > However if you replace
> > >
> > > hfile->Write("TestMap", TObject::kSingleKey);
> > >
> > > with
> > >
> > > testMap->Write();
> >
> > That was a typo. I actually meant to do:
> > testMap->Write("TestMap", TObject::kSingleKey);
> > because I had already tried the approach you suggested, and  got/get the
> > following problem:
> >
> > root [0] TFile* hfile = new TFile("test.root","RECREATE");
> > root [1] TExMap* testMap = new TExMap();
> > root [2] testMap->Add(1,2);
> > root [3] testMap->Add(2,56);
> > root [4] testMap->Add(3,256);
> > root [5] cout << (testMap->GetValue(2))<<endl;;
> > 56
> > root [6] cout << (testMap->GetValue(1))<<endl;;
> > 2
> > root [8] testMap->Write();
> > root [9] hfile->Close();
> > root [10] gROOT->Reset()
> >
> > Sure enough the TExMap appears to be added to the root file properly:
> >
> > root [14]  TFile f("test.root")
> > root [15] f.ls()
> > TFile**         test.root
> >  TFile*         test.root
> >   KEY: TExMap   TestMap;1       Map with external hash
> >
> > But I can't seem to "Get" it properly:
> >
> > root [12] TExMap *map = (TExMap*)f2.Get("TExMap");
> > root [13] cout << (map->GetValue(2))<<endl;;
> > 0
> > root [14] cout << (map->GetValue(1))<<endl;;
> > 0
> >
> > i.e. it seems to be empty!
> >
> > Any help would be much appreciated!
> >
> > Cheers,
> >
> > Ed



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET