Hi Edward, The problem is you didn't write your TExMap in the file, so it's normal you can't get it back afterwards ;-) If you execute your first script, then open the file and list its contents you see: root [0] TFile f("test.root") root [1] f.ls() TFile** test.root TFile* test.root However if you replace hfile->Write("TestMap", TObject::kSingleKey); with testMap->Write(); then the file listing you get looks like this: root [0] TFile f("test.root") root [1] f.ls() TFile** test.root TFile* test.root KEY: TExMap TExMap;1 Map with external hash Therefore you can "Get" your TExMap with TExMap *l = (TExMap*)f.Get("TExMap"); I was going to say 'if you want to use Get("TestMap") then you should do a testMap->SetName("TestMap") before you write it in the file", but unfortunately I have just discovered that TExMap is a TObject, not a TNamed. :-D Hope this helps John Frankland Edward Moyse wrote: >Hi, > >Can anyone help with this problem? I need to save TExMap objects to disk, and >read them back later, and I can't find any useful examples, not work it out >myself. > >If I do: > >{ > TFile* hfile = new TFile("test.root","RECREATE"); > TExMap* testMap = new TExMap(); > testMap->Add(1,2); > testMap->Add(2,56); > testMap->Add(3,256); > cout << (testMap->GetValue(2))<<endl;; > cout << (testMap->GetValue(1))<<endl;; > cout << (testMap->GetValue(100))<<endl;; > hfile->Write("TestMap", TObject::kSingleKey); > hfile->Close(); >} > > > >Followed by : >{ >TFile f2("test.root", "READ"); >TExMap *l = (TExMap*)f2.Get("TestMap"); >cout << (l->GetValue(2))<<endl;; >cout << (l->GetValue(1))<<endl;; >} > >I get the error: >Error: illegal pointer to class object l 0x0 358 FILE:testExMapLoad.C LINE:5 >*** Interpreter error recovered *** > >I've been trying for horus now, using several different approaches, and I >can't work out what's wrong! > >Any help would be VERY appreciated! > >Cheers, > >Ed > > > > > -- John D. Frankland Beam Coordinator GANIL B.P. 55027 14076 CAEN Cedex 05 tel: +33 (0)231454628 fax: +33 (0)231454665
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:12 MET