Skip to content

Commit c7b07de

Browse files
committed
Fix fetching CCDB metadata, extend ccdbRunDependent behaviour
ccdbParamSpec run-dependence flag changed from bool to int. The new convension is: ccdbParamSpec(path) : not run-depndent ccdbParamSpec(path, 1) : run-dependent object with usual timestamp and runNumber requested via metadata ccdbParamSpec(path, 2) : run-dependent object with runNumber used instead of timestamp. So, the entry like RCT/Info/RunInformation should be requested by passing 2.
1 parent 80195a0 commit c7b07de

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

Framework/CCDBSupport/src/CCDBHelpers.cxx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
198198
auto sid = _o2_signpost_id_t{(int64_t)timingInfo.timeslice};
199199
O2_SIGNPOST_START(ccdb, sid, "populateCacheWith", "Starting to populate cache with CCDB objects");
200200
for (auto& route : helper->routes) {
201+
int64_t timestampToUse = timestamp;
201202
O2_SIGNPOST_EVENT_EMIT(ccdb, sid, "populateCacheWith", "Fetching object for route %{public}s", DataSpecUtils::describe(route.matcher).data());
202203
objCnt++;
203204
auto concrete = DataSpecUtils::asConcreteDataMatcher(route.matcher);
@@ -212,8 +213,14 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
212213
for (auto& meta : route.matcher.metadata) {
213214
if (meta.name == "ccdb-path") {
214215
path = meta.defaultValue.get<std::string>();
215-
} else if (meta.name == "ccdb-run-dependent" && meta.defaultValue.get<bool>() == true) {
216-
metadata["runNumber"] = dtc.runNumber;
216+
} else if (meta.name == "ccdb-run-dependent" && meta.defaultValue.get<int>() > 0) {
217+
if (meta.defaultValue.get<int>() == 1) {
218+
metadata["runNumber"] = dtc.runNumber;
219+
} else if (meta.defaultValue.get<int>() == 2) {
220+
timestampToUse = std::stoi(dtc.runNumber);
221+
} else {
222+
LOGP(fatal, "Undefined run-dependent option {} for spec {}/{}/{}", meta.defaultValue.get<int>(), concrete.origin.as<std::string>(), concrete.description.as<std::string>(), int(concrete.subSpec));
223+
}
217224
} else if (isPrefix(ccdbMetadataPrefix, meta.name)) {
218225
std::string key = meta.name.substr(ccdbMetadataPrefix.size());
219226
auto value = meta.defaultValue.get<std::string>();
@@ -232,7 +239,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
232239
uint64_t cachePopulatedAt = url2uuid->second.cachePopulatedAt;
233240
// If timestamp is before the time the element was cached or after the claimed validity, we need to check validity, again
234241
// when online.
235-
bool cacheExpired = (validUntil <= timestamp) || (timestamp <= cachePopulatedAt);
242+
bool cacheExpired = (validUntil <= timestampToUse) || (timestamp < cachePopulatedAt);
236243
checkValidity = (std::abs(int(timingInfo.tfCounter - url2uuid->second.lastCheckedTF)) >= chRate) && (isOnline || cacheExpired);
237244
} else {
238245
checkValidity = true; // never skip check if the cache is empty
@@ -242,10 +249,10 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
242249

243250
const auto& api = helper->getAPI(path);
244251
if (checkValidity && (!api.isSnapshotMode() || etag.empty())) { // in the snapshot mode the object needs to be fetched only once
245-
LOGP(detail, "Loading {} for timestamp {}", path, timestamp);
246-
api.loadFileToMemory(v, path, metadata, timestamp, &headers, etag, helper->createdNotAfter, helper->createdNotBefore);
252+
LOGP(detail, "Loading {} for timestamp {}", path, timestampToUse);
253+
api.loadFileToMemory(v, path, metadata, timestampToUse, &headers, etag, helper->createdNotAfter, helper->createdNotBefore);
247254
if ((headers.count("Error") != 0) || (etag.empty() && v.empty())) {
248-
LOGP(fatal, "Unable to find object {}/{}", path, timestamp);
255+
LOGP(fatal, "Unable to find object {}/{}", path, timestampToUse);
249256
// FIXME: I should send a dummy message.
250257
continue;
251258
}
@@ -256,7 +263,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
256263
helper->mapURL2UUID[path].lastCheckedTF = timingInfo.tfCounter;
257264
if (etag.empty()) {
258265
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
259-
helper->mapURL2UUID[path].cachePopulatedAt = timestamp;
266+
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
260267
helper->mapURL2UUID[path].cacheMiss++;
261268
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);
262269
helper->mapURL2UUID[path].maxSize = std::max(v.size(), helper->mapURL2UUID[path].maxSize);
@@ -269,7 +276,7 @@ auto populateCacheWith(std::shared_ptr<CCDBFetcherHelper> const& helper,
269276
if (v.size()) { // but should be overridden by fresh object
270277
// somewhere here pruneFromCache should be called
271278
helper->mapURL2UUID[path].etag = headers["ETag"]; // update uuid
272-
helper->mapURL2UUID[path].cachePopulatedAt = timestamp;
279+
helper->mapURL2UUID[path].cachePopulatedAt = timestampToUse;
273280
helper->mapURL2UUID[path].cacheValidUntil = headers["Cache-Valid-Until"].empty() ? 0 : std::stoul(headers["Cache-Valid-Until"]);
274281
helper->mapURL2UUID[path].cacheMiss++;
275282
helper->mapURL2UUID[path].minSize = std::min(v.size(), helper->mapURL2UUID[path].minSize);

Framework/Core/include/Framework/CCDBParamSpec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ struct CCDBMetadata {
2323
};
2424

2525
ConfigParamSpec ccdbPathSpec(std::string const& path);
26-
ConfigParamSpec ccdbRunDependent(bool defaultValue = true);
26+
ConfigParamSpec ccdbRunDependent(int defaultValue = 1); // <1: not run-dependent, 1: run-dependent object with usual timestamp, 2: run-dependent object with runNumber used instead of timestamp
2727

28-
std::vector<ConfigParamSpec> ccdbParamSpec(std::string const& path, bool runDependent, std::vector<CCDBMetadata> metadata = {}, int qrate = 0);
28+
std::vector<ConfigParamSpec> ccdbParamSpec(std::string const& path, int runDependent, std::vector<CCDBMetadata> metadata = {}, int qrate = 0);
2929
/// Helper to create an InputSpec which will read from a CCDB
3030
/// Notice that those input specs have some convetions for their metadata:
3131
///

Framework/Core/include/Framework/InputRecord.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ class InputRecord
493493
auto cacheEntry = cache.matcherToMetadataId.find(path);
494494
if (cacheEntry == cache.matcherToMetadataId.end()) {
495495
cache.matcherToMetadataId.insert(std::make_pair(path, id));
496-
cache.idToMetadata[id] = extractCCDBHeaders(ref);
496+
cache.idToMetadata[id] = DataRefUtils::extractCCDBHeaders(ref);
497497
LOGP(info, "Caching CCDB metadata {}: {}", id.value, path);
498498
return cache.idToMetadata[id];
499499
}
@@ -506,9 +506,9 @@ class InputRecord
506506
// The id in the cache is different. Let's destroy the old cached entry
507507
// and create a new one.
508508
LOGP(info, "Replacing cached entry {} with {} for {}", oldId.value, id.value, path);
509-
cache.idToObject[id] = extracCCDBMetadata(ref);
509+
cache.idToMetadata[id] = DataRefUtils::extractCCDBHeaders(ref);
510510
oldId.value = id.value;
511-
return cache.idToObject[id];
511+
return cache.idToMetadata[id];
512512
}
513513

514514
/// Helper method to be used to check if a given part of the InputRecord is present.

Framework/Core/src/CCDBParamSpec.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ ConfigParamSpec ccdbPathSpec(std::string const& path)
2121
return ConfigParamSpec{"ccdb-path", VariantType::String, path, {fmt::format("Path in CCDB ({})", path)}, ConfigParamKind::kGeneric};
2222
}
2323

24-
ConfigParamSpec ccdbRunDependent(bool defaultValue)
24+
ConfigParamSpec ccdbRunDependent(int defaultValue)
2525
{
26-
return ConfigParamSpec{"ccdb-run-dependent", VariantType::Bool, defaultValue, {"Give object for specific run number"}, ConfigParamKind::kGeneric};
26+
return ConfigParamSpec{"ccdb-run-dependent", VariantType::Int, defaultValue, {"Give object for specific run number"}, ConfigParamKind::kGeneric};
2727
}
2828

2929
ConfigParamSpec ccdbQueryRateSpec(int r)
@@ -45,11 +45,11 @@ std::vector<ConfigParamSpec> ccdbParamSpec(std::string const& path, std::vector<
4545
return ccdbParamSpec(path, false, metadata, qrate);
4646
}
4747

48-
std::vector<ConfigParamSpec> ccdbParamSpec(std::string const& path, bool runDependent, std::vector<CCDBMetadata> metadata, int qrate)
48+
std::vector<ConfigParamSpec> ccdbParamSpec(std::string const& path, int runDependent, std::vector<CCDBMetadata> metadata, int qrate)
4949
{
5050
// Add here CCDB objecs which should be considered run dependent
5151
std::vector<ConfigParamSpec> result{ccdbPathSpec(path)};
52-
if (runDependent) {
52+
if (runDependent > 0) {
5353
result.push_back(ccdbRunDependent(runDependent));
5454
}
5555
if (qrate != 0) {

0 commit comments

Comments
 (0)