Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/histv7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=install -Dhistv7_benchmark=ON hist/histv7
run: cmake -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS="-Werror -Wall -Wextra -Wpedantic -Wsign-conversion" -DCMAKE_INSTALL_PREFIX=install -Dhistv7_benchmark=ON hist/histv7
- name: Build
run: cmake --build build
- name: Install
Expand Down
31 changes: 30 additions & 1 deletion hist/histv7/inc/ROOT/RBinIndex.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class RBinIndex final {
// We use std::uint64_t instead of std::size_t for the index because for sparse histograms, not all bins have to be
// allocated in memory. However, we require that the index has at least that size.
static_assert(sizeof(std::uint64_t) >= sizeof(std::size_t), "index type not large enough to address all bins");
// During construction, we expect that any standard integer fits in std::uint64_t.
static_assert(sizeof(std::uint64_t) >= sizeof(unsigned long long),
"index type not large enough to store any standard integer");

std::uint64_t fIndex = kInvalidIndex;

Expand All @@ -36,7 +39,33 @@ public:
RBinIndex() = default;

/// Construct a bin index for a normal bin.
RBinIndex(std::uint64_t index) : fIndex(index) { assert(IsNormal()); }
RBinIndex(unsigned int index) : RBinIndex(static_cast<unsigned long long>(index)) {}

/// Construct a bin index for a normal bin.
RBinIndex(unsigned long index) : RBinIndex(static_cast<unsigned long long>(index)) {}

/// Construct a bin index for a normal bin.
RBinIndex(unsigned long long index) : fIndex(index) { assert(IsNormal()); }

/// Construct a bin index for a normal bin.
///
/// \param[in] index signed integer that must not be negative
RBinIndex(int index) : RBinIndex(static_cast<long long>(index)) {}

/// Construct a bin index for a normal bin.
///
/// \param[in] index signed integer that must not be negative
RBinIndex(long index) : RBinIndex(static_cast<long long>(index)) {}

/// Construct a bin index for a normal bin.
///
/// \param[in] index signed integer that must not be negative
RBinIndex(long long index)
{
assert(index >= 0);
fIndex = static_cast<std::uint64_t>(index);
assert(IsNormal());
}

/// Return the index for a normal bin.
std::uint64_t GetIndex() const
Expand Down
18 changes: 18 additions & 0 deletions hist/histv7/test/hist_index.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <iterator>
#include <vector>

#ifndef TYPED_TEST_SUITE
#define TYPED_TEST_SUITE TYPED_TEST_CASE
#endif

TEST(RBinIndex, Constructor)
{
const RBinIndex invalid;
Expand Down Expand Up @@ -152,6 +156,20 @@ TEST(RBinIndex, Relation)
EXPECT_FALSE(underflow >= overflow);
}

template <typename T>
class RBinIndexConversion : public testing::Test {};

using IntegerTypes = testing::Types<signed char, unsigned char, short, unsigned short, int, unsigned int, long,
unsigned long, long long, unsigned long long>;
TYPED_TEST_SUITE(RBinIndexConversion, IntegerTypes);

TYPED_TEST(RBinIndexConversion, Constructor)
{
const TypeParam input = 1;
const RBinIndex index(input);
EXPECT_EQ(index.GetIndex(), 1);
}

using ROOT::Experimental::Internal::CreateBinIndexRange;

TEST(RBinIndexRange, ConstructorCreate)
Expand Down
Loading