Skip to content

Commit 2597ea8

Browse files
sawenzelclaude
andcommitted
Keep RandomRing vector reads inside the ring
This addresses a review comment on the random ring repositioning. - setRandomPosition() can place the ring at any index. - getNextValueVc() now wraps to the start when a vector would run past the end. https://its.cern.ch/jira/browse/O2-7309 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d0703a0 commit 2597ea8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎Common/MathUtils/include/MathUtils/RandomRing.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class RandomRing
101101
// within this header file (to reduce memory problems during compilation).
102102
// The hope is that the calling user calls this with a
103103
// correct Vc type (Vc::float_v) in a source file.
104+
// a vector must not run past the end of the ring, also after setRandomPosition()
105+
if (mRingPosition + VcType::size() > mRandomNumbers.size()) {
106+
mRingPosition = 0;
107+
}
104108
const VcType value = VcType(&mRandomNumbers[mRingPosition]);
105109
mRingPosition += VcType::size();
106110
if (mRingPosition >= mRandomNumbers.size()) {
@@ -113,7 +117,7 @@ class RandomRing
113117
/// @return position in the ring buffer
114118
unsigned int getRingPosition() const { return mRingPosition; }
115119

116-
/// move to a random position in the ring buffer; not for rings read with getNextValueVc()
120+
/// move to a random position in the ring buffer
117121
/// @param [in] rng random generator to draw the position from
118122
void setRandomPosition(TRandom& rng) { mRingPosition = rng.Integer(N); }
119123

0 commit comments

Comments
 (0)