Skip to content

Commit 9380490

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 fba03ad commit 9380490

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

Framework/CCDBSupport/src/AnalysisCCDBHelpers.cxx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
8484
// device's options. Here we just read the final value — honouring any further
8585
// runtime override supplied via CLI or JSON config.
8686
std::unordered_map<std::string, std::string> ccdbUrls;
87+
std::unordered_map<std::string, std::string> runDependent;
8788
for (auto& input : dec.analysisCCDBInputs) {
8889
for (auto& m : input.metadata) {
90+
if (m.name.starts_with("ccdb-run-dependent:")) {
91+
runDependent.emplace(m.name, m.defaultValue.asString());
92+
continue;
93+
}
8994
if (!m.name.starts_with("ccdb:") || ccdbUrls.count(m.name)) {
9095
continue;
9196
}
@@ -120,6 +125,8 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
120125
auto fieldMetadata = std::make_shared<arrow::KeyValueMetadata>();
121126
auto it = ccdbUrls.find(m.name);
122127
fieldMetadata->Append("url", it != ccdbUrls.end() ? it->second : m.defaultValue.asString());
128+
auto runDep = runDependent.find("ccdb-run-dependent:" + m.name.substr(strlen("ccdb:")));
129+
fieldMetadata->Append("runDependent", runDep != runDependent.end() ? runDep->second : "0");
123130
auto columnName = m.name.substr(strlen("ccdb:"));
124131
fields.emplace_back(std::make_shared<arrow::Field>(columnName, soa::asArrowDataType<int64_t[3]>(), false, fieldMetadata));
125132
}
@@ -280,12 +287,22 @@ AlgorithmSpec AnalysisCCDBHelpers::fetchFromCCDB(ConfigContext const& /*ctx*/)
280287
for (auto& field : schema->fields()) {
281288
auto const& url = pathTables[i][fi++].resolve(uniformityKey, field->name());
282289
// Time to actually populate the blob
290+
// A run-dependent object is queried with the run number rather than by
291+
// timestamp alone. The run comes from the uniformity value, so the column's
292+
// table has to be uniform in the run number for this to mean anything.
293+
int const fieldRunDependent = field->metadata()->Contains("runDependent")
294+
? std::stoi(*field->metadata()->Get("runDependent"))
295+
: 0;
296+
if (fieldRunDependent != 0 && uniformityColumnName != "fRunNumber") {
297+
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, ...).)",
298+
field->name(), outBinding, uniformityColumnName);
299+
}
283300
ops.push_back({
284301
.spec = spec,
285302
.url = url,
286303
.timestamp = timestamp,
287-
.runNumber = 1,
288-
.runDependent = 0,
304+
.runNumber = fieldRunDependent != 0 ? static_cast<int>(uniformityKey) : 1,
305+
.runDependent = fieldRunDependent,
289306
.queryRate = 0,
290307
});
291308
}

Framework/Core/include/Framework/ASoA.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,10 +2370,15 @@ consteval static std::string_view namespace_prefix()
23702370
}; \
23712371
[[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
23722372

2373-
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_, ...) \
2373+
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_, _RunDependent_, ...) \
23742374
struct _Name_ : o2::soa::Column<int64_t[3], _Name_> { \
23752375
static constexpr const char* mLabel = _Label_; \
2376-
static constexpr const char* query = _CCDBQuery_; \
2376+
static constexpr const char* query = _CCDBQuery_; \
2377+
/* How the object is keyed in CCDB: 0 queries by timestamp alone, 1 additionally sends */ \
2378+
/* the run number as "runNumber" metadata (o2::ccdb run-dependent objects), 2 uses the */ \
2379+
/* run number in place of the timestamp. A non-zero value needs the column's table to */ \
2380+
/* be uniform in the run number, since that is where the run comes from. */ \
2381+
static constexpr int run_dependent = _RunDependent_; \
23772382
static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
23782383
static constexpr bool needs_ptr_rec = true; \
23792384
/* Post-deserialisation fixup for objects which are not usable straight out of the ROOT */ \
@@ -2438,8 +2443,8 @@ consteval static std::string_view namespace_prefix()
24382443
for DECLARE_SOA_CCDB_COLUMN_FULL when it needs finalising first — a FlatObject whose
24392444
pointers must be rectified, say. Its finaliser is the trailing argument, so commas in a
24402445
lambda body are absorbed by __VA_ARGS__. */
2441-
#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2442-
DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, \
2446+
#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2447+
DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_, 0, \
24432448
[](_ConcreteType_* ccdbObject) { return ccdbObject; })
24442449

24452450
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
@@ -3355,6 +3360,9 @@ consteval auto getIndexTargets()
33553360
static constexpr const auto ccdb_bindings = []<typename... Cs>(framework::pack<Cs...>) { \
33563361
return std::array<std::string_view, sizeof...(Cs)>{Cs::mLabel...}; \
33573362
}(framework::pack<__VA_ARGS__>{}); \
3363+
static constexpr const auto ccdb_run_dependent = []<typename... Cs>(framework::pack<Cs...>) { \
3364+
return std::array<int, sizeof...(Cs)>{Cs::run_dependent...}; \
3365+
}(framework::pack<__VA_ARGS__>{}); \
33583366
/* The uniformity column may live in a table other than the timestamp source (the run */ \
33593367
/* number is on aod::BCs, the timestamp on aod::Timestamps). Both are handed to the */ \
33603368
/* fetcher, which reads them positionally — sound because the two are row-aligned. */ \

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ inline constexpr auto getCCDBUrls()
266266
framework::VariantType::String,
267267
T::ccdb_urls[i],
268268
{"\"\""}});
269+
// How this object is keyed in CCDB; the fetcher turns a non-zero value into a
270+
// run-number-qualified query rather than a plain timestamp one.
271+
result.push_back({std::string{"ccdb-run-dependent:"} + std::string{T::ccdb_bindings[i]},
272+
framework::VariantType::Int,
273+
T::ccdb_run_dependent[i],
274+
{"\"\""}});
269275
}
270276
return result;
271277
}

0 commit comments

Comments
 (0)