Skip to content

Commit 9e322a9

Browse files
authored
DPL Analysis: improve handling of tables with sources (AliceO2Group#14172)
1 parent b75d643 commit 9e322a9

File tree

3 files changed

+57
-69
lines changed

3 files changed

+57
-69
lines changed

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "Framework/ASoA.h"
1515
#include "Framework/DataAllocator.h"
16-
#include "Framework/ExpressionHelpers.h"
1716
#include "Framework/IndexBuilderHelpers.h"
1817
#include "Framework/InputSpec.h"
1918
#include "Framework/Output.h"
@@ -28,14 +27,58 @@
2827
#include <string>
2928
namespace o2::soa
3029
{
30+
template <TableRef R>
31+
constexpr auto tableRef2ConfigParamSpec()
32+
{
33+
return o2::framework::ConfigParamSpec{
34+
std::string{"input:"} + o2::aod::label<R>(),
35+
framework::VariantType::String,
36+
aod::sourceSpec<R>(),
37+
{"\"\""}};
38+
}
39+
40+
namespace
41+
{
42+
template <soa::with_sources T>
43+
inline constexpr auto getSources()
44+
{
45+
return []<size_t N, std::array<soa::TableRef, N> refs>() {
46+
return []<size_t... Is>(std::index_sequence<Is...>) {
47+
return std::vector{soa::tableRef2ConfigParamSpec<refs[Is]>()...};
48+
}(std::make_index_sequence<N>());
49+
}.template operator()<T::sources.size(), T::sources>();
50+
}
51+
52+
template <soa::with_sources T>
53+
constexpr auto getInputMetadata() -> std::vector<framework::ConfigParamSpec>
54+
{
55+
std::vector<framework::ConfigParamSpec> inputMetadata;
56+
auto inputSources = getSources<T>();
57+
std::sort(inputSources.begin(), inputSources.end(), [](framework::ConfigParamSpec const& a, framework::ConfigParamSpec const& b) { return a.name < b.name; });
58+
auto last = std::unique(inputSources.begin(), inputSources.end(), [](framework::ConfigParamSpec const& a, framework::ConfigParamSpec const& b) { return a.name == b.name; });
59+
inputSources.erase(last, inputSources.end());
60+
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
61+
return inputMetadata;
62+
}
63+
64+
template <typename T>
65+
requires(!soa::with_sources<T>)
66+
constexpr auto getInputMetadata() -> std::vector<framework::ConfigParamSpec>
67+
{
68+
return {};
69+
}
70+
} // namespace
71+
3172
template <TableRef R>
3273
constexpr auto tableRef2InputSpec()
3374
{
3475
return framework::InputSpec{
3576
o2::aod::label<R>(),
3677
o2::aod::origin<R>(),
3778
o2::aod::description(o2::aod::signature<R>()),
38-
R.version};
79+
R.version,
80+
framework::Lifetime::Timeframe,
81+
getInputMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>()};
3982
}
4083

4184
template <TableRef R>
@@ -64,16 +107,6 @@ constexpr auto tableRef2OutputRef()
64107
o2::aod::label<R>(),
65108
R.version};
66109
}
67-
68-
template <TableRef R>
69-
constexpr auto tableRef2ConfigParamSpec()
70-
{
71-
return o2::framework::ConfigParamSpec{
72-
std::string{"input:"} + o2::aod::label<R>(),
73-
framework::VariantType::String,
74-
aod::sourceSpec<R>(),
75-
{"\"\""}};
76-
}
77110
} // namespace o2::soa
78111

79112
namespace o2::framework

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,46 +65,6 @@ concept is_enumeration = is_enumeration_v<std::decay_t<T>>;
6565
// the contents of an AnalysisTask...
6666
namespace {
6767
struct AnalysisDataProcessorBuilder {
68-
template <typename T>
69-
static ConfigParamSpec getSpec()
70-
{
71-
if constexpr (soa::has_metadata<aod::MetadataTrait<T>>) {
72-
return ConfigParamSpec{std::string{"input:"} + aod::MetadataTrait<T>::metadata::tableLabel(), VariantType::String, aod::MetadataTrait<T>::metadata::sourceSpec(), {"\"\""}};
73-
} else {
74-
using O1 = framework::pack_element_t<0, typename T::originals>;
75-
return ConfigParamSpec{std::string{"input:"} + aod::MetadataTrait<T>::metadata::tableLabel(), VariantType::String, aod::MetadataTrait<O1>::metadata::sourceSpec(), {"\"\""}};
76-
}
77-
}
78-
79-
template <soa::TableRef R>
80-
static ConfigParamSpec getSpec()
81-
{
82-
return soa::tableRef2ConfigParamSpec<R>();
83-
}
84-
85-
template <soa::with_sources T>
86-
static inline auto getSources()
87-
{
88-
return []<size_t N, std::array<soa::TableRef, N> refs>() {
89-
return []<size_t... Is>(std::index_sequence<Is...>) {
90-
return std::vector{soa::tableRef2ConfigParamSpec<refs[Is]>()...};
91-
}(std::make_index_sequence<N>());
92-
}.template operator()<T::sources.size(), T::sources>();
93-
}
94-
95-
template <soa::with_sources T>
96-
97-
static auto getInputMetadata()
98-
{
99-
std::vector<ConfigParamSpec> inputMetadata;
100-
auto inputSources = getSources<T>();
101-
std::sort(inputSources.begin(), inputSources.end(), [](ConfigParamSpec const& a, ConfigParamSpec const& b) { return a.name < b.name; });
102-
auto last = std::unique(inputSources.begin(), inputSources.end(), [](ConfigParamSpec const& a, ConfigParamSpec const& b) { return a.name == b.name; });
103-
inputSources.erase(last, inputSources.end());
104-
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
105-
return inputMetadata;
106-
}
107-
10868
template <typename G, typename... Args>
10969
static void addGroupingCandidates(std::vector<StringPair>& bk, std::vector<StringPair>& bku)
11070
{
@@ -130,14 +90,9 @@ struct AnalysisDataProcessorBuilder {
13090
template <soa::TableRef R>
13191
static void addOriginalRef(const char* name, bool value, std::vector<InputSpec>& inputs)
13292
{
133-
using metadata = typename aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata;
134-
std::vector<ConfigParamSpec> inputMetadata;
135-
inputMetadata.emplace_back(ConfigParamSpec{std::string{"control:"} + name, VariantType::Bool, value, {"\"\""}});
136-
if constexpr (soa::with_sources<metadata>) {
137-
auto inputSources = getInputMetadata<metadata>();
138-
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
139-
}
140-
DataSpecUtils::updateInputList(inputs, InputSpec{o2::aod::label<R>(), o2::aod::origin<R>(), aod::description(o2::aod::signature<R>()), R.version, Lifetime::Timeframe, inputMetadata});
93+
auto spec = soa::tableRef2InputSpec<R>();
94+
spec.metadata.emplace_back(ConfigParamSpec{std::string{"control:"} + name, VariantType::Bool, value, {"\"\""}});
95+
DataSpecUtils::updateInputList(inputs, std::move(spec));
14196
}
14297

14398
/// helpers to append expression information for a single argument

Framework/Core/src/WorkflowHelpers.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
385385
auto outputSpecLessThan = [](OutputSpec const& lhs, OutputSpec const& rhs) { return DataSpecUtils::describe(lhs) < DataSpecUtils::describe(rhs); };
386386
std::sort(ac.requestedDYNs.begin(), ac.requestedDYNs.end(), inputSpecLessThan);
387387
std::sort(ac.providedDYNs.begin(), ac.providedDYNs.end(), outputSpecLessThan);
388+
389+
DataProcessorSpec indexBuilder{
390+
"internal-dpl-aod-index-builder",
391+
{},
392+
{},
393+
readers::AODReaderHelpers::indexBuilderCallback(ac.requestedIDXs),
394+
{}};
395+
AnalysisSupportHelpers::addMissingOutputsToBuilder(ac.requestedIDXs, ac.requestedAODs, ac.requestedDYNs, indexBuilder);
396+
388397
for (auto& input : ac.requestedDYNs) {
389398
if (std::none_of(ac.providedDYNs.begin(), ac.providedDYNs.end(), [&input](auto const& x) { return DataSpecUtils::match(input, x); })) {
390399
ac.spawnerInputs.emplace_back(input);
@@ -397,15 +406,6 @@ void WorkflowHelpers::injectServiceDevices(WorkflowSpec& workflow, ConfigContext
397406
{},
398407
readers::AODReaderHelpers::aodSpawnerCallback(ac.spawnerInputs),
399408
{}};
400-
401-
DataProcessorSpec indexBuilder{
402-
"internal-dpl-aod-index-builder",
403-
{},
404-
{},
405-
readers::AODReaderHelpers::indexBuilderCallback(ac.requestedIDXs),
406-
{}};
407-
408-
AnalysisSupportHelpers::addMissingOutputsToBuilder(ac.requestedIDXs, ac.requestedAODs, ac.requestedDYNs, indexBuilder);
409409
AnalysisSupportHelpers::addMissingOutputsToSpawner({}, ac.spawnerInputs, ac.requestedAODs, aodSpawner);
410410

411411
AnalysisSupportHelpers::addMissingOutputsToReader(ac.providedAODs, ac.requestedAODs, aodReader);

0 commit comments

Comments
 (0)