Skip to content

Commit

Permalink
DPL Analysis: make BindingNodes constexpr (#12661)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalkin authored Feb 7, 2024
1 parent a919d1f commit 1c7eb18
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 201 deletions.
327 changes: 163 additions & 164 deletions Framework/Core/include/Framework/ASoA.h

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Framework/Core/include/Framework/AnalysisTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct AnalysisDataProcessorBuilder {
DataSpecUtils::updateInputList(inputs, std::move(newInput));
}

static void doAppendEnumeration(const char* name, int64_t begin, int64_t end, int64_t step, std::vector<InputSpec>& inputs)
static void doAppendEnumeration(const char*, int64_t, int64_t, int64_t, std::vector<InputSpec>& inputs)
{
std::vector<ConfigParamSpec> inputMetadata;
// FIXME: for the moment we do not support begin, end and step.
Expand All @@ -148,11 +148,11 @@ struct AnalysisDataProcessorBuilder {
if constexpr (is_enumeration_v<dT> == false) {
if constexpr (soa::is_soa_filtered_v<dT>) {
auto fields = createFieldsFromColumns(typename dT::table_t::persistent_columns_t{});
eInfos.push_back({ai, hash, dT::hashes(), std::make_shared<arrow::Schema>(fields), nullptr});
eInfos.emplace_back(ai, hash, dT::hashes(), std::make_shared<arrow::Schema>(fields));
} else if constexpr (soa::is_soa_iterator_v<dT>) {
auto fields = createFieldsFromColumns(typename dT::parent_t::persistent_columns_t{});
if constexpr (std::is_same_v<typename dT::policy_t, soa::FilteredIndexPolicy>) {
eInfos.push_back({ai, hash, dT::parent_t::hashes(), std::make_shared<arrow::Schema>(fields), nullptr});
eInfos.emplace_back(ai, hash, dT::parent_t::hashes(), std::make_shared<arrow::Schema>(fields));
}
}
doAppendInputWithMetadata(soa::make_originals_from_type<dT>(), name, value, inputs);
Expand Down Expand Up @@ -189,7 +189,7 @@ struct AnalysisDataProcessorBuilder {
static void inputsFromArgs(R (C::*)(Args...), const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos, std::vector<StringPair>& bk, std::vector<StringPair>& bku)
{
int ai = 0;
auto hash = typeHash<R (C::*)(Args...)>();
auto hash = o2::framework::TypeIdHelpers::uniqueId<R (C::*)(Args...)>();
if constexpr (soa::is_soa_iterator_v<std::decay_t<framework::pack_element_t<0, framework::pack<Args...>>>>) {
appendGroupingCandidates(bk, bku, framework::pack<Args...>{});
}
Expand All @@ -205,7 +205,7 @@ struct AnalysisDataProcessorBuilder {
template <typename R, typename C, typename Grouping, typename... Args>
static auto bindGroupingTable(InputRecord& record, R (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
{
auto hash = typeHash<R (C::*)(Grouping, Args...)>();
auto hash = o2::framework::TypeIdHelpers::uniqueId<R (C::*)(Grouping, Args...)>();
return extractSomethingFromRecord<Grouping, 0>(record, infos, hash);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ struct AnalysisDataProcessorBuilder {
static auto bindAssociatedTables(InputRecord& record, R (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
{
constexpr auto p = pack<Args...>{};
auto hash = typeHash<R (C::*)(Grouping, Args...)>();
auto hash = o2::framework::TypeIdHelpers::uniqueId<R (C::*)(Grouping, Args...)>();
return std::make_tuple(extractSomethingFromRecord<Args, has_type_at_v<Args>(p) + 1>(record, infos, hash)...);
}

Expand Down
21 changes: 14 additions & 7 deletions Framework/Core/include/Framework/Expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ using FilterPtr = std::shared_ptr<gandiva::Filter>;

using atype = arrow::Type;
struct ExpressionInfo {
ExpressionInfo(int ai, size_t hash, std::set<uint32_t>&& hs, gandiva::SchemaPtr sc)
: argumentIndex(ai),
processHash(hash),
hashes(hs),
schema(sc)
{
}
int argumentIndex;
size_t processHash;
std::set<size_t> hashes;
std::set<uint32_t> hashes;
gandiva::SchemaPtr schema;
gandiva::NodePtr tree;
gandiva::FilterPtr filter;
gandiva::Selection selection;
gandiva::NodePtr tree = nullptr;
gandiva::FilterPtr filter = nullptr;
gandiva::Selection selection = nullptr;
bool resetSelection = false;
};

Expand Down Expand Up @@ -122,9 +129,9 @@ struct LiteralNode {
struct BindingNode {
BindingNode(BindingNode const&) = default;
BindingNode(BindingNode&&) = delete;
BindingNode(std::string const& name_, std::size_t hash_, atype::type type_) : name{name_}, hash{hash_}, type{type_} {}
std::string name;
std::size_t hash;
constexpr BindingNode(const char* name_, uint32_t hash_, atype::type type_) : name{name_}, hash{hash_}, type{type_} {}
const char* name;
uint32_t hash;
atype::type type;
};

Expand Down
3 changes: 1 addition & 2 deletions Framework/Core/include/Framework/GroupedCombinations.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ expressions::BindingNode getMatchingIndexNode()
using selected_indices_t = selected_pack_multicondition<is_index_to_g_t, pack<G>, external_index_columns_pack>;
static_assert(pack_size(selected_indices_t{}) == 1, "No matching index column from associated to grouping");
using index_column_t = pack_head_t<selected_indices_t>;
auto label = std::string(index_column_t::mLabel);
return expressions::BindingNode{label, typeid(typename index_column_t::column_t).hash_code(), expressions::selectArrowType<typename index_column_t::type>()};
return expressions::BindingNode{index_column_t::mLabel, o2::framework::TypeIdHelpers::uniqueId<typename index_column_t::column_t>(), expressions::selectArrowType<typename index_column_t::type>()};
}

template <typename T1, typename GroupingPolicy, typename BP, typename G, typename... As>
Expand Down
6 changes: 0 additions & 6 deletions Framework/Core/include/Framework/StringHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,4 @@ constexpr auto get_size(const std::string_view& str)
return const_str_details::as_chars<literal_to_chars>(); \
}()

template <typename T>
constexpr auto typeHash()
{
return compile_time_hash(typeid(T).name());
}

#endif // O2_FRAMEWORK_STRINGHELPERS_H
4 changes: 2 additions & 2 deletions Framework/Core/src/Expressions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
return tree;
}

bool isTableCompatible(std::set<size_t> const& hashes, Operations const& specs)
bool isTableCompatible(std::set<uint32_t> const& hashes, Operations const& specs)
{
std::set<size_t> opHashes;
std::set<uint32_t> opHashes;
for (auto const& spec : specs) {
if (spec.left.datum.index() == 3) {
opHashes.insert(spec.left.hash);
Expand Down
47 changes: 33 additions & 14 deletions Framework/Foundation/include/Framework/TypeIdHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

#include <string_view>
#include <sstream>
#include <source_location>
#include "Framework/StringHelpers.h"

namespace o2::framework
{

#ifdef __CLING__
template <typename T>
struct unique_type_id {
static constexpr auto get() noexcept
Expand All @@ -32,35 +33,53 @@ struct unique_type_id {

template <typename T>
inline constexpr auto unique_type_id_v = unique_type_id<T>::value;
#endif

struct TypeIdHelpers {
/// Return a unique id for a given type
/// This works just fine with GCC and CLANG,
/// C++20 will allow us to use:
/// std::source_location::current().function_name();
template <typename T>
constexpr static uint32_t uniqueId()
{
constexpr uint32_t r = crc32(unique_type_id_v<T>.data(), unique_type_id_v<T>.size());
return r;
}
};
#ifndef __CLING__
/// Workaround GCC optimizing out unused template parameter
template <typename T>
consteval static std::string_view type_name_impl(T*)
{
return std::source_location::current().function_name();
}
#endif

/// Return pure type name with no namespaces etc.
/// Works fine with GCC and CLANG
/// Works with GCC and CLANG
template <typename T>
constexpr static std::string_view type_name()
{
#ifdef __CLING__
constexpr std::string_view wrapped_name{unique_type_id_v<T>};
#else
constexpr std::string_view wrapped_name = type_name_impl<T>(nullptr);
#endif
const std::string_view left_marker{"T = "};
#ifdef __clang__
const std::string_view right_marker{"]"};
#else
const std::string_view right_marker{";"};
#endif
const auto left_marker_index = wrapped_name.find(left_marker);
const auto start_index = left_marker_index + left_marker.size();
const auto end_index = wrapped_name.find(right_marker, left_marker_index);
const auto length = end_index - start_index;
return wrapped_name.substr(start_index, length);
}

struct TypeIdHelpers {
template <typename T>
constexpr static uint32_t uniqueId()
{
#ifdef __CLING__
constexpr uint32_t r = crc32(unique_type_id_v<T>.data(), unique_type_id_v<T>.size());
return r;
#else
return compile_time_hash(type_name<T>().data());
#endif
}
};

/// Convert a CamelCase task struct name to snake-case task name
inline static std::string type_to_task_name(std::string_view& camelCase)
{
Expand Down

0 comments on commit 1c7eb18

Please sign in to comment.