Skip to content

Commit 4717d6b

Browse files
authored
DPL Analysis: replace SFINAE with overloaded restricted templates (#13947)
1 parent 5e43c17 commit 4717d6b

File tree

10 files changed

+617
-629
lines changed

10 files changed

+617
-629
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ template <typename T, typename Policy, bool OPT = false>
14161416
struct PresliceBase : public Policy {
14171417
constexpr static bool optional = OPT;
14181418
using target_t = T;
1419+
using policy_t = Policy;
14191420
const std::string binding;
14201421

14211422
PresliceBase(expressions::BindingNode index_)
@@ -1453,6 +1454,15 @@ using Preslice = PresliceBase<T, PreslicePolicySorted, false>;
14531454
template <typename T>
14541455
using PresliceOptional = PresliceBase<T, PreslicePolicySorted, true>;
14551456

1457+
template <typename T>
1458+
concept is_preslice = requires(T t) {
1459+
requires std::same_as<decltype(t.binding), std::string>;
1460+
requires std::same_as<decltype(t.bindingKey), StringPair>;
1461+
&T::isMising;
1462+
&T::updateSliceInfo;
1463+
&T::getSliceFor;
1464+
};
1465+
14561466
} // namespace o2::framework
14571467

14581468
namespace o2::soa

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ template <is_producable T>
190190
struct Produces : WritingCursor<T> {
191191
};
192192

193+
template <typename T>
194+
concept is_produces = requires(T t) { typename T::cursor_t; typename T::persistent_table_t; &T::cursor; };
195+
193196
/// Use this to group together produces. Useful to separate them logically
194197
/// or simply to stay within the 100 elements per Task limit.
195198
/// Use as:
@@ -201,6 +204,9 @@ struct Produces : WritingCursor<T> {
201204
struct ProducesGroup {
202205
};
203206

207+
template <typename T>
208+
concept is_produces_group = std::derived_from<T, ProducesGroup>;
209+
204210
/// Helper template for table transformations
205211
template <soa::is_metadata M, soa::TableRef Ref>
206212
struct TableTransform {
@@ -250,6 +256,7 @@ constexpr auto transformBase()
250256

251257
template <is_spawnable T>
252258
struct Spawns : decltype(transformBase<T>()) {
259+
using spawnable_t = T;
253260
using metadata = decltype(transformBase<T>())::metadata;
254261
using extension_t = typename metadata::extension_table_t;
255262
using base_table_t = typename metadata::base_table_t;
@@ -277,6 +284,12 @@ struct Spawns : decltype(transformBase<T>()) {
277284
std::shared_ptr<extension_t> extension = nullptr;
278285
};
279286

287+
template <typename T>
288+
concept is_spawns = requires(T t) {
289+
typename T::metadata;
290+
requires std::same_as<decltype(t.pack()), typename T::expression_pack_t>;
291+
};
292+
280293
/// Policy to control index building
281294
/// Exclusive index: each entry in a row has a valid index
282295
/// Sparse index: values in a row can be (-1), index table is isomorphic (joinable)
@@ -420,6 +433,7 @@ constexpr auto transformBase()
420433

421434
template <soa::is_index_table T>
422435
struct Builds : decltype(transformBase<T>()) {
436+
using buildable_t = T;
423437
using metadata = decltype(transformBase<T>())::metadata;
424438
using IP = std::conditional_t<metadata::exclusive, IndexBuilder<Exclusive>, IndexBuilder<Sparse>>;
425439
using Key = metadata::Key;
@@ -455,6 +469,13 @@ struct Builds : decltype(transformBase<T>()) {
455469
}
456470
};
457471

472+
template <typename T>
473+
concept is_builds = requires(T t) {
474+
typename T::metadata;
475+
typename T::Key;
476+
requires std::same_as<decltype(t.pack()), typename T::index_pack_t>;
477+
};
478+
458479
/// This helper class allows you to declare things which will be created by a
459480
/// given analysis task. Currently wrapped objects are limited to be TNamed
460481
/// descendants. Objects will be written to a ROOT file at the end of the
@@ -550,11 +571,21 @@ struct OutputObj {
550571
uint32_t mTaskHash;
551572
};
552573

574+
template <typename T>
575+
concept is_outputobj = requires(T t) {
576+
&T::setHash;
577+
&T::spec;
578+
&T::ref;
579+
requires std::same_as<decltype(t.operator->()), typename T::obj_t*>;
580+
requires std::same_as<decltype(t.object), std::shared_ptr<typename T::obj_t>>;
581+
};
582+
553583
/// This helper allows you to fetch a Sevice from the context or
554584
/// by using some singleton. This hopefully will hide the Singleton and
555585
/// We will be able to retrieve it in a more thread safe manner later on.
556586
template <typename T>
557587
struct Service {
588+
using service_t = T;
558589
T* service;
559590

560591
decltype(auto) operator->() const
@@ -567,6 +598,12 @@ struct Service {
567598
}
568599
};
569600

601+
template <typename T>
602+
concept is_service = requires(T t) {
603+
requires std::same_as<decltype(t.service), typename T::service_t*>;
604+
&T::operator->;
605+
};
606+
570607
auto getTableFromFilter(soa::is_filtered_table auto const& table, soa::SelectionVector&& selection)
571608
{
572609
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
@@ -581,6 +618,7 @@ void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr
581618

582619
template <typename T>
583620
struct Partition {
621+
using content_t = T;
584622
Partition(expressions::Node&& filter_) : filter{std::forward<expressions::Node>(filter_)}
585623
{
586624
}
@@ -690,6 +728,13 @@ struct Partition {
690728
return mFiltered->size();
691729
}
692730
};
731+
732+
template <typename T>
733+
concept is_partition = requires(T t) {
734+
&T::updatePlaceholders;
735+
requires std::same_as<decltype(t.filter), expressions::Filter>;
736+
requires std::same_as<decltype(t.mFiltered), std::unique_ptr<o2::soa::Filtered<typename T::content_t>>>;
737+
};
693738
} // namespace o2::framework
694739

695740
namespace o2::soa

0 commit comments

Comments
 (0)