Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hist] fix regression in AddBinContentND and add test
Browse files Browse the repository at this point in the history
Fixes #17552
ferdymercury authored Jan 30, 2025
1 parent a20c8cd commit 19c8e88
Showing 3 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hist/hist/inc/TH2.h
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ class TH2C : public TH2, public TArrayC {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -200,6 +201,7 @@ class TH2S : public TH2, public TArrayS {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -241,6 +243,7 @@ class TH2I : public TH2, public TArrayI {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -280,6 +283,7 @@ class TH2L : public TH2, public TArrayL64 {
~TH2L() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -326,6 +330,7 @@ class TH2F : public TH2, public TArrayF {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Float_t (w);}
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -373,6 +378,7 @@ class TH2D : public TH2, public TArrayD {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Double_t (w);}
using TH2::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
6 changes: 6 additions & 0 deletions hist/hist/inc/TH3.h
Original file line number Diff line number Diff line change
@@ -175,6 +175,7 @@ class TH3C : public TH3, public TArrayC {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -213,6 +214,7 @@ class TH3S : public TH3, public TArrayS {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -251,6 +253,7 @@ class TH3I : public TH3, public TArrayI {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -289,6 +292,7 @@ class TH3L : public TH3, public TArrayL64 {
~TH3L() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -333,6 +337,7 @@ class TH3F : public TH3, public TArrayF {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Float_t (w);}
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
@@ -376,6 +381,7 @@ class TH3D : public TH3, public TArrayD {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Double_t (w);}
using TH3::AddBinContent;
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
15 changes: 15 additions & 0 deletions hist/hist/test/test_TH1.cxx
Original file line number Diff line number Diff line change
@@ -75,3 +75,18 @@ TEST(TH1, DumpOutput)
const std::string output = testing::internal::GetCapturedStdout();
EXPECT_TRUE(output.find(line_fArray) != std::string::npos) << "Could not find '" << line_fArray << "' in the multiline output '" << output;
}


// https://github.com/root-project/root/issues/17552
TEST(TH1, AddBinContent)
{
TH1F h1("h1", "h1", 10, 0, 1);
h1.AddBinContent(1,1.);
EXPECT_FLOAT_EQ(h1.GetBinContent(1),1.);
TH2F h2("h2", "h2", 10, 0, 1, 2, 0, 3);

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

unknown type name 'TH2F'; did you mean 'TH1F'?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

no matching constructor for initialization of 'TH1F'

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo

‘TH2F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 modules_off runtime_cxxmodules=Off

‘TH2F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora40 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

‘TH2F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 march_native CMAKE_BUILD_TYPE=RelWithDebInfo, CMAKE_CXX_FLAGS=-march=native, CMAKE_C_FLAGS=-march=native, fortran=OFF

‘TH2F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora41 LLVM_ENABLE_ASSERTIONS=On

‘TH2F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

unknown type name 'TH2F'; did you mean 'TH1F'?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

no matching constructor for initialization of 'TH1F'

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

unknown type name 'TH2F'; did you mean 'TH1F'?

Check failure on line 86 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

no matching constructor for initialization of 'TH1F'
h2.AddBinContent(1,1,1.);

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

no matching member function for call to 'AddBinContent'

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo

‘h2’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 modules_off runtime_cxxmodules=Off

‘h2’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora40 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

‘h2’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 march_native CMAKE_BUILD_TYPE=RelWithDebInfo, CMAKE_CXX_FLAGS=-march=native, CMAKE_C_FLAGS=-march=native, fortran=OFF

‘h2’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora41 LLVM_ENABLE_ASSERTIONS=On

‘h2’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

no matching member function for call to 'AddBinContent'

Check failure on line 87 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

no matching member function for call to 'AddBinContent'
EXPECT_FLOAT_EQ(h2.GetBinContent(1,1),1.);
TH3F h3("h3", "h3", 5, 0, 1, 2, 0, 2, 2, 0, 3);;

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

unknown type name 'TH3F'; did you mean 'TH1F'?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

no matching constructor for initialization of 'TH1F'

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo

‘TH3F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 modules_off runtime_cxxmodules=Off

‘TH3F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora40 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

‘TH3F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 march_native CMAKE_BUILD_TYPE=RelWithDebInfo, CMAKE_CXX_FLAGS=-march=native, CMAKE_C_FLAGS=-march=native, fortran=OFF

‘TH3F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora41 LLVM_ENABLE_ASSERTIONS=On

‘TH3F’ was not declared in this scope; did you mean ‘TH1F’?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

unknown type name 'TH3F'; did you mean 'TH1F'?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

no matching constructor for initialization of 'TH1F'

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

unknown type name 'TH3F'; did you mean 'TH1F'?

Check failure on line 89 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

no matching constructor for initialization of 'TH1F'
h3.AddBinContent(1,1,1,1.);

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9-clang clang LLVM_ENABLE_ASSERTIONS=On, CMAKE_C_COMPILER=clang, CMAKE_CXX_COMPILER=clang++

no matching member function for call to 'AddBinContent'

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 arm64 CMAKE_BUILD_TYPE=RelWithDebInfo

‘h3’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 modules_off runtime_cxxmodules=Off

‘h3’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora40 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

‘h3’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / alma9 march_native CMAKE_BUILD_TYPE=RelWithDebInfo, CMAKE_CXX_FLAGS=-march=native, CMAKE_C_FLAGS=-march=native, fortran=OFF

‘h3’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / fedora41 LLVM_ENABLE_ASSERTIONS=On

‘h3’ was not declared in this scope; did you mean ‘h1’?

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac15 ARM64 LLVM_ENABLE_ASSERTIONS=On, CMAKE_CXX_STANDARD=20

no matching member function for call to 'AddBinContent'

Check failure on line 90 in hist/hist/test/test_TH1.cxx

GitHub Actions / mac13 ARM64 LLVM_ENABLE_ASSERTIONS=On, builtin_zlib=ON

no matching member function for call to 'AddBinContent'
EXPECT_FLOAT_EQ(h3.GetBinContent(1,1,1),1.);
}

0 comments on commit 19c8e88

Please sign in to comment.