Skip to content

Commit 25cf4e2

Browse files
committed
[hist] Throw on streaming Experimental classes
1 parent 54a286a commit 25cf4e2

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

hist/histv7/inc/LinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma link C++ class ROOT::Experimental::RRegularAxis-;
2+
#pragma link C++ class ROOT::Experimental::RVariableBinAxis-;

hist/histv7/inc/ROOT/RRegularAxis.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "RLinearizedIndex.hxx"
99

1010
#include <cstddef>
11+
#include <stdexcept>
12+
13+
class TBuffer;
1114

1215
namespace ROOT {
1316
namespace Experimental {
@@ -86,6 +89,9 @@ public:
8689
std::size_t bin = (x - fLow) * fInvBinWidth;
8790
return {bin, true};
8891
}
92+
93+
/// ROOT Streamer function to throw when trying to store an object of this class.
94+
void Streamer(TBuffer &) { throw std::runtime_error("unable to store RRegularAxis"); }
8995
};
9096

9197
} // namespace Experimental

hist/histv7/inc/ROOT/RVariableBinAxis.hxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
#include "RLinearizedIndex.hxx"
99

1010
#include <cstddef>
11+
#include <stdexcept>
1112
#include <utility>
1213
#include <vector>
1314

15+
class TBuffer;
16+
1417
namespace ROOT {
1518
namespace Experimental {
1619

@@ -84,6 +87,9 @@ public:
8487
std::size_t bin = fBinEdges.size() - 2;
8588
return {bin, true};
8689
}
90+
91+
/// ROOT Streamer function to throw when trying to store an object of this class.
92+
void Streamer(TBuffer &) { throw std::runtime_error("unable to store RVariableBinAxis"); }
8793
};
8894

8995
} // namespace Experimental

hist/histv7/standalone.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set(histv7_standalone TRUE)
2+
13
include(GNUInstallDirs)
24
include(headers.cmake)
35

hist/histv7/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
HIST_ADD_GTEST(hist_regular hist_regular.cxx)
22
HIST_ADD_GTEST(hist_variable hist_variable.cxx)
3+
4+
if(NOT DEFINED histv7_standalone)
5+
ROOT_ADD_GTEST(hist_io hist_io.cxx LIBRARIES RIO ROOTHist)
6+
endif()

hist/histv7/test/hist_io.cxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "hist_test.hxx"
2+
3+
#include <ROOT/TestSupport.hxx>
4+
#include <TMemFile.h>
5+
6+
#include <stdexcept>
7+
8+
template <typename T>
9+
static void ExpectThrowOnWriteObject(const T &obj)
10+
{
11+
ROOT::TestSupport::CheckDiagsRAII diagRAII;
12+
diagRAII.optionalDiag(kWarning, "TKey::TKey", "no public constructor", /*matchFullMessage=*/false);
13+
14+
TMemFile f("mem.root", "RECREATE");
15+
EXPECT_THROW(f.WriteObject(&obj, "o"), std::runtime_error);
16+
}
17+
18+
TEST(RRegularAxis, Streamer)
19+
{
20+
static constexpr std::size_t Bins = 20;
21+
const RRegularAxis axis(Bins, 0, Bins);
22+
ExpectThrowOnWriteObject(axis);
23+
}
24+
25+
TEST(RVariableBinAxis, Streamer)
26+
{
27+
static constexpr std::size_t Bins = 20;
28+
std::vector<double> bins;
29+
for (std::size_t i = 0; i < Bins; i++) {
30+
bins.push_back(i);
31+
}
32+
bins.push_back(Bins);
33+
34+
const RVariableBinAxis axis(bins);
35+
ExpectThrowOnWriteObject(axis);
36+
}

0 commit comments

Comments
 (0)