Skip to content

Commit e8b52df

Browse files
TPC: rate-limit TPCScaler weight errors
TPCScalerWeights::getWeight logged an error for every scaler value outside the stored weights. For a timestamp within the first ion drift time of a TPCScaler object (e.g. at the start of a run) the clamped averaging range extends beyond the timestamp, which produced hundreds of identical error lines per call. The weight (1) is unchanged; getMeanScaler now counts these values and reports them in one line per call, at most 20 times per process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1f4567d commit e8b52df

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎Detectors/TPC/calibration/include/TPCCalibration/TPCScaler.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ Class for storing the scalers which are used to calculate an estimate for the me
2828
*/
2929

3030
struct TPCScalerWeights {
31+
/// \return weight for the time deltaTime relative to the timestamp; 1 if deltaTime is outside the stored weights (see isInRange)
3132
float getWeight(float deltaTime) const;
33+
/// \return true if the stored weights cover deltaTime
34+
bool isInRange(float deltaTime) const;
3235
bool isValid() const { return (mSamplingTimeMS > 0 && !mWeights.empty()); }
3336
float getDurationMS() const { return mSamplingTimeMS * mWeights.size(); }
3437
float mSamplingTimeMS = -1; ///< sampling of the stored weights

‎Detectors/TPC/calibration/src/TPCScaler.cxx‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <TTree.h>
2020
#include "Framework/Logger.h"
2121
#include "CommonConstants/LHCConstants.h"
22+
#include <atomic>
2223

2324
using namespace o2::tpc;
2425

@@ -130,29 +131,50 @@ float TPCScaler::getMeanScaler(double timestamp, o2::tpc::Side side) const
130131
// sump up values from last ion drift time
131132
float sum = 0;
132133
float sumW = 0;
134+
int nOutOfRange = 0;
133135
const bool useWeights = mUseWeights && getScalerWeights().isValid();
134136
for (int i = firstIdx; i < lastIdx; ++i) {
135137
float weight = 1;
136138
if (useWeights) {
137139
const double relTSMS = mTimeStampMS + i * mIntegrationTimeMS - timestamp;
140+
nOutOfRange += !getScalerWeights().isInRange(relTSMS);
138141
weight = getScalerWeights().getWeight(relTSMS);
139142
}
140143
sum += getScalers(i, side) * weight;
141144
sumW += weight;
142145
}
146+
147+
// values outside the stored weights (e.g. timestamp within the first ion drift time of this object, where the clamped range extends
148+
// beyond the timestamp) are used with weight 1: reported once per call and at most MaxOutOfRangeReports times per process
149+
if (nOutOfRange > 0) {
150+
constexpr int MaxOutOfRangeReports = 20;
151+
static std::atomic<int> nReports{0};
152+
const int report = nReports++;
153+
if (report < MaxOutOfRangeReports) {
154+
LOGP(error, "{} of {} scaler values for timestamp {} outside the weights (first timestamp {} ms, sampling {} ms): weight 1 used{}", nOutOfRange,
155+
lastIdx - firstIdx, timestamp, getScalerWeights().mFirstTimeStampMS, getScalerWeights().mSamplingTimeMS,
156+
(report + 1 == MaxOutOfRangeReports) ? ", further messages suppressed" : "");
157+
}
158+
}
159+
143160
if (sumW != 0) {
144161
return (sum / sumW);
145162
}
146163
return 0;
147164
}
148165

166+
bool TPCScalerWeights::isInRange(float deltaTime) const
167+
{
168+
const int idx = (deltaTime - mFirstTimeStampMS) / mSamplingTimeMS;
169+
return (idx >= 0) && (idx < static_cast<int>(mWeights.size()));
170+
}
171+
149172
float TPCScalerWeights::getWeight(float deltaTime) const
150173
{
151174
const float idxF = (deltaTime - mFirstTimeStampMS) / mSamplingTimeMS;
152175
const int idx = idxF;
153-
if ((idx < 0) || (idx > mWeights.size() - 1)) {
154-
LOGP(error, "Index out of range for deltaTime: {} mFirstTimeStampMS: {} mSamplingTimeMS: {}", deltaTime, mFirstTimeStampMS, mSamplingTimeMS);
155-
// set weight 1 to in case it is out of range. This can only happen if the TPC scaler is not valid for given time
176+
if (!isInRange(deltaTime)) {
177+
// set weight 1 to in case it is out of range. This can only happen if the TPC scaler is not valid for given time (reported in getMeanScaler)
156178
return 1;
157179
}
158180

0 commit comments

Comments
 (0)