Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Framework/Core/include/Framework/ConfigParamRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

#include "Framework/ConfigParamStore.h"
#include <boost/property_tree/ptree.hpp>
#include "Framework/Traits.h"

#include <concepts>
#include <cstdint>
#include <memory>
#include <string>
#include <cassert>
#include <type_traits>

template <typename T>
concept SimpleConfigValueType = std::same_as<T, int> ||
Expand All @@ -37,6 +34,13 @@ concept SimpleConfigValueType = std::same_as<T, int> ||
std::same_as<T, double> ||
std::same_as<T, bool>;

template <typename T>
concept VectorConfigValueType = std::same_as<T, std::vector<int>> ||
std::same_as<T, std::vector<float>> ||
std::same_as<T, std::vector<double>> ||
std::same_as<T, std::vector<std::string>> ||
std::same_as<T, std::vector<bool>>;

template <typename T>
concept StringConfigValueType = std::same_as<T, std::string>;

Expand All @@ -50,7 +54,7 @@ template <typename T>
concept LabeledArrayLike = requires(T& t) { t.is_labeled_array(); };

template <typename T>
concept ConfigValueType = SimpleConfigValueType<T> || StringConfigValueType<T> || o2::framework::base_of_template<std::vector, T> || Array2DLike<T> || LabeledArrayLike<T>;
concept ConfigValueType = SimpleConfigValueType<T> || StringConfigValueType<T> || VectorConfigValueType<T> || Array2DLike<T> || LabeledArrayLike<T>;

namespace o2::framework
{
Expand Down
49 changes: 15 additions & 34 deletions Framework/Core/include/Framework/TableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ auto makeHolders(arrow::MemoryPool* pool, size_t nRows)
template <typename... ARGS>
using IndexedHoldersTuple = decltype(makeHolderTypes<ARGS...>());

template <typename T>
concept ShouldNotDeconstruct = std::is_bounded_array_v<T> || std::is_arithmetic_v<T> || framework::is_base_of_template_v<std::vector, T>;

/// Helper class which creates a lambda suitable for building
/// an arrow table from a tuple. This can be used, for example
/// to build an arrow::Table from a TDataFrame.
Expand Down Expand Up @@ -662,21 +665,15 @@ class TableBuilder

public:
template <typename ARG0, typename... ARGS>
requires(sizeof...(ARGS) == 0)
requires(sizeof...(ARGS) == 0) && (!ShouldNotDeconstruct<ARG0>)
static constexpr int countColumns()
{
if constexpr (std::is_bounded_array_v<ARG0> == false &&
std::is_arithmetic_v<ARG0> == false &&
framework::is_base_of_template_v<std::vector, ARG0> == false) {
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
return framework::pack_size(argsPack_t{});
} else {
return 1;
}
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
return framework::pack_size(argsPack_t{});
}

template <typename ARG0, typename... ARGS>
requires(sizeof...(ARGS) > 0)
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
static constexpr int countColumns()
{
return 1 + sizeof...(ARGS);
Expand All @@ -698,7 +695,7 @@ class TableBuilder
/// Creates a lambda which is suitable to persist things
/// in an arrow::Table
template <typename ARG0, typename... ARGS>
requires(sizeof...(ARGS) > 0)
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
auto persist(std::array<char const*, sizeof...(ARGS) + 1> const& columnNames)
{
auto persister = persistTuple(framework::pack<ARG0, ARGS...>{}, columnNames);
Expand All @@ -711,31 +708,15 @@ class TableBuilder
// Special case for a single parameter to handle the serialization of struct
// which can be decomposed
template <typename ARG0, typename... ARGS>
requires(sizeof...(ARGS) == 0)
requires(sizeof...(ARGS) == 0) && (!ShouldNotDeconstruct<ARG0>)
auto persist(std::array<char const*, countColumns<ARG0, ARGS...>()> const& columnNames)
{
if constexpr (std::is_bounded_array_v<ARG0> == false &&
std::is_arithmetic_v<ARG0> == false &&
framework::is_base_of_template_v<std::vector, ARG0> == false) {
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
auto persister = persistTuple(argsPack_t{}, columnNames);
return [persister = persister](unsigned int slot, ARG0 const& obj) -> void {
auto t = to_tuple(obj);
persister(slot, t);
};
} else if constexpr ((std::is_bounded_array_v<ARG0> == true ||
framework::is_base_of_template_v<std::vector, ARG0> == true)) {
auto persister = persistTuple(framework::pack<ARG0>{}, columnNames);
// Callback used to fill the builders
return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const& arg) -> void {
persister(slot, std::forward_as_tuple(arg));
};
} else {
auto persister = persistTuple(framework::pack<ARG0>{}, columnNames);
return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const& arg) -> void {
persister(slot, std::forward_as_tuple(arg));
};
}
using argsPack_t = decltype(tuple_to_pack(framework::to_tuple(std::declval<ARG0>())));
auto persister = persistTuple(argsPack_t{}, columnNames);
return [persister = persister](unsigned int slot, ARG0 const& obj) -> void {
auto t = to_tuple(obj);
persister(slot, t);
};
}

/// Same a the above, but use a tuple to persist stuff.
Expand Down
2 changes: 1 addition & 1 deletion Framework/Core/src/ConfigParamRegistry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ T getImpl(boost::property_tree::ptree const& tree, const char* key)
}

template <typename T>
requires base_of_template<std::vector, T>
requires VectorConfigValueType<T>
auto getImpl(boost::property_tree::ptree const& tree, const char* key)
{
return o2::framework::vectorFromBranch<typename T::value_type>(tree.get_child(key));
Expand Down
Loading