17#ifndef ROOT_RDF_RMERGEABLEVALUE
18#define ROOT_RDF_RMERGEABLEVALUE
35template <
typename T,
typename... Ts>
36std::unique_ptr<RMergeableValue<T>>
MergeValues(std::unique_ptr<RMergeableValue<T>> OutputMergeable,
37 std::unique_ptr<RMergeableValue<Ts>>... InputMergeables);
39template <
typename T,
typename... Ts>
40void MergeValues(RMergeableValue<T> &OutputMergeable,
const RMergeableValue<Ts> &... InputMergeables);
131 template <
typename T1,
typename... Ts>
134 template <
typename T1,
typename... Ts>
197 }
catch (
const std::bad_cast &) {
198 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
239 template <typename U, std::enable_if_t<std::is_base_of<TObject, U>::value,
int> = 0>
244 l.
Add(
const_cast<U *
>(&other.fValue));
249 template <
typename U>
251 ->
decltype(this->
fValue.Merge(std::vector<U *>{}),
void())
253 this->
fValue.Merge({
const_cast<U *
>(&other.fValue)});
276 }
catch (
const std::bad_cast &) {
277 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
303 this->
fValue = std::max(this->fValue, othercast.
fValue);
304 }
catch (
const std::bad_cast &) {
305 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
356 const auto &othercast =
dynamic_cast<const RMergeableMean &
>(other);
357 const auto &othervalue = othercast.
fValue;
358 const auto &othercounts = othercast.fCounts;
361 const auto num = this->
fValue * fCounts + othervalue * othercounts;
365 this->
fValue = num / denum;
367 }
catch (
const std::bad_cast &) {
368 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
395 this->
fValue = std::min(this->fValue, othercast.
fValue);
396 }
catch (
const std::bad_cast &) {
397 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
451 const auto &othercounts = othercast.
fCounts;
452 const auto &othermean = othercast.fMean;
456 const auto thisvariance = std::pow(this->
fValue, 2);
457 const auto othervariance = std::pow(othercast.fValue, 2);
459 const auto delta = othermean -
fMean;
461 const auto m_a = thisvariance * (
fCounts - 1);
462 const auto m_b = othervariance * (othercounts - 1);
466 const auto M2 = m_a + m_b + std::pow(delta, 2) *
fCounts * othercounts / sumcounts;
468 const auto meannum =
fMean *
fCounts + othermean * othercounts;
471 this->
fValue = std::sqrt(M2 / (sumcounts - 1));
472 fMean = meannum / sumcounts;
474 }
catch (
const std::bad_cast &) {
475 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
507 }
catch (
const std::bad_cast &) {
508 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
533template <
class... Ts>
534using conjunction = std::is_same<bool_pack<
true, Ts::value...>, bool_pack<Ts::value...,
true>>;
559template <
typename T,
typename... Ts>
564 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
567 using expander =
int[];
569 (
void)expander{0, (OutputMergeable->Merge(*InputMergeables), 0)...};
571 return OutputMergeable;
593template <
typename T,
typename... Ts>
597 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
600 using expander =
int[];
602 (
void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
unsigned long long ULong64_t
Specialization of RMergeableValue for the Count action.
RMergeableCount(const RMergeableCount &)=delete
void Merge(const RMergeableValue< ULong64_t > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableCount()=default
Default constructor.
RMergeableCount(ULong64_t value)
Constructor that initializes data members.
RMergeableCount(RMergeableCount &&)=default
Specialization of RMergeableValue for histograms and statistics.
RMergeableFill(RMergeableFill &&)=default
auto DoMerge(const RMergeableFill< U > &other, double) -> decltype(this->fValue.Merge(std::vector< U * >{}), void())
auto DoMerge(const RMergeableFill< U > &other, int) -> decltype(((U &) this->fValue).Merge((TCollection *) nullptr), void())
RMergeableFill()=default
Default constructor.
RMergeableFill(const T &value)
Constructor that initializes data members.
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableFill(const RMergeableFill &)=delete
RMergeableMax(RMergeableMax &&)=default
RMergeableMax(const T &value)
Constructor that initializes data members.
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableMax()=default
Default constructor.
RMergeableMax(const RMergeableMax &)=delete
Specialization of RMergeableValue for the Mean action.
RMergeableMean(Double_t value, ULong64_t counts)
Constructor that initializes data members.
RMergeableMean(const RMergeableMean &)=delete
ULong64_t fCounts
The number of entries used to compute the mean.
RMergeableMean(RMergeableMean &&)=default
RMergeableMean()=default
Default constructor.
void Merge(const RMergeableValue< Double_t > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableMin()=default
Default constructor.
RMergeableMin(const RMergeableMin &)=delete
RMergeableMin(const T &value)
Constructor that initializes data members.
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableMin(RMergeableMin &&)=default
Specialization of RMergeableValue for the StdDev action.
RMergeableStdDev(Double_t value, ULong64_t counts, Double_t mean)
Constructor that initializes data members.
void Merge(const RMergeableValue< Double_t > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableStdDev(const RMergeableStdDev &)=delete
ULong64_t fCounts
Number of entries of the set.
Double_t fMean
Average of the set.
RMergeableStdDev()=default
Default constructor.
RMergeableStdDev(RMergeableStdDev &&)=default
RMergeableSum()=default
Default constructor.
RMergeableSum(const T &value)
Constructor that initializes data members.
RMergeableSum(const RMergeableSum &)=delete
RMergeableSum(RMergeableSum &&)=default
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
Base class of RMergeableValue.
RMergeableValueBase()=default
Default constructor.
virtual ~RMergeableValueBase()=default
A result of an RDataFrame execution, that knows how to merge with other results of the same type.
RMergeableValue()=default
Default constructor.
const T & GetValue() const
Retrieve the result wrapped by this mergeable.
friend void MergeValues(RMergeableValue< T1 > &OutputMergeable, const RMergeableValue< Ts > &... InputMergeables)
friend std::unique_ptr< RMergeableValue< T1 > > MergeValues(std::unique_ptr< RMergeableValue< T1 > > OutputMergeable, std::unique_ptr< RMergeableValue< Ts > >... InputMergeables)
RMergeableValue(const T &value)
Constructor taking the action result by const reference.
virtual void Merge(const RMergeableValue< T > &)=0
Aggregate the information contained in another RMergeableValue into this.
Collection abstract base class.
virtual void Add(TObject *obj)
std::unique_ptr< RMergeableValue< T > > MergeValues(std::unique_ptr< RMergeableValue< T > > OutputMergeable, std::unique_ptr< RMergeableValue< Ts > >... InputMergeables)
Merge multiple RMergeableValue objects into one.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...