Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions core/cont/src/TClonesArray.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ When investigating misuse of TClonesArray, please make sure of the following:

ClassImp(TClonesArray);

// To allow backward compatibility of TClonesArray of v5 TF1 objects
// that were stored member-wise.
using Updater_t = void (*)(Int_t nobjects, TObject **from, TObject **to);
Updater_t gClonesArrayTF1Updater = nullptr;
Updater_t gClonesArrayTFormulaUpdater = nullptr;

bool R__SetClonesArrayTF1Updater(Updater_t func) {
gClonesArrayTF1Updater = func;
return true;
}

bool R__SetClonesArrayTFormulaUpdater(Updater_t func) {
gClonesArrayTFormulaUpdater = func;
return true;
}

/// Internal Utility routine to correctly release the memory for an object
static inline void R__ReleaseMemory(TClass *cl, TObject *obj)
{
Expand Down Expand Up @@ -453,6 +469,10 @@ void TClonesArray::Expand(Int_t newSize)
Error ("Expand", "newSize must be positive (%d)", newSize);
return;
}
if (!fKeep) {
Error("ExpandCreate", "Not initialized properly, fKeep is still a nullptr");
return;
}
if (newSize == fSize)
return;
if (newSize < fSize) {
Expand Down Expand Up @@ -481,7 +501,11 @@ void TClonesArray::ExpandCreate(Int_t n)
{
if (n < 0) {
Error("ExpandCreate", "n must be positive (%d)", n);
return ;
return;
}
if (!fKeep) {
Error("ExpandCreate", "Not initialized properly, fKeep is still a nullptr");
return;
}
if (n > fSize)
Expand(TMath::Max(n, GrowBy(fSize)));
Expand Down Expand Up @@ -778,9 +802,28 @@ void TClonesArray::Streamer(TBuffer &b)

fCont[i] = fKeep->fCont[i];
}
//sinfo->ReadBufferClones(b,this,nobjects,-1,0);
b.ReadClones(this,nobjects,clv);

if (clv < 8 && classv == "TF1") {
// To allow backward compatibility of TClonesArray of v5 TF1 objects
// that were stored member-wise.
TClonesArray temp("ROOT::v5::TF1Data");
temp.ExpandCreate(nobjects);
b.ReadClones(&temp, nobjects, clv);
// And now covert the v5 into the current
if (gClonesArrayTF1Updater)
gClonesArrayTF1Updater(nobjects, temp.GetObjectRef(nullptr), this->GetObjectRef(nullptr));
} else if (clv <= 8 && clv > 3 && clv != 6 && classv == "TFormula") {
// To allow backwar compatibility of TClonesArray of v5 TF1 objects
// that were stored member-wise.
TClonesArray temp("ROOT::v5::TFormula");
temp.ExpandCreate(nobjects);
b.ReadClones(&temp, nobjects, clv);
// And now covert the v5 into the current
if (gClonesArrayTFormulaUpdater)
gClonesArrayTFormulaUpdater(nobjects, temp.GetObjectRef(nullptr), this->GetObjectRef(nullptr));
} else {
// sinfo->ReadBufferClones(b,this,nobjects,-1,0);
b.ReadClones(this, nobjects, clv);
}
} else {
for (Int_t i = 0; i < nobjects; i++) {
b >> nch;
Expand Down
146 changes: 90 additions & 56 deletions hist/hist/src/TF1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,94 @@ Bool_t TF1::fgRejectPoint = kFALSE;
std::atomic<Bool_t> TF1::fgAddToGlobList(kTRUE);
static Double_t gErrorTF1 = 0;

using TF1Updater_t = void (*)(Int_t nobjects, TObject **from, TObject **to);
bool R__SetClonesArrayTF1Updater(TF1Updater_t func);


namespace {
struct TF1v5Convert : public TF1 {
public:
void Convert(ROOT::v5::TF1Data &from)
{
// convert old TF1 to new one
fNpar = from.GetNpar();
fNdim = from.GetNdim();
if (from.fType == 0) {
// formula functions
// if ndim is not 1 set xmin max to zero to avoid error in ctor
double xmin = from.fXmin;
double xmax = from.fXmax;
if (fNdim > 1) {
xmin = 0;
xmax = 0;
}
TF1 fnew(from.GetName(), from.GetExpFormula(), xmin, xmax);
if (fNdim > 1) {
fnew.SetRange(from.fXmin, from.fXmax);
}
fnew.Copy(*this);
// need to set parameter values
if (from.GetParameters())
fFormula->SetParameters(from.GetParameters());
} else {
// case of a function pointers
fParams = new TF1Parameters(fNpar);
fName = from.GetName();
fTitle = from.GetTitle();
// need to set parameter values
if (from.GetParameters())
fParams->SetParameters(from.GetParameters());
}
// copy the other data members
fNpx = from.fNpx;
fType = (EFType)from.fType;
fNpfits = from.fNpfits;
fNDF = from.fNDF;
fChisquare = from.fChisquare;
fMaximum = from.fMaximum;
fMinimum = from.fMinimum;
fXmin = from.fXmin;
fXmax = from.fXmax;

if (from.fParErrors)
fParErrors = std::vector<Double_t>(from.fParErrors, from.fParErrors + fNpar);
if (from.fParMin)
fParMin = std::vector<Double_t>(from.fParMin, from.fParMin + fNpar);
if (from.fParMax)
fParMax = std::vector<Double_t>(from.fParMax, from.fParMax + fNpar);
if (from.fNsave > 0) {
assert(from.fSave);
fSave = std::vector<Double_t>(from.fSave, from.fSave + from.fNsave);
}
// set the bits
for (int ibit = 0; ibit < 24; ++ibit)
if (from.TestBit(BIT(ibit)))
SetBit(BIT(ibit));

// copy the graph attributes
auto &fromLine = static_cast<TAttLine &>(from);
fromLine.Copy(*this);
auto &fromFill = static_cast<TAttFill &>(from);
fromFill.Copy(*this);
auto &fromMarker = static_cast<TAttMarker &>(from);
fromMarker.Copy(*this);
}
};
} // unnamed namespace

static void R__v5TF1Updater(Int_t nobjects, TObject **from, TObject **to)
{
auto **fromv5 = (ROOT::v5::TF1Data **)from;
auto **target = (TF1v5Convert **)to;

for (int i = 0; i < nobjects; ++i) {
if (fromv5[i] && target[i])
target[i]->Convert(*fromv5[i]);
}
}

static int R__RegisterTF1UpdaterTrigger = R__SetClonesArrayTF1Updater(R__v5TF1Updater);

ClassImp(TF1);

// class wrapping evaluation of TF1(x) - y0
Expand Down Expand Up @@ -1764,8 +1852,7 @@ Double_t TF1::GetX(Double_t fy, Double_t xmin, Double_t xmax, Double_t epsilon,
brf.SetLogScan(logx);
bool ret = brf.Solve(maxiter, epsilon, epsilon);
if (!ret) Error("GetX","[%f,%f] is not a valid interval",xmin,xmax);
return (ret) ? brf.Root() : TMath::QuietNaN();

return (ret) ? brf.Root() : TMath::QuietNaN();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3490,60 +3577,7 @@ void TF1::Streamer(TBuffer &b)
//printf("Reading TF1 as v5::TF1Data- version %d \n",v);
fold.Streamer(b, v, R__s, R__c, TF1::Class());
// convert old TF1 to new one
fNpar = fold.GetNpar();
fNdim = fold.GetNdim();
if (fold.fType == 0) {
// formula functions
// if ndim is not 1 set xmin max to zero to avoid error in ctor
double xmin = fold.fXmin;
double xmax = fold.fXmax;
if (fNdim > 1) {
xmin = 0;
xmax = 0;
}
TF1 fnew(fold.GetName(), fold.GetExpFormula(), xmin, xmax);
if (fNdim > 1) {
fnew.SetRange(fold.fXmin, fold.fXmax);
}
fnew.Copy(*this);
} else {
// case of a function pointers
fParams = new TF1Parameters(fNpar);
fName = fold.GetName();
fTitle = fold.GetTitle();
}
// need to set parameter values
SetParameters(fold.GetParameters());
// copy the other data members
fNpx = fold.fNpx;
fType = (EFType) fold.fType;
fNpfits = fold.fNpfits;
fNDF = fold.fNDF;
fChisquare = fold.fChisquare;
fMaximum = fold.fMaximum;
fMinimum = fold.fMinimum;
fXmin = fold.fXmin;
fXmax = fold.fXmax;

if (fold.fParErrors) fParErrors = std::vector<Double_t>(fold.fParErrors, fold.fParErrors + fNpar);
if (fold.fParMin) fParMin = std::vector<Double_t>(fold.fParMin, fold.fParMin + fNpar);
if (fold.fParMax) fParMax = std::vector<Double_t>(fold.fParMax, fold.fParMax + fNpar);
if (fold.fNsave > 0) {
assert(fold.fSave);
fSave = std::vector<Double_t>(fold.fSave, fold.fSave + fold.fNsave);
}
// set the bits
for (int ibit = 0; ibit < 24; ++ibit)
if (fold.TestBit(BIT(ibit))) SetBit(BIT(ibit));

// copy the graph attributes
TAttLine &fOldLine = static_cast<TAttLine &>(fold);
fOldLine.Copy(*this);
TAttFill &fOldFill = static_cast<TAttFill &>(fold);
fOldFill.Copy(*this);
TAttMarker &fOldMarker = static_cast<TAttMarker &>(fold);
fOldMarker.Copy(*this);

((TF1v5Convert *)this)->Convert(fold);
}
}

Expand Down
19 changes: 19 additions & 0 deletions hist/hist/src/TFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ static const TString gNamePrefix = "TFormula__";
//static std::unordered_map<std::string, TInterpreter::CallFuncIFacePtr_t::Generic_t> gClingFunctions = std::unordered_map<TString, TInterpreter::CallFuncIFacePtr_t::Generic_t>();
static std::unordered_map<std::string, void *> gClingFunctions = std::unordered_map<std::string, void * >();

static void R__v5TFormulaUpdater(Int_t nobjects, TObject **from, TObject **to)
{
auto **fromv5 = (ROOT::v5::TFormula **)from;
auto **target = (TFormula **)to;

for (int i = 0; i < nobjects; ++i) {
if (fromv5[i] && target[i]) {
TFormula fnew(fromv5[i]->GetName(), fromv5[i]->GetExpFormula());
*(target[i]) = fnew;
target[i]->SetParameters(fromv5[i]->GetParameters());
}
}
}

using TFormulaUpdater_t = void (*)(Int_t nobjects, TObject **from, TObject **to);
bool R__SetClonesArrayTFormulaUpdater(TFormulaUpdater_t func);

static int R__RegisterTF1UpdaterTrigger = R__SetClonesArrayTFormulaUpdater(R__v5TFormulaUpdater);

////////////////////////////////////////////////////////////////////////////////
Bool_t TFormula::IsOperator(const char c)
{
Expand Down
29 changes: 19 additions & 10 deletions hist/hist/src/TGraph2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ TGraph2D& TGraph2D::operator=(const TGraph2D &g)
if (fZ) delete [] fZ;
if (fHistogram && !fUserHisto) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
// copy everything except the function list
fNpoints = g.fNpoints;
Expand Down Expand Up @@ -588,7 +589,7 @@ void TGraph2D::Build(Int_t n)
fNpy = 40;
fDirectory = 0;
fHistogram = 0;
fDelaunay = nullptr;
fDelaunay = nullptr;
fMaximum = -1111;
fMinimum = -1111;
fX = new Double_t[fSize];
Expand Down Expand Up @@ -633,7 +634,8 @@ void TGraph2D::Clear(Option_t * /*option = "" */)
fSize = fNpoints = 0;
if (fHistogram && !fUserHisto) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
if (fFunctions) {
fFunctions->SetBit(kInvalidObject);
Expand Down Expand Up @@ -1082,14 +1084,16 @@ TH2D *TGraph2D::GetHistogram(Option_t *option)
if (!empty && fHistogram->GetEntries() == 0) {
if (!fUserHisto) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
} else if (fHistogram->GetEntries() == 0)
{; }
// check case if interpolation type has changed
else if ( (TestBit(kOldInterpolation) && !oldInterp) || ( !TestBit(kOldInterpolation) && oldInterp ) ) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
// normal case return existing histogram
else {
Expand Down Expand Up @@ -1490,7 +1494,8 @@ Int_t TGraph2D::RemovePoint(Int_t ipoint)
fSize = fNpoints;
if (fHistogram) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
return ipoint;
}
Expand Down Expand Up @@ -1608,7 +1613,8 @@ void TGraph2D::SetMargin(Double_t m)
}
if (fHistogram) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
}

Expand All @@ -1622,7 +1628,8 @@ void TGraph2D::SetMarginBinsContent(Double_t z)
fZout = z;
if (fHistogram) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
}

Expand Down Expand Up @@ -1693,7 +1700,8 @@ void TGraph2D::SetNpx(Int_t npx)
}
if (fHistogram) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
}

Expand All @@ -1714,7 +1722,8 @@ void TGraph2D::SetNpy(Int_t npy)
}
if (fHistogram) {
delete fHistogram;
fHistogram = 0;
fHistogram = nullptr;
fDelaunay = nullptr;
}
}

Expand Down