Skip to content

Commit 54753b2

Browse files
committed
DPL CCDB Analysis: add ability to specify run dependent queries
Certain objects need to be queried via their run, not the timestamp. This allows using the uniform column as key for the run based query.
1 parent 1068c91 commit 54753b2

3 files changed

Lines changed: 83 additions & 54 deletions

File tree

Framework/CCDBSupport/src/AnalysisCCDBHelpers.cxx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
O2_DECLARE_DYNAMIC_LOG(ccdb);
4444

45-
46-
4745
namespace o2::framework
4846
{
4947
// Fill valid routes. Notice that for analysis the timestamps are associated to
@@ -84,8 +82,13 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
8482
// device's options. Here we just read the final value — honouring any further
8583
// runtime override supplied via CLI or JSON config.
8684
std::unordered_map<std::string, std::string> ccdbUrls;
85+
std::unordered_map<std::string, std::string> runDependent;
8786
for (auto& input : dec.analysisCCDBInputs) {
8887
for (auto& m : input.metadata) {
88+
if (m.name.starts_with("ccdb-run-dependent:")) {
89+
runDependent.emplace(m.name, m.defaultValue.asString());
90+
continue;
91+
}
8992
if (!m.name.starts_with("ccdb:") || ccdbUrls.count(m.name)) {
9093
continue;
9194
}
@@ -120,6 +123,8 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
120123
auto fieldMetadata = std::make_shared<arrow::KeyValueMetadata>();
121124
auto it = ccdbUrls.find(m.name);
122125
fieldMetadata->Append("url", it != ccdbUrls.end() ? it->second : m.defaultValue.asString());
126+
auto runDep = runDependent.find("ccdb-run-dependent:" + m.name.substr(strlen("ccdb:")));
127+
fieldMetadata->Append("runDependent", runDep != runDependent.end() ? runDep->second : "0");
123128
auto columnName = m.name.substr(strlen("ccdb:"));
124129
fields.emplace_back(std::make_shared<arrow::Field>(columnName, soa::asArrowDataType<int64_t[3]>(), false, fieldMetadata));
125130
}
@@ -280,12 +285,22 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
280285
for (auto& field : schema->fields()) {
281286
auto const& url = pathTables[i][fi++].resolve(uniformityKey, field->name());
282287
// Time to actually populate the blob
288+
// A run-dependent object is queried with the run number rather than by
289+
// timestamp alone. The run comes from the uniformity value, so the column's
290+
// table has to be uniform in the run number for this to mean anything.
291+
int const fieldRunDependent = field->metadata()->Contains("runDependent")
292+
? std::stoi(*field->metadata()->Get("runDependent"))
293+
: 0;
294+
if (fieldRunDependent != 0 && uniformityColumnName != "fRunNumber") {
295+
LOGP(fatal, R"(Column "{}" of {} is declared run-dependent, but its table is uniform in "{}" rather than fRunNumber, so no run number is available to query with. Declare the table with DECLARE_SOA_UNIFORM_TABLE(..., aod::BCs, o2::aod::bc::RunNumber, ...).)",
296+
field->name(), outBinding, uniformityColumnName);
297+
}
283298
ops.push_back({
284299
.spec = spec,
285300
.url = url,
286301
.timestamp = timestamp,
287-
.runNumber = 1,
288-
.runDependent = 0,
302+
.runNumber = fieldRunDependent != 0 ? static_cast<int>(uniformityKey) : 1,
303+
.runDependent = fieldRunDependent,
289304
.queryRate = 0,
290305
});
291306
}

0 commit comments

Comments
 (0)