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
13 changes: 6 additions & 7 deletions Framework/Core/include/Framework/AnalysisManagers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ struct GroupedCombinationManager {
}
};

template <typename T1, typename GroupingPolicy, typename H, typename G, typename... Us, typename... As>
struct GroupedCombinationManager<GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...>> {
template <typename TH, typename TG, typename... T2s>
static void setGroupedCombination(GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...>& comb, TH& hashes, TG& grouping, std::tuple<T2s...>& associated)
template <typename T1, typename GroupingPolicy, typename BP, typename G, typename... Us, typename... As>
struct GroupedCombinationManager<GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, pack<Us...>, As...>> {
template <typename TG, typename... T2s>
static void setGroupedCombination(GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, pack<Us...>, As...>& comb, TG& grouping, std::tuple<T2s...>& associated)
{
static_assert(sizeof...(T2s) > 0, "There must be associated tables in process() for a correct pair");
static_assert(!soa::is_soa_iterator_t<std::decay_t<H>>::value, "Only full tables can be in process(), no grouping");
if constexpr (std::is_same_v<G, TG> && std::is_same_v<H, TH>) {
if constexpr (std::is_same_v<G, TG>) {
// Take respective unique associated tables for grouping
auto associatedTuple = std::tuple<Us...>(std::get<Us>(associated)...);
comb.setTables(hashes, grouping, associatedTuple);
comb.setTables(grouping, associatedTuple);
}
}
};
Expand Down
6 changes: 2 additions & 4 deletions Framework/Core/include/Framework/AnalysisTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ struct AnalysisDataProcessorBuilder {
associatedTables);

// GroupedCombinations bound separately, as they should be set once for all associated tables
auto hashes = std::get<0>(associatedTables);
auto realAssociated = tuple_tail(associatedTables);
homogeneous_apply_refs([&groupingTable, &hashes, &realAssociated](auto& t) {
GroupedCombinationManager<std::decay_t<decltype(t)>>::setGroupedCombination(t, hashes, groupingTable, realAssociated);
homogeneous_apply_refs([&groupingTable, &associatedTables](auto& t) {
GroupedCombinationManager<std::decay_t<decltype(t)>>::setGroupedCombination(t, groupingTable, associatedTables);
return true;
},
task);
Expand Down
51 changes: 23 additions & 28 deletions Framework/Core/include/Framework/GroupedCombinations.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define FRAMEWORK_GROUPEDCOMBINATIONS_H

#include "Framework/ASoAHelpers.h"
#include "Framework/BinningPolicy.h"
#include "Framework/GroupSlicer.h"
#include "Framework/Pack.h"
#include <optional>
Expand Down Expand Up @@ -52,14 +53,13 @@ auto functionToTuple(R (C::*f)(Args...), C& obj, Args... args)
return functionToTupleImpl(f, obj, args..., std::make_index_sequence<N>());
}

template <typename T1, typename GroupingPolicy, typename H, typename G, typename... Ts>
template <typename T1, typename GroupingPolicy, typename BP, typename G, typename... Ts>
struct GroupedCombinationsGenerator {
};

template <typename T1, typename GroupingPolicy, typename H, typename G, typename... Us, typename... As>
struct GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...> {
using joinIterator = typename soa::Join<H, G>::table_t::iterator;
using GroupedIteratorType = pack_to_tuple_t<interleaved_pack_t<repeated_type_pack_t<joinIterator, sizeof...(As)>, pack<As...>>>;
template <typename T1, typename GroupingPolicy, typename BP, typename G, typename... Us, typename... As>
struct GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, pack<Us...>, As...> {
using GroupedIteratorType = pack_to_tuple_t<interleaved_pack_t<repeated_type_pack_t<typename G::iterator, sizeof...(As)>, pack<As...>>>;

struct GroupedIterator : public GroupingPolicy {
public:
Expand All @@ -69,9 +69,9 @@ struct GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...
using iterator_category = std::forward_iterator_tag;

GroupedIterator(const GroupingPolicy& groupingPolicy) : GroupingPolicy(groupingPolicy) {}
GroupedIterator(const GroupingPolicy& groupingPolicy, const H& hashes, const G& grouping, const std::shared_ptr<GroupSlicer<G, Us...>>&& slicer_ptr) : GroupingPolicy(groupingPolicy), mSlicer{std::move(slicer_ptr)}, mGrouping{std::make_shared<G>(std::vector{grouping.asArrowTable()})}
GroupedIterator(const GroupingPolicy& groupingPolicy, const G& grouping, const std::shared_ptr<GroupSlicer<G, Us...>>&& slicer_ptr) : GroupingPolicy(groupingPolicy), mSlicer{std::move(slicer_ptr)}, mGrouping{std::make_shared<G>(std::vector{grouping.asArrowTable()})}
{
GroupingPolicy::setTables(join(hashes, grouping), join(hashes, grouping));
setMultipleGroupingTables<sizeof...(As)>(grouping);
if (!this->mIsEnd) {
setCurrentGroupedCombination();
}
Expand All @@ -81,11 +81,11 @@ struct GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...
GroupedIterator& operator=(GroupedIterator const&) = default;
~GroupedIterator() = default;

void setTables(const H& hashes, const G& grouping, std::shared_ptr<GroupSlicer<G, Us...>> slicer_ptr)
void setTables(const G& grouping, std::shared_ptr<GroupSlicer<G, Us...>> slicer_ptr)
{
mGrouping = std::make_shared<G>(std::vector{grouping.asArrowTable()});
mSlicer = slicer_ptr;
setMultipleGroupingTables<sizeof...(As)>(join(hashes, grouping));
setMultipleGroupingTables<sizeof...(As)>(grouping);
if (!this->mIsEnd) {
setCurrentGroupedCombination();
}
Expand Down Expand Up @@ -226,48 +226,43 @@ struct GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<Us...>, As...
return iterator(mEnd);
}

GroupedCombinationsGenerator(const char* category, int catNeighbours, const T1& outsider) : mBegin(GroupingPolicy(category, catNeighbours, outsider)), mEnd(GroupingPolicy(category, catNeighbours, outsider)), mCategory(category), mCatNeighbours(catNeighbours), mOutsider(outsider) {}
GroupedCombinationsGenerator(const char* category, int catNeighbours, const T1& outsider, H& hashes, G& grouping, std::tuple<Us...>& associated) : GroupedCombinationsGenerator(category, catNeighbours, outsider)
GroupedCombinationsGenerator(const BP& binningPolicy, int catNeighbours, const T1& outsider) : mBegin(GroupingPolicy(binningPolicy, catNeighbours, outsider)), mEnd(GroupingPolicy(binningPolicy, catNeighbours, outsider)) {}
GroupedCombinationsGenerator(const BP& binningPolicy, int catNeighbours, const T1& outsider, G& grouping, std::tuple<Us...>& associated) : GroupedCombinationsGenerator(binningPolicy, catNeighbours, outsider)
{
setTables(hashes, grouping, associated);
setTables(grouping, associated);
}
GroupedCombinationsGenerator(GroupedCombinationsGenerator const&) = default;
GroupedCombinationsGenerator& operator=(GroupedCombinationsGenerator const&) = default;
~GroupedCombinationsGenerator() = default;

void setTables(H& hashes, G& grouping, std::tuple<Us...>& associated)
void setTables(G& grouping, std::tuple<Us...>& associated)
{
if (mSlicer == nullptr) {
mSlicer = std::make_shared<GroupSlicer<G, Us...>>(grouping, associated);
mBegin.setTables(hashes, grouping, mSlicer);
mEnd.setTables(hashes, grouping, mSlicer);
mBegin.setTables(grouping, mSlicer);
mEnd.setTables(grouping, mSlicer);
mEnd.moveToEnd();
}
}

private:
iterator mBegin;
iterator mEnd;
const char* mCategory;
const int mCatNeighbours;
const T1 mOutsider;
std::shared_ptr<GroupSlicer<G, Us...>> mSlicer = nullptr;
};

// Aliases for 2-particle correlations
// 'Pair' and 'Triple' can be used for same kind pair/triple, too, just specify the same type twice
template <typename H, typename G>
using joinedCollisions = typename soa::Join<H, G>::table_t;
template <typename H, typename G, typename A1, typename A2, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, joinedCollisions<H, G>, joinedCollisions<H, G>>>
using Pair = GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, unique_pack_t<pack<A1, A2>>, A1, A2>;
template <typename H, typename G, typename A, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, joinedCollisions<H, G>, joinedCollisions<H, G>>>
using SameKindPair = GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<A>, A, A>;
template <typename G, typename A1, typename A2, typename BP, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, G, G>>
using Pair = GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, unique_pack_t<pack<A1, A2>>, A1, A2>;
template <typename G, typename A, typename BP, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, G, G>>
using SameKindPair = GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, pack<A>, A, A>;

// Aliases for 3-particle correlations
template <typename H, typename G, typename A1, typename A2, typename A3, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, joinedCollisions<H, G>, joinedCollisions<H, G>, joinedCollisions<H, G>>>
using Triple = GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, unique_pack_t<pack<A1, A2, A3>>, A1, A2, A3>;
template <typename H, typename G, typename A, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, joinedCollisions<H, G>, joinedCollisions<H, G>, joinedCollisions<H, G>>>
using SameKindTriple = GroupedCombinationsGenerator<T1, GroupingPolicy, H, G, pack<A>, A, A, A>;
template <typename G, typename A1, typename A2, typename A3, typename BP, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, G, G, G>>
using Triple = GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, unique_pack_t<pack<A1, A2, A3>>, A1, A2, A3>;
template <typename G, typename A, typename BP, typename T1 = int, typename GroupingPolicy = o2::soa::CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, G, G, G>>
using SameKindTriple = GroupedCombinationsGenerator<T1, GroupingPolicy, BP, G, pack<A>, A, A, A>;

} // namespace o2::framework
#endif // FRAMEWORK_GROUPEDCOMBINATIONS_H_