Skip to content

Commit b0b090f

Browse files
authored
DPL Analysis: Preliminary changes for Table rewrite (#13679)
1 parent 496ce9d commit b0b090f

File tree

13 files changed

+291
-408
lines changed

13 files changed

+291
-408
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 166 additions & 182 deletions
Large diffs are not rendered by default.

Framework/Core/include/Framework/ASoAHelpers.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
8888
return groupedIndices;
8989
}
9090

91-
if constexpr (soa::is_soa_filtered_v<T>) {
91+
if constexpr (soa::is_filtered_table<T>) {
9292
selectedRows = table.getSelectedRows(); // vector<int64_t>
9393
}
9494

@@ -111,7 +111,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
111111
}
112112
});
113113

114-
if constexpr (soa::is_soa_filtered_v<T>) {
114+
if constexpr (soa::is_filtered_table<T>) {
115115
if (selectedRows[ind] >= selInd + chunkLength) {
116116
selInd += chunkLength;
117117
continue; // Go to the next chunk, no value selected in this chunk
@@ -120,7 +120,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
120120

121121
uint64_t ai = 0;
122122
while (ai < chunkLength) {
123-
if constexpr (soa::is_soa_filtered_v<T>) {
123+
if constexpr (soa::is_filtered_table<T>) {
124124
ai += selectedRows[ind] - selInd;
125125
selInd = selectedRows[ind];
126126
}
@@ -132,7 +132,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
132132
}
133133
ind++;
134134

135-
if constexpr (soa::is_soa_filtered_v<T>) {
135+
if constexpr (soa::is_filtered_table<T>) {
136136
if (ind >= selectedRows.size()) {
137137
break;
138138
}
@@ -141,7 +141,7 @@ std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPol
141141
}
142142
}
143143

144-
if constexpr (soa::is_soa_filtered_v<T>) {
144+
if constexpr (soa::is_filtered_table<T>) {
145145
if (ind == selectedRows.size()) {
146146
break;
147147
}
@@ -1348,7 +1348,7 @@ auto combinations(const BP& binningPolicy, int categoryNeighbours, const T1& out
13481348
}
13491349
}
13501350

1351-
template <typename... T2s>
1351+
template <soa::is_table... T2s>
13521352
auto combinations(const o2::framework::expressions::Filter& filter, const T2s&... tables)
13531353
{
13541354
if constexpr (isSameType<T2s...>()) {
@@ -1366,7 +1366,7 @@ CombinationsGenerator<P2<T2s...>> combinations(const P2<T2s...>& policy)
13661366
return CombinationsGenerator<P2<T2s...>>(policy);
13671367
}
13681368

1369-
template <template <typename...> typename P2, typename... T2s>
1369+
template <template <typename...> typename P2, soa::is_table... T2s>
13701370
CombinationsGenerator<P2<Filtered<T2s>...>> combinations(P2<T2s...>&&, const o2::framework::expressions::Filter& filter, const T2s&... tables)
13711371
{
13721372
return CombinationsGenerator<P2<Filtered<T2s>...>>(P2<Filtered<T2s>...>(tables.select(filter)...));

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct WritingCursor<soa::Table<ORIGIN, PC...>> {
8787
template <typename T>
8888
static decltype(auto) extract(T const& arg)
8989
{
90-
if constexpr (soa::is_soa_iterator_v<T>) {
90+
if constexpr (requires(T t) { t.globalIndex(); }) {
9191
return arg.globalIndex();
9292
} else {
9393
static_assert(!framework::has_type<T>(framework::pack<PC...>{}), "Argument type mismatch");
@@ -104,6 +104,7 @@ struct WritingCursor<soa::Table<ORIGIN, PC...>> {
104104

105105
/// Helper to define output for a Table
106106
template <typename T>
107+
requires soa::is_table<T> || soa::is_iterator<T>
107108
struct OutputForTable {
108109
using table_t = T;
109110
using metadata = typename aod::MetadataTrait<table_t>::metadata;
@@ -243,16 +244,15 @@ namespace
243244
template <typename T, typename Key>
244245
inline std::shared_ptr<arrow::ChunkedArray> getIndexToKey(arrow::Table* table)
245246
{
246-
using IC = framework::pack_element_t<framework::has_type_at_conditional<soa::is_binding_compatible, Key>(typename T::external_index_columns_t{}), typename T::external_index_columns_t>;
247-
return table->column(framework::has_type_at<IC>(typename T::persistent_columns_t{}));
247+
using IC = framework::pack_element_t<framework::has_type_at_conditional_v<soa::is_binding_compatible, Key>(typename T::external_index_columns_t{}), typename T::external_index_columns_t>;
248+
return table->column(framework::has_type_at_v<IC>(typename T::persistent_columns_t{}));
248249
}
249250

250-
template <typename C>
251+
template <soa::is_column C>
251252
struct ColumnTrait {
252-
static_assert(framework::is_base_of_template_v<o2::soa::Column, C>, "Not a column type!");
253253
using column_t = C;
254254

255-
static constexpr auto listSize()
255+
static consteval auto listSize()
256256
{
257257
if constexpr (std::is_same_v<typename C::type, std::vector<int>>) {
258258
return -1;
@@ -483,14 +483,14 @@ struct Service {
483483
}
484484
};
485485

486-
template <typename T>
487-
auto getTableFromFilter(const T& table, soa::SelectionVector&& selection)
486+
auto getTableFromFilter(soa::is_filtered_table auto const& table, soa::SelectionVector&& selection)
488487
{
489-
if constexpr (soa::is_soa_filtered_v<std::decay_t<T>>) {
490-
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
491-
} else {
492-
return std::make_unique<o2::soa::Filtered<T>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
493-
}
488+
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
489+
}
490+
491+
auto getTableFromFilter(soa::is_not_filtered_table auto const& table, soa::SelectionVector&& selection)
492+
{
493+
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
494494
}
495495

496496
void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);
@@ -611,20 +611,18 @@ struct Partition {
611611
namespace o2::soa
612612
{
613613
/// On-the-fly adding of expression columns
614-
template <typename T, typename... Cs>
614+
template <soa::is_table T, soa::is_spawnable_column... Cs>
615615
auto Extend(T const& table)
616616
{
617-
static_assert((soa::is_type_spawnable_v<Cs> && ...), "You can only extend a table with expression columns");
618617
using output_t = Join<T, soa::Table<o2::framework::OriginEnc{"JOIN"}, Cs...>>;
619618
return output_t{{o2::framework::spawner<o2::framework::OriginEnc{"JOIN"}>(framework::pack<Cs...>{}, {table.asArrowTable()}, "dynamicExtension"), table.asArrowTable()}, 0};
620619
}
621620

622621
/// Template function to attach dynamic columns on-the-fly (e.g. inside
623622
/// process() function). Dynamic columns need to be compatible with the table.
624-
template <typename T, typename... Cs>
623+
template <soa::is_table T, soa::is_dynamic_column... Cs>
625624
auto Attach(T const& table)
626625
{
627-
static_assert((framework::is_base_of_template_v<o2::soa::DynamicColumn, Cs> && ...), "You can only attach dynamic columns");
628626
using output_t = Join<T, o2::soa::Table<o2::framework::OriginEnc{"JOIN"}, Cs...>>;
629627
return output_t{{table.asArrowTable()}, table.offset()};
630628
}

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -417,43 +417,6 @@ struct OutputManager<Builds<T>> {
417417
}
418418
};
419419

420-
template <typename T>
421-
class has_instance
422-
{
423-
using one = char;
424-
struct two {
425-
char x[2];
426-
};
427-
428-
template <typename C>
429-
static one test(decltype(&C::instance));
430-
template <typename C>
431-
static two test(...);
432-
433-
public:
434-
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
435-
};
436-
437-
template <typename T>
438-
class has_end_of_stream
439-
{
440-
using one = char;
441-
struct two {
442-
char x[2];
443-
};
444-
445-
template <typename C>
446-
static one test(decltype(&C::endOfStream));
447-
template <typename C>
448-
static two test(...);
449-
450-
public:
451-
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
452-
};
453-
454-
template <typename T>
455-
inline constexpr bool has_end_of_stream_v = has_end_of_stream<T>::value;
456-
457420
template <typename T>
458421
struct ServiceManager {
459422
template <typename ANY>
@@ -477,7 +440,7 @@ struct ServiceManager {
477440

478441
template <typename T>
479442
struct ServiceManager<Service<T>> {
480-
static bool add(std::vector<ServiceSpec>& specs, Service<T>& service)
443+
static bool add(std::vector<ServiceSpec>& specs, Service<T>& /*service*/)
481444
{
482445
if constexpr (o2::framework::is_base_of_template_v<LoadableServicePlugin, T>) {
483446
T p = T{};
@@ -489,7 +452,7 @@ struct ServiceManager<Service<T>> {
489452

490453
static bool prepare(InitContext& context, Service<T>& service)
491454
{
492-
if constexpr (has_instance<T>::value) {
455+
if constexpr (requires { &T::instance; }) {
493456
service.service = &(T::instance()); // Sigh...
494457
return true;
495458
} else {
@@ -500,11 +463,11 @@ struct ServiceManager<Service<T>> {
500463
}
501464

502465
/// If a service has a method endOfStream, it is called at the end of the stream.
503-
static bool postRun(EndOfStreamContext& context, Service<T>& service)
466+
static bool postRun(EndOfStreamContext& /*context*/, Service<T>& service)
504467
{
505468
// FIXME: for the moment we only need endOfStream to be
506469
// stateless. In the future we might want to pass it EndOfStreamContext
507-
if constexpr (has_end_of_stream_v<T>) {
470+
if constexpr (requires { &T::endOfStream; }) {
508471
service.service->endOfStream();
509472
return true;
510473
}
@@ -637,7 +600,7 @@ struct SpawnManager {
637600
static bool requestInputs(std::vector<InputSpec>&, T const&) { return false; }
638601
};
639602

640-
template <typename TABLE>
603+
template <soa::is_table TABLE>
641604
struct SpawnManager<Spawns<TABLE>> {
642605
static bool requestInputs(std::vector<InputSpec>& inputs, Spawns<TABLE>& spawns)
643606
{
@@ -656,7 +619,7 @@ struct IndexManager {
656619
static bool requestInputs(std::vector<InputSpec>&, T const&) { return false; };
657620
};
658621

659-
template <typename IDX>
622+
template <soa::is_index_table IDX>
660623
struct IndexManager<Builds<IDX>> {
661624
static bool requestInputs(std::vector<InputSpec>& inputs, Builds<IDX>& builds)
662625
{

0 commit comments

Comments
 (0)