[ROOT] Is there a "true" clone function for TH1F ?

From: Pierre-Luc Drouin (pldrouin@physics.carleton.ca)
Date: Thu Jul 25 2002 - 16:56:11 MEST


Hello,

I'm looking for a "true" Clone function for TH1F. To illustrate what I
mean, here is a part of my code (fPDF is a TH1F* member variable of QDis):

int QDis::LoadPDF(const char *aPDFFileName, const char *aPDFHistogramName)
{
  // Loads a PDF histogram from a file with the proper attributes.
  ClearPDF();
  TFile *f = new TFile(aPDFFileName, "READ");
  TH1F* th1fbuf = dynamic_cast<TH1F*>(f->Get(aPDFHistogramName));
  if(th1fbuf){
    fPDF=dynamic_cast<TH1F*>(th1fbuf->Clone());
  }
  f->Close();
  delete f;
  return (th1fbuf && fPDF);
}

void QDis::ClearPDF(){
if(fPDF){
        delete fPDF;
        fPDF=NULL;
}
}

Here is a simple main() function:
int main();

int main()
{
  QDis mydis;
  mydis.LoadPDF("observed.root","observed");
  mydis.ClearPDF();
}

Since the instance of fPDF seems to share some pointers with the
instance of th1fbuf (and of TFile *f), I get an error
message when I try to call ClearPDF() in
main(), because f has been deleted in LoadPDF. So, is there a
"true" Clone() member function for TH1F? I've tried the Copy() member
function, but I get the same error:

 *** Break *** segmentation violation

Thank you!
Pierre-Luc Drouin
SNO, Carleton University



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:01 MET