12#ifndef FRAMEWORK_BINNINGPOLICY_H
13#define FRAMEWORK_BINNINGPOLICY_H
26namespace binning_helpers
31 int nBins =
static_cast<int>(
bins[0]);
33 expanded.resize(nBins + 2);
35 for (
int i = 0;
i <= nBins;
i++) {
42template <std::
size_t N>
46 static_assert(N <= 3,
"No default binning for more than 3 columns, you need to implement a binning class yourself");
47 for (
int i = 0;
i < N;
i++) {
52 template <
typename...
Ts>
55 static_assert(
sizeof...(Ts) == N,
"There must be the same number of binning axes and data values/columns");
57 unsigned int i = 2,
j = 2, k = 2;
60 if (std::get<0>(
data) < this->
mBins[0][1]) {
63 if constexpr (N > 1) {
64 if (std::get<1>(
data) < this->
mBins[1][1]) {
68 if constexpr (N > 2) {
69 if (std::get<2>(
data) < this->
mBins[2][1]) {
79 for (;
i < this->
mBins[0].size(); i++) {
82 if constexpr (N > 1) {
83 for (;
j < this->
mBins[1].size();
j++) {
86 if constexpr (N > 2) {
87 for (; k < this->
mBins[2].size(); k++) {
88 if (std::get<2>(
data) < this->
mBins[2][k]) {
89 return getBinAt(
i,
j, k);
98 return getBinAt(
i,
j, k);
107 if constexpr (N > 2) {
108 for (k = 2; k < this->
mBins[2].size(); k++) {
109 if (std::get<2>(
data) < this->
mBins[2][k]) {
110 return getBinAt(
i,
j, k);
117 return getBinAt(
i,
j, k);
127 if constexpr (N > 1) {
128 for (
j = 2;
j < this->
mBins[1].size();
j++) {
131 if constexpr (N > 2) {
132 for (k = 2; k < this->
mBins[2].size(); k++) {
133 if (std::get<2>(
data) < this->
mBins[2][k]) {
134 return getBinAt(
i,
j, k);
140 return getBinAt(
i,
j, k);
146 if constexpr (N > 2) {
147 for (k = 2; k < this->
mBins[2].size(); k++) {
148 if (std::get<2>(
data) < this->
mBins[2][k]) {
149 return getBinAt(
i,
j, k);
155 return getBinAt(
i,
j, k);
161 return getBinsCount(
mBins[0]);
167 if constexpr (N == 1) {
170 return getBinsCount(
mBins[1]);
176 if constexpr (N < 3) {
179 return getBinsCount(
mBins[2]);
185 if constexpr (N == 1) {
188 if constexpr (N == 2) {
191 if constexpr (N == 2) {
197 std::array<std::vector<double>, N>
mBins;
204 int getBinAt(
unsigned int iRaw,
unsigned int jRaw,
unsigned int kRaw)
const
206 int shiftBinsWithoutOverflow = getOverflowShift();
207 unsigned int i = iRaw - 1 - shiftBinsWithoutOverflow;
208 unsigned int j = jRaw - 1 - shiftBinsWithoutOverflow;
209 unsigned int k = kRaw - 1 - shiftBinsWithoutOverflow;
211 if constexpr (N == 1) {
213 }
else if constexpr (N == 2) {
214 return i +
j * xBinsCount;
215 }
else if constexpr (N == 3) {
222 int getOverflowShift()
const
228 int getBinsCount(std::vector<double>
const&
bins)
const
230 return bins.size() - 1 - getOverflowShift();
234template <
typename,
typename...>
237template <
typename...
Ts,
typename... Ls>
243 template <
typename T,
typename T2>
244 auto getBinningValue(T& rowIterator, arrow::Table* table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
247 if (globalIndex != -1) {
248 rowIterator.setCursor(globalIndex);
250 return std::get<T2>(mBinningFunctions)(rowIterator);
252 return soa::row_helpers::getSingleRowData<T, T2>(table, rowIterator, ci, ai, globalIndex);
256 template <
typename T>
257 auto getBinningValues(T& rowIterator, arrow::Table* table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
259 return std::make_tuple(getBinningValue<T, Ts>(rowIterator, table, ci, ai, globalIndex)...);
262 template <
typename T>
263 auto getBinningValues(
typename T::iterator rowIterator, T& table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
265 return getBinningValues(rowIterator, table.asArrowTable().get(), ci, ai, globalIndex);
268 template <
typename... T2s>
277 std::tuple<Ls...> mBinningFunctions;
280template <
typename...
Ts>
286 template <
typename T>
287 auto getBinningValues(T& rowIterator, arrow::Table* table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
289 return std::make_tuple(soa::row_helpers::getSingleRowData<T, Ts>(table, rowIterator, ci, ai, globalIndex)...);
292 template <
typename T>
293 auto getBinningValues(
typename T::iterator rowIterator, T& table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
295 return getBinningValues(rowIterator, table.asArrowTable().get(), ci, ai, globalIndex);
298 int getBin(std::tuple<typename Ts::type...>
const&
data)
const
311 template <
typename T>
312 auto getBinningValues(T& rowIterator, arrow::Table* table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
314 return std::make_tuple(soa::row_helpers::getSingleRowData<T, C>(table, rowIterator, ci, ai, globalIndex));
317 template <
typename T>
318 auto getBinningValues(
typename T::iterator rowIterator, T& table, uint64_t ci = -1, uint64_t ai = -1, uint64_t globalIndex = -1)
const
320 return getBinningValues(rowIterator, table.asArrowTable().get(), ci, ai, globalIndex);
325 return std::get<0>(
data);
void expandConstantBinning(std::vector< double > const &bins, std::vector< double > &expanded)
Defining PrimaryVertex explicitly as messageable.
std::decay_t< decltype(prune_voids_pack(pack<>{}, with_condition_pack< Condition, Types... >{}))> selected_pack
constexpr double VARIABLE_WIDTH
std::conditional_t< is_persistent_column< C >, std::true_type, std::false_type > is_persistent_column_t
Defining DataPointCompositeObject explicitly as copiable.
int getXBinsCount() const
int getBin(std::tuple< Ts... > const &data) const
int getYBinsCount() const
int getZBinsCount() const
BinningPolicyBase(std::array< std::vector< double >, N > bins, bool ignoreOverflows=true)
int getAllBinsCount() const
std::array< std::vector< double >, N > mBins
auto getBinningValues(T &rowIterator, arrow::Table *table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
auto getBinningValues(typename T::iterator rowIterator, T &table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
framework::selected_pack< o2::soa::is_persistent_column_t, Ts... > persistent_columns_t
ColumnBinningPolicy(std::array< std::vector< double >, sizeof...(Ts)> bins, bool ignoreOverflows=true)
int getBin(std::tuple< typename Ts::type... > const &data) const
auto getBinningValues(typename T::iterator rowIterator, T &table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
framework::selected_pack< o2::soa::is_persistent_column_t, Ts... > persistent_columns_t
auto getBinningValue(T &rowIterator, arrow::Table *table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
FlexibleBinningPolicy(std::tuple< Ls... > const &lambdaPtrs, std::array< std::vector< double >, sizeof...(Ts)> bins, bool ignoreOverflows=true)
int getBin(std::tuple< T2s... > const &data) const
auto getBinningValues(T &rowIterator, arrow::Table *table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
framework::selected_pack< o2::soa::is_persistent_column_t, C > persistent_columns_t
NoBinningPolicy()=default
auto getBinningValues(typename T::iterator rowIterator, T &table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
auto getBinningValues(T &rowIterator, arrow::Table *table, uint64_t ci=-1, uint64_t ai=-1, uint64_t globalIndex=-1) const
int getBin(std::tuple< typename C::type > const &data) const