Skip to content

Commit 432055c

Browse files
committed
With -condition-use-slice-for-prescaling use TF slice instead of TFcounter for CCDB cache validation.
If --condition-tf-per-query-multiplier value is negative, the prescaling is simply applied to tfCounter%|query_rate| (or timeslice%|query_rate| if --condition-use-slice-for-prescaling is asked)
1 parent 604f7cb commit 432055c

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

Framework/CCDBSupport/src/CCDBFetcherHelper.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ void CCDBFetcherHelper::initialiseHelper(CCDBFetcherHelper& helper, ConfigParamR
5151
auto defHost = options.get<std::string>("condition-backend");
5252
auto checkRate = options.get<int>("condition-tf-per-query");
5353
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
54+
helper.useTFSlice = options.get<bool>("condition-use-slice-for-prescaling");
5455
helper.timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
5556
helper.queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
56-
helper.queryPeriodFactor = checkMult > 0 ? checkMult : 1;
57-
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper.queryPeriodGlo, helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
57+
helper.queryPeriodFactor = checkMult == 0 ? 1 : checkMult;
58+
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}{}", defHost, helper.queryPeriodGlo, helper.useTFSlice ? "(slice!)" : "",
59+
helper.queryPeriodFactor == 1 ? std::string{} : (helper.queryPeriodFactor > 0 ? fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor) : fmt::format(", (query downscaled as TFcounter%{})", -helper.queryPeriodFactor)));
5860
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
5961
auto remapString = options.get<std::string>("condition-remap");
6062
ParserResult result = parseRemappings(remapString.c_str());
@@ -196,6 +198,7 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
196198
}
197199

198200
const auto url2uuid = helper->mapURL2UUID.find(path);
201+
uint32_t counter = helper->useTFSlice ? timingInfo.timeslice : timingInfo.tfCounter;
199202
if (url2uuid != helper->mapURL2UUID.end()) {
200203
etag = url2uuid->second.etag;
201204
// We check validity every chRate timeslices or if the cache is expired
@@ -205,12 +208,12 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
205208
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
206209
// when online.
207210
bool cacheExpired = (validUntil <= timestampToUse) || (op.timestamp < cachePopulatedAt);
208-
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
211+
checkValidity = (std::abs(int(counter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
209212
} else {
210213
checkValidity = true; // never skip check if the cache is empty
211214
}
212215

213-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tfID %d of %{public}s", checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
216+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tf%{public}s %d of %{public}s", checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
214217

215218
const auto& api = helper->getAPI(path);
216219
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
@@ -225,7 +228,7 @@ auto CCDBFetcherHelper::populateCacheWith(std::shared_ptr<CCDBFetcherHelper> con
225228
if (headers.find("default") != headers.end()) {
226229
LOGP(detail, "******** Default entry used for {} ********", path);
227230
}
228-
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
231+
helper->mapURL2UUID[path].lastCheckedTF = counter;
229232
if (etag.empty()) {
230233
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
231234
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;

Framework/CCDBSupport/src/CCDBFetcherHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct CCDBFetcherHelper {
9494
int queryPeriodGlo = 1;
9595
int queryPeriodFactor = 1;
9696
int64_t timeToleranceMS = 5000;
97+
bool useTFSlice = false;
9798

9899
o2::ccdb::CcdbApi& getAPI(const std::string& path);
99100
static void initialiseHelper(CCDBFetcherHelper& helper, ConfigParamRegistry const& options);

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct CCDBFetcherHelper {
6060
int queryPeriodGlo = 1;
6161
int queryPeriodFactor = 1;
6262
int64_t timeToleranceMS = 5000;
63+
bool useTFSlice = false;
6364

6465
o2::ccdb::CcdbApi& getAPI(const std::string& path)
6566
{
@@ -165,10 +166,12 @@ void initialiseHelper(CCDBFetcherHelper& helper, ConfigParamRegistry const& opti
165166
auto defHost = options.get<std::string>("condition-backend");
166167
auto checkRate = options.get<int>("condition-tf-per-query");
167168
auto checkMult = options.get<int>("condition-tf-per-query-multiplier");
169+
helper.useTFSlice = options.get<bool>("condition-use-slice-for-prescaling");
168170
helper.timeToleranceMS = options.get<int64_t>("condition-time-tolerance");
169171
helper.queryPeriodGlo = checkRate > 0 ? checkRate : std::numeric_limits<int>::max();
170-
helper.queryPeriodFactor = checkMult > 0 ? checkMult : 1;
171-
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}", defHost, helper.queryPeriodGlo, helper.queryPeriodFactor == 1 ? std::string{} : fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor));
172+
helper.queryPeriodFactor = checkMult == 0 ? 1 : checkMult;
173+
LOGP(info, "CCDB Backend at: {}, validity check for every {} TF{}{}", defHost, helper.queryPeriodGlo, helper.useTFSlice ? "(slice!)" : "",
174+
helper.queryPeriodFactor == 1 ? std::string{} : (helper.queryPeriodFactor > 0 ? fmt::format(", (query for high-rate objects downscaled by {})", helper.queryPeriodFactor) : fmt::format(", (query downscaled as TFcounter%{})", -helper.queryPeriodFactor)));
172175
LOGP(info, "Hook to enable signposts for CCDB messages at {}", (void*)&private_o2_log_ccdb->stacktrace);
173176
auto remapString = options.get<std::string>("condition-remap");
174177
CCDBHelpers::ParserResult result = CCDBHelpers::parseRemappings(remapString.c_str());
@@ -276,10 +279,11 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
276279
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Adding metadata %{public}s: %{public}s to the request", key.data(), value.data());
277280
metadata[key] = value;
278281
} else if (meta.name == "ccdb-query-rate") {
279-
chRate = meta.defaultValue.get<int>() * helper->queryPeriodFactor;
282+
chRate = std::max(1, meta.defaultValue.get<int>()) * helper->queryPeriodFactor;
280283
}
281284
}
282285
const auto url2uuid = helper->mapURL2UUID.find(path);
286+
uint32_t counter = helper->useTFSlice ? timingInfo.timeslice : timingInfo.tfCounter;
283287
if (url2uuid != helper->mapURL2UUID.end()) {
284288
etag = url2uuid->second.etag;
285289
// We check validity every chRate timeslices or if the cache is expired
@@ -289,12 +293,12 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
289293
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
290294
// when online.
291295
bool cacheExpired = (validUntil <= timestampToUse) || (timestamp < cachePopulatedAt);
292-
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
296+
checkValidity = (chRate > 0 ? (std::abs(int(counter - url2uuid->second.lastCheckedTF)) >= chRate) : (counter % -chRate) == 0) && (isOnline || cacheExpired);
293297
} else {
294298
checkValidity = true; // never skip check if the cache is empty
295299
}
296300

297-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tfID %d of %{public}s", checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
301+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "checkValidity is %{public}s for tf%{public}s %d of %{public}s", checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
298302

299303
const auto& api = helper->getAPI(path);
300304
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
@@ -309,7 +313,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
309313
if (headers.find("default") != headers.end()) {
310314
LOGP(detail, "******** Default entry used for {} ********", path);
311315
}
312-
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
316+
helper->mapURL2UUID[path].lastCheckedTF = counter;
313317
if (etag.empty()) {
314318
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
315319
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
@@ -382,21 +386,22 @@ AlgorithmSpec CCDBHelpers::fetchFromCCDB()
382386
std::map<std::string, std::string> metadata;
383387
std::map<std::string, std::string> headers;
384388
std::string etag;
385-
bool checkValidity = std::abs(int(timingInfo.tfCounter - helper->lastCheckedTFCounterOrbReset)) >= helper->queryPeriodGlo;
389+
uint32_t counter = helper->useTFSlice ? timingInfo.timeslice : timingInfo.tfCounter;
390+
bool checkValidity = std::abs(int(counter - helper->lastCheckedTFCounterOrbReset)) >= helper->queryPeriodGlo;
386391
const auto url2uuid = helper->mapURL2UUID.find(path);
387392
if (url2uuid != helper->mapURL2UUID.end()) {
388393
etag = url2uuid->second.etag;
389394
} else {
390395
checkValidity = true; // never skip check if the cache is empty
391396
}
392-
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "checkValidity is %{public}s for tfID %d of %{public}s",
393-
checkValidity ? "true" : "false", timingInfo.tfCounter, path.data());
397+
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "fetchFromCCDB", "checkValidity is %{public}s for tf%{public}s %d of %{public}s",
398+
checkValidity ? "true" : "false", helper->useTFSlice ? "ID" : "Slice", counter, path.data());
394399
Output output{"CTP", "OrbitReset", 0};
395400
Long64_t newOrbitResetTime = orbitResetTime;
396401
auto&& v = allocator.makeVector<char>(output);
397402
const auto& api = helper->getAPI(path);
398403
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
399-
helper->lastCheckedTFCounterOrbReset = timingInfo.tfCounter;
404+
helper->lastCheckedTFCounterOrbReset = counter;
400405
api.loadFileToMemory(v, path, metadata, timingInfo.creation, &headers, etag, helper->createdNotAfter, helper->createdNotBefore);
401406
if ((headers.count("Error") != 0) || (etag.empty() && v.empty())) {
402407
LOGP(fatal, "Unable to find CCDB object {}/{}", path, timingInfo.creation);

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
177177
{"condition-not-after", VariantType::Int64, 3385078236000ll, {"do not fetch from CCDB objects created after the timestamp"}},
178178
{"condition-remap", VariantType::String, "", {"remap condition path in CCDB based on the provided string."}},
179179
{"condition-tf-per-query", VariantType::Int, defaultConditionQueryRate(), {"check condition validity per requested number of TFs, fetch only once if <=0"}},
180-
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks"}},
180+
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks (>0) or on module of TFcounter (<0)"}},
181+
{"condition-use-slice-for-prescaling", VariantType::Bool, false, {"use TFslice instead of TFcounter to control validation frequency"}},
181182
{"condition-time-tolerance", VariantType::Int64, 5000ll, {"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
182183
{"orbit-offset-enumeration", VariantType::Int64, 0ll, {"initial value for the orbit"}},
183184
{"orbit-multiplier-enumeration", VariantType::Int64, 0ll, {"multiplier to get the orbit from the counter"}},
@@ -195,7 +196,8 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
195196
{"condition-not-after", VariantType::Int64, 3385078236000ll, {"do not fetch from CCDB objects created after the timestamp"}},
196197
{"condition-remap", VariantType::String, "", {"remap condition path in CCDB based on the provided string."}},
197198
{"condition-tf-per-query", VariantType::Int, defaultConditionQueryRate(), {"check condition validity per requested number of TFs, fetch only once if <=0"}},
198-
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks"}},
199+
{"condition-tf-per-query-multiplier", VariantType::Int, defaultConditionQueryRateMultiplier(), {"check conditions once per this amount of nominal checks (>0) or on module of TFcounter (<0)"}},
200+
{"condition-use-slice-for-prescaling", VariantType::Bool, false, {"use TFslice instead of TFcounter to control validation frequency"}},
199201
{"condition-time-tolerance", VariantType::Int64, 5000ll, {"prefer creation time if its difference to orbit-derived time exceeds threshold (ms), impose if <0"}},
200202
{"start-value-enumeration", VariantType::Int64, 0ll, {"initial value for the enumeration"}},
201203
{"end-value-enumeration", VariantType::Int64, -1ll, {"final value for the enumeration"}},

0 commit comments

Comments
 (0)