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.");
254 l.
Add(
const_cast<T *
>(&(othercast.fValue)));
256 }
catch (
const std::bad_cast &) {
257 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
283 this->
fValue = std::max(this->fValue, othercast.
fValue);
284 }
catch (
const std::bad_cast &) {
285 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
336 const auto &othercast =
dynamic_cast<const RMergeableMean &
>(other);
337 const auto &othervalue = othercast.
fValue;
338 const auto &othercounts = othercast.fCounts;
341 const auto num = this->
fValue * fCounts + othervalue * othercounts;
345 this->
fValue = num / denum;
347 }
catch (
const std::bad_cast &) {
348 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
375 this->
fValue = std::min(this->fValue, othercast.
fValue);
376 }
catch (
const std::bad_cast &) {
377 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
431 const auto &othercounts = othercast.
fCounts;
432 const auto &othermean = othercast.fMean;
436 const auto thisvariance = std::pow(this->
fValue, 2);
437 const auto othervariance = std::pow(othercast.fValue, 2);
439 const auto delta = othermean -
fMean;
441 const auto m_a = thisvariance * (
fCounts - 1);
442 const auto m_b = othervariance * (othercounts - 1);
446 const auto M2 = m_a + m_b + std::pow(delta, 2) *
fCounts * othercounts / sumcounts;
448 const auto meannum =
fMean *
fCounts + othermean * othercounts;
451 this->
fValue = std::sqrt(M2 / (sumcounts - 1));
452 fMean = meannum / sumcounts;
454 }
catch (
const std::bad_cast &) {
455 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
487 }
catch (
const std::bad_cast &) {
488 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
513template <
class... Ts>
514using conjunction = std::is_same<bool_pack<
true, Ts::value...>, bool_pack<Ts::value...,
true>>;
539template <
typename T,
typename... Ts>
544 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
547 using expander =
int[];
549 (
void)expander{0, (OutputMergeable->Merge(*InputMergeables), 0)...};
551 return OutputMergeable;
573template <
typename T,
typename... Ts>
577 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
580 using expander =
int[];
582 (
void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
unsigned long long ULong64_t
typedef void((*Func_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
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.
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...