Hello,
I am trying to save some number (a lot) of TMultiDimFit objects into a root file.
What I am trying to figure out is how to reduce the memory taken by the object. If I read one such object from a file 6Mb of additional memory are allocated. The one object file takes on disk 459Kb. But If I just save the function code using MakeCode method and remove the function itself (leaving only the factors used in the function) and the comments, the file is only ~500 bites in size.
How can I ask TMultiDimFit to save on disk only information needed for the Eval function (and may be for EvalError) and nothing else? Or how can I ask TMultiDimFit to read only such information? The memory taken would reduce by a factor of ~1000 which is very important for me.
Thank you,
Siarhei.
Hello,
The following function seems to be doing well just what I need (the object size on disk drops from 459Kb to 4.3Kb). Root developers could consider adding it or something similar to the standard source code.
void TMultiDimFit::MinimizeObjectSize(void)
{
// Clear internal structures and variables except those needed by
// functions Eval and EvalError.
// Training sample, dependent quantity
fQuantity.ResizeTo(0);
fSqError.ResizeTo(0);
// Training sample, independent variables
fVariables.ResizeTo(0);
fMeanVariables.ResizeTo(0);
// Test sample
fTestQuantity.ResizeTo(0);
fTestSqError.ResizeTo(0);
fTestVariables.ResizeTo(0);
// Functions
fFunctions.ResizeTo(0,0);
delete [] fFunctionCodes; fFunctionCodes = 0;
fOrthFunctions.ResizeTo(0,0);
fOrthFunctionNorms.ResizeTo(0);
// Powers
delete [] fMaxPowers; fMaxPowers = 0;
delete [] fMaxPowersFinal; fMaxPowersFinal = 0;
// Fit
fCorrelationMatrix.ResizeTo(0,0);
fOrthCoefficients.ResizeTo(0);
fOrthCurvatureMatrix.ResizeTo(0,0);
// Coefficients
fResiduals.ResizeTo(0);
if(fHistograms!=0)
{
fHistograms->Delete();
delete fHistograms;
}// end of if
}
=========================================================
Also I suggest to remove from function TMultiDimFit::MakeRealCode
the code below since gXMean[] is not used in the generated code anyway:
// Assignment to mean vector.
outFile << "// Assignment to mean vector." << endl;
outFile << cv_qual << "double " << prefix
<< "gXMean[] = {" << endl;
for (i = 0; i < fNVariables; i++)
outFile << (i != 0 ? ", " : " ") << fMeanVariables(i) << flush;
outFile << " };" << endl << endl;
=========================================================
Guys, you also need to put the condition on fHistograms!=0 (like in the code above) to function TMultiDimFit::Clear, since if histograms were not created the function would crash root.
Siarhei.