Re: [ROOT] Seg. Fault with ROOT 4.00/08 but not with ROOT 3.10/02

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Sep 07 2004 - 11:50:43 MEST


Hi julien,

Your loop may be simplified like below;

    TTree *tree = (TTree *)f.Get("tree");
    TBranch *branch = tree->GetBranch("Exposition_Maps");
    TH1::AddDirectory(kFALSE); //by default histograms are addeed to the current
dir  
    for(Int_t i = 0 ; i < tree->GetEntries() ; i++) {
      TExpositionMap *emap = 0;
      branch->SetAddress(&emap);
      branch->GetEntry(i);
      
      A->AddLast(emap);
    }


Rene Brun

Julien Bolmont wrote:
> 
> Hi Rene,
> 
> Thanks again for your help !
> Actually, I have one more thing to point out about the script below.
> In this script, it's just like you load 44 times the last object into
> the TObjArray because each time you perform branch->GetEntry(), you
> modify the pointer emap and then all objects already stored in the
> TObjArray.
> That's why I had written it this way :
> 
> for(Int_t i = 0 ; i < tree->GetEntries() ; i++) {
> 
> TExpositionMap *emap = new TExpositionMap();
> branch->SetAddress(emap);
> branch->GetEntry();
> A->AddLast(emap);
> 
> }
> 
> to really have 44 different objects TExpositionMap and not 44 times the
> same.
> 
> Is there a better way to do that ?
> 
> Bye,
> Julien
> 
> Le 6 sept. 04, à 22:25, Rene Brun a écrit :
> 
> > 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
> >>
> >>
> >
> >
> ------------------------------------------------------
> Julien Bolmont
> Ingénieur diplômé - doctorant
> Groupe d'Astroparticules de Montpellier



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET