Skip to content

Commit

Permalink
Make sure changed labels are kept after a clone (fix ROOT-10580) (#5041)
Browse files Browse the repository at this point in the history
* Make sure changed labels are kept after a clone (fix ROOT-10580)

* new version using TObject::Clone...

* Fix to avoid double delete of fHistogram

* Use TNamed::Clone
remove spaces
  • Loading branch information
couet committed Feb 24, 2020
1 parent 8795698 commit 740d3dd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hist/hist/inc/TF1.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class TF1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
static Bool_t DefaultAddToGlobalList(Bool_t on = kTRUE);
virtual void Browse(TBrowser *b);
virtual void Copy(TObject &f1) const;
TObject* Clone(const char* newname=0) const;
virtual Double_t Derivative(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
virtual Double_t Derivative2(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
virtual Double_t Derivative3(Double_t x, Double_t *params = 0, Double_t epsilon = 0.001) const;
Expand Down Expand Up @@ -774,7 +775,7 @@ T TF1::EvalPar(const T *x, const Double_t *params)
////////////////////////////////////////////////////////////////////////////////
/// Eval for vectorized functions
// template <class T>
// T TF1::Eval(T x, T y, T z, T t) const
// T TF1::Eval(T x, T y, T z, T t) const
// {
// if (fType == EFType::kFormula)
// return fFormula->Eval(x, y, z, t);
Expand Down
12 changes: 12 additions & 0 deletions hist/hist/src/TAxis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ void TAxis::Copy(TObject &obj) const
delete axis.fModLabs;
axis.fModLabs = 0;
}
if (fModLabs) {
TIter next(fModLabs);
TAxisModLab *modlabel;
if(! axis.fModLabs) {
axis.fModLabs = new TList();
}
while( (modlabel=(TAxisModLab*)next()) ) {
TAxisModLab *copyModLabel = new TAxisModLab(*modlabel);
axis.fModLabs->Add(copyModLabel);
copyModLabel->SetUniqueID(modlabel->GetUniqueID());
}
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 19 additions & 1 deletion hist/hist/src/TF1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ TF1::~TF1()

if (fFormula) delete fFormula;
if (fParams) delete fParams;
if (fFunctor) delete fFunctor;
if (fFunctor) delete fFunctor;
}


Expand Down Expand Up @@ -1059,6 +1059,24 @@ void TF1::Copy(TObject &obj) const
}


////////////////////////////////////////////////////////////////////////////////
/// Make a complete copy of the underlying object. If 'newname' is set,
/// the copy's name will be set to that name.

TObject* TF1::Clone(const char*) const
{

TF1* obj = (TF1*) TNamed::Clone();

if (fHistogram) {
obj->fHistogram = (TH1*)fHistogram->Clone();
obj->fHistogram->SetDirectory(0);
}

return obj;
}


////////////////////////////////////////////////////////////////////////////////
/// Returns the first derivative of the function at point x,
/// computed by Richardson's extrapolation method (use 2 derivative estimates
Expand Down

0 comments on commit 740d3dd

Please sign in to comment.