Skip to content

Commit 61fbfde

Browse files
committed
complete baseline origin replacement
1 parent e8854d7 commit 61fbfde

6 files changed

Lines changed: 141 additions & 64 deletions

File tree

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ struct Builder {
173173

174174
std::shared_ptr<arrow::Table> materialize(ProcessingContext& pc);
175175
};
176+
177+
ConfigParamSpec replaceOrigin(ConfigParamSpec& source, std::string const& originStr);
178+
ConcreteDataMatcher replaceOrigin(ConcreteDataMatcher& matcher, const header::DataOrigin& newOrigin);
176179
} // namespace o2::framework
177180

178181
namespace o2::soa
@@ -274,19 +277,23 @@ consteval IndexKind getIndexKind()
274277
}
275278

276279
template <soa::with_index_pack T>
277-
inline constexpr auto getIndexMapping()
280+
inline constexpr auto getIndexMapping(header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
278281
{
279282
std::vector<IndexRecord> idx;
280283
using indices = T::index_pack_t;
281284
using Key = T::Key;
282-
[&idx]<size_t... Is>(std::index_sequence<Is...>) mutable {
285+
[&idx, &newOrigin]<size_t... Is>(std::index_sequence<Is...>) mutable {
283286
constexpr auto refs = T::generateSources();
284-
([&idx]<TableRef ref, typename C>() mutable {
287+
([&idx, &newOrigin]<TableRef ref, typename C>() mutable {
285288
constexpr auto pos = o2::aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::template getIndexPosToKey<Key>();
289+
auto matcher = o2::aod::matcher<ref>();
290+
if ((ref.origin_hash == "AOD"_h) && (newOrigin != header::DataOrigin{"AOD"})) {
291+
matcher = replaceOrigin(matcher, newOrigin);
292+
}
286293
if constexpr (pos == -1) {
287-
idx.emplace_back(o2::aod::label<ref>(), o2::aod::matcher<ref>(), C::columnLabel(), IndexKind::IdxSelf, pos);
294+
idx.emplace_back(o2::aod::label<ref>(), matcher, C::columnLabel(), IndexKind::IdxSelf, pos);
288295
} else {
289-
idx.emplace_back(o2::aod::label<ref>(), o2::aod::matcher<ref>(), C::columnLabel(), getIndexKind<typename C::type>(), pos);
296+
idx.emplace_back(o2::aod::label<ref>(), matcher, C::columnLabel(), getIndexKind<typename C::type>(), pos);
290297
}
291298
}.template operator()<refs[Is], typename framework::pack_element_t<Is, indices>>(),
292299
...);
@@ -381,24 +388,24 @@ constexpr auto getExpressionMetadata() -> std::vector<framework::ConfigParamSpec
381388
}
382389

383390
template <soa::with_index_pack T>
384-
constexpr auto getIndexMetadata() -> std::vector<framework::ConfigParamSpec>
391+
constexpr auto getIndexMetadata(header::DataOrigin newOrigin = header::DataOrigin{"AOD"}) -> std::vector<framework::ConfigParamSpec>
385392
{
386-
auto map = getIndexMapping<T>();
393+
auto map = getIndexMapping<T>(newOrigin);
387394
return {framework::ConfigParamSpec{"index-records", framework::VariantType::String, framework::serializeIndexRecords(map), {"\"\""}},
388395
{framework::ConfigParamSpec{"index-exclusive", framework::VariantType::Bool, T::exclusive, {"\"\""}}}};
389396
}
390397

391398
template <typename T>
392399
requires(!soa::with_index_pack<T>)
393-
constexpr auto getIndexMetadata() -> std::vector<framework::ConfigParamSpec>
400+
constexpr auto getIndexMetadata(header::DataOrigin) -> std::vector<framework::ConfigParamSpec>
394401
{
395402
return {};
396403
}
397404

398405
} // namespace
399406

400407
template <TableRef R>
401-
constexpr auto tableRef2InputSpec()
408+
constexpr auto tableRef2InputSpec(header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
402409
{
403410
std::vector<framework::ConfigParamSpec> metadata;
404411
std::vector<framework::ConfigParamSpec> sources;
@@ -407,24 +414,29 @@ constexpr auto tableRef2InputSpec()
407414
} else if constexpr (soa::with_sources_generator<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>) {
408415
sources = getInputMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata, o2::aod::Hash<R.origin_hash>>();
409416
}
417+
if ((R.origin_hash == "AOD"_h) && (newOrigin != header::DataOrigin{"AOD"})) {
418+
std::ranges::transform(sources, sources.begin(), [originStr = newOrigin.as<std::string>()](framework::ConfigParamSpec& source){
419+
return replaceOrigin(source, originStr);
420+
});
421+
}
410422
metadata.insert(metadata.end(), sources.begin(), sources.end());
411423
auto ccdbURLs = getCCDBMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>();
412424
metadata.insert(metadata.end(), ccdbURLs.begin(), ccdbURLs.end());
413425
auto expressions = getExpressionMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>();
414426
metadata.insert(metadata.end(), expressions.begin(), expressions.end());
415-
auto indices = getIndexMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>();
427+
auto indices = getIndexMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>(newOrigin);
416428
metadata.insert(metadata.end(), indices.begin(), indices.end());
417429
if constexpr (!soa::with_ccdb_urls<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>) {
418430
metadata.emplace_back(framework::ConfigParamSpec{"schema", framework::VariantType::String, framework::serializeSchema(o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata::getSchema()), {"\"\""}});
419431
}
420432

421433
return framework::InputSpec{
422-
o2::aod::label<R>(),
423-
o2::aod::origin<R>(),
424-
o2::aod::description(o2::aod::signature<R>()),
425-
R.version,
426-
framework::Lifetime::Timeframe,
427-
metadata};
434+
o2::aod::label<R>(),
435+
((R.origin_hash == "AOD"_h) && (newOrigin != header::DataOrigin{"AOD"})) ? newOrigin : o2::aod::origin<R>(),
436+
o2::aod::description(o2::aod::signature<R>()),
437+
R.version,
438+
framework::Lifetime::Timeframe,
439+
metadata};
428440
}
429441

430442
template <TableRef R>

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,30 @@ static void setGroupedCombination(C& comb, TG& grouping, std::tuple<Ts...>& asso
577577
}
578578

579579
/// Preslice handling
580+
template <typename T>
581+
requires(!is_preslice<T> && !is_preslice_group<T>)
582+
bool replaceOrigin(T&, header::DataOrigin const&)
583+
{
584+
return false;
585+
}
586+
587+
template <is_preslice T>
588+
bool replaceOrigin(T& preslice, header::DataOrigin const& newOrigin)
589+
{
590+
if ((T::target_t::originals[0].origin_hash == "AOD"_h) && (newOrigin != header::DataOrigin{"AOD"})) {
591+
preslice.bindingKey.matcher = framework::replaceOrigin(preslice.bindingKey.matcher, newOrigin);
592+
return true;
593+
}
594+
return false;
595+
}
596+
597+
template <is_preslice_group T>
598+
bool replaceOrigin(T& presliceGroup, header::DataOrigin const& newOrigin)
599+
{
600+
homogeneous_apply_refs<true>([&newOrigin](auto& preslice){ return replaceOrigin(preslice, newOrigin); }, presliceGroup);
601+
return true;
602+
}
603+
580604
template <typename T>
581605
requires(!is_preslice<T> && !is_preslice_group<T>)
582606
bool registerCache(T&, Cache&, Cache&)

0 commit comments

Comments
 (0)