Hi Julien, See your main.C file modified below. (see comments) Read chapter about Object Ownership in the Users guide Rene Brun { gSystem->Load("libTExpositionMap.so"); TObjArray *A = new TObjArray(1); TFile f("expo-time.tree.root"); if(f.IsZombie()) { return; } else { TTree *tree = (TTree *)f.Get("tree"); TBranch *branch = tree->GetBranch("Exposition_Maps"); TExpositionMap *emap =0; branch->SetAddress(&emap); TH1::AddDirectory(kFALSE); //by default histograms are addeed to the current dir for(Int_t i = 0 ; i < tree->GetEntries() ; i++) { branch->GetEntry(i); A->AddLast(emap); } TExpositionMap *emap2 = (TExpositionMap *)A->At(15); TH2D *map2 = emap2->GetHExpoMap(); cout << map2->GetBinContent(10,10) << endl; f.Close(); //histogram in the current dirs are deleted TExpositionMap *emap3 = (TExpositionMap *)A->At(15); TH2D *map3 = emap3->GetHExpoMap(); cout << map3->GetBinContent(10,10) << endl; } } On Mon, 6 Sep 2004, Julien Bolmont wrote: > > Hi Rene, > > Here is a short program reproducing my problem. > 1. Build the library typing : > make (I hope it will work this time !) > 2. Run the macro "main.C". It should write "18240" twice with ROOT > 3.10/02 and only once with ROOT 4.00/08 because in this version, > TFile::Close() seems to destroy all objects read in the file which > leads to a Seg. Fault. > > Could you explain me why the two versions have such different > behaviours ? > What is the proper way to manage ressources from a TFile ? Shall I keep > it open from the beginning to the end of the execution ? > > Thanks again, > Julien > >
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET