Skip to content

Commit

Permalink
DPL Analysis: replace SFINAE with overloaded restricted templates (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
aalkin authored Feb 20, 2025
1 parent 5e43c17 commit 4717d6b
Show file tree
Hide file tree
Showing 10 changed files with 617 additions and 629 deletions.
10 changes: 10 additions & 0 deletions Framework/Core/include/Framework/ASoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,7 @@ template <typename T, typename Policy, bool OPT = false>
struct PresliceBase : public Policy {
constexpr static bool optional = OPT;
using target_t = T;
using policy_t = Policy;
const std::string binding;

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

template <typename T>
concept is_preslice = requires(T t) {
requires std::same_as<decltype(t.binding), std::string>;
requires std::same_as<decltype(t.bindingKey), StringPair>;
&T::isMising;
&T::updateSliceInfo;
&T::getSliceFor;
};

} // namespace o2::framework

namespace o2::soa
Expand Down
45 changes: 45 additions & 0 deletions Framework/Core/include/Framework/AnalysisHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ template <is_producable T>
struct Produces : WritingCursor<T> {
};

template <typename T>
concept is_produces = requires(T t) { typename T::cursor_t; typename T::persistent_table_t; &T::cursor; };

/// Use this to group together produces. Useful to separate them logically
/// or simply to stay within the 100 elements per Task limit.
/// Use as:
Expand All @@ -201,6 +204,9 @@ struct Produces : WritingCursor<T> {
struct ProducesGroup {
};

template <typename T>
concept is_produces_group = std::derived_from<T, ProducesGroup>;

/// Helper template for table transformations
template <soa::is_metadata M, soa::TableRef Ref>
struct TableTransform {
Expand Down Expand Up @@ -250,6 +256,7 @@ constexpr auto transformBase()

template <is_spawnable T>
struct Spawns : decltype(transformBase<T>()) {
using spawnable_t = T;
using metadata = decltype(transformBase<T>())::metadata;
using extension_t = typename metadata::extension_table_t;
using base_table_t = typename metadata::base_table_t;
Expand Down Expand Up @@ -277,6 +284,12 @@ struct Spawns : decltype(transformBase<T>()) {
std::shared_ptr<extension_t> extension = nullptr;
};

template <typename T>
concept is_spawns = requires(T t) {
typename T::metadata;
requires std::same_as<decltype(t.pack()), typename T::expression_pack_t>;
};

/// Policy to control index building
/// Exclusive index: each entry in a row has a valid index
/// Sparse index: values in a row can be (-1), index table is isomorphic (joinable)
Expand Down Expand Up @@ -420,6 +433,7 @@ constexpr auto transformBase()

template <soa::is_index_table T>
struct Builds : decltype(transformBase<T>()) {
using buildable_t = T;
using metadata = decltype(transformBase<T>())::metadata;
using IP = std::conditional_t<metadata::exclusive, IndexBuilder<Exclusive>, IndexBuilder<Sparse>>;
using Key = metadata::Key;
Expand Down Expand Up @@ -455,6 +469,13 @@ struct Builds : decltype(transformBase<T>()) {
}
};

template <typename T>
concept is_builds = requires(T t) {
typename T::metadata;
typename T::Key;
requires std::same_as<decltype(t.pack()), typename T::index_pack_t>;
};

/// This helper class allows you to declare things which will be created by a
/// given analysis task. Currently wrapped objects are limited to be TNamed
/// descendants. Objects will be written to a ROOT file at the end of the
Expand Down Expand Up @@ -550,11 +571,21 @@ struct OutputObj {
uint32_t mTaskHash;
};

template <typename T>
concept is_outputobj = requires(T t) {
&T::setHash;
&T::spec;
&T::ref;
requires std::same_as<decltype(t.operator->()), typename T::obj_t*>;
requires std::same_as<decltype(t.object), std::shared_ptr<typename T::obj_t>>;
};

/// This helper allows you to fetch a Sevice from the context or
/// by using some singleton. This hopefully will hide the Singleton and
/// We will be able to retrieve it in a more thread safe manner later on.
template <typename T>
struct Service {
using service_t = T;
T* service;

decltype(auto) operator->() const
Expand All @@ -567,6 +598,12 @@ struct Service {
}
};

template <typename T>
concept is_service = requires(T t) {
requires std::same_as<decltype(t.service), typename T::service_t*>;
&T::operator->;
};

auto getTableFromFilter(soa::is_filtered_table auto const& table, soa::SelectionVector&& selection)
{
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
Expand All @@ -581,6 +618,7 @@ void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr

template <typename T>
struct Partition {
using content_t = T;
Partition(expressions::Node&& filter_) : filter{std::forward<expressions::Node>(filter_)}
{
}
Expand Down Expand Up @@ -690,6 +728,13 @@ struct Partition {
return mFiltered->size();
}
};

template <typename T>
concept is_partition = requires(T t) {
&T::updatePlaceholders;
requires std::same_as<decltype(t.filter), expressions::Filter>;
requires std::same_as<decltype(t.mFiltered), std::unique_ptr<o2::soa::Filtered<typename T::content_t>>>;
};
} // namespace o2::framework

namespace o2::soa
Expand Down
Loading

0 comments on commit 4717d6b

Please sign in to comment.