Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hist] TPrincipal bounds check and format #15110

Merged
merged 2 commits into from
Apr 8, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions hist/hist/inc/TPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ class TPrincipal : public TNamed {
public:
TPrincipal();
~TPrincipal() override;
TPrincipal(Int_t nVariables, Option_t *opt="ND");
TPrincipal(Long64_t nVariables, Option_t *opt="ND");

virtual void AddRow(const Double_t *x);
void Browse(TBrowser *b) override;
void Clear(Option_t *option="") override;
/// Return the covariance matrix. \note Only the lower diagonal of the covariance matrix is computed by the class
const TMatrixD *GetCovarianceMatrix() const {return &fCovarianceMatrix;}
const TVectorD *GetEigenValues() const {return &fEigenValues;}
const TMatrixD *GetEigenVectors() const {return &fEigenVectors;}
TList *GetHistograms() const {return fHistograms;}
const TVectorD *GetMeanValues() const {return &fMeanValues;}
const Double_t *GetRow(Int_t row);
const Double_t *GetRow(Long64_t row);
const TVectorD *GetSigmas() const {return &fSigmas;}
const TVectorD *GetUserData() const {return &fUserData;}
Bool_t IsFolder() const override { return kTRUE;}
Expand Down
20 changes: 16 additions & 4 deletions hist/hist/src/TPrincipal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TPrincipal::TPrincipal()
///
/// The created object is named "principal" by default.

TPrincipal::TPrincipal(Int_t nVariables, Option_t *opt)
TPrincipal::TPrincipal(Long64_t nVariables, Option_t *opt)
: fMeanValues(nVariables),
fSigmas(nVariables),
fCovarianceMatrix(nVariables,nVariables),
Expand All @@ -260,7 +260,11 @@ TPrincipal::TPrincipal(Int_t nVariables, Option_t *opt)
fStoreData(kFALSE)
{
if (nVariables <= 1) {
Error("TPrincipal", "You can't be serious - nVariables == 1!!!");
Error("TPrincipal", "You can't be serious - nVariables <= 1!!!");
return;
}
if (nVariables > std::numeric_limits<Int_t>::max()) {
Error("TPrincipal", "`nVariables` input parameter %lld is larger than the allowed maximum %d", nVariables, std::numeric_limits<Int_t>::max());
return;
}

Expand Down Expand Up @@ -411,6 +415,10 @@ void TPrincipal::AddRow(const Double_t *p)
{
if (!p)
return;
if (fNumberOfDataPoints == std::numeric_limits<Int_t>::max()) {
Error("AddRow", "`fNumberOfDataPoints` has reached its allowed maximum %d, cannot add new row.", fNumberOfDataPoints);
return;
}

// Increment the data point counter
Int_t i,j;
Expand Down Expand Up @@ -510,15 +518,19 @@ void TPrincipal::Clear(Option_t *opt)
/// It's up to the user to delete the returned array.
/// Row 0 is the first row;

const Double_t *TPrincipal::GetRow(Int_t row)
const Double_t *TPrincipal::GetRow(Long64_t row)
{
if (row >= fNumberOfDataPoints)
return nullptr;

if (!fStoreData)
return nullptr;

Int_t index = row * fNumberOfVariables;
Long64_t index = row * fNumberOfVariables;
if (index > std::numeric_limits<Int_t>::max()) {
Error("GetRow", "Input parameter `row` %lld x fNumberOfVariables %d goes into overflow (%lld>%d), returning nullptr.", row, fNumberOfVariables, index, std::numeric_limits<Int_t>::max());
return nullptr;
}
return &fUserData(index);
}

Expand Down