17#ifndef ROOT_RDF_RMERGEABLEVALUE
18#define ROOT_RDF_RMERGEABLEVALUE
40class RMergeableVariations;
42template <
typename T,
typename... Ts>
43std::unique_ptr<RMergeableValue<T>>
MergeValues(std::unique_ptr<RMergeableValue<T>> OutputMergeable,
44 std::unique_ptr<RMergeableValue<Ts>>... InputMergeables);
46template <
typename T,
typename... Ts>
47void MergeValues(RMergeableValue<T> &OutputMergeable,
const RMergeableValue<Ts> &... InputMergeables);
49template <
typename T,
typename... Ts>
50void MergeValues(RMergeableVariations<T> &OutputMergeable,
const RMergeableVariations<Ts> &... InputMergeables);
145 template <
typename T1,
typename... Ts>
148 template <
typename T1,
typename... Ts>
215 }
catch (
const std::bad_cast &) {
216 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
259 template <typename U, std::enable_if_t<std::is_base_of<TObject, U>::value,
int> = 0>
264 l.Add(
const_cast<U *
>(&other.fValue));
269 template <
typename U>
271 ->
decltype(this->
fValue.Merge(std::vector<U *>{}),
void())
273 this->
fValue.Merge({
const_cast<U *
>(&other.fValue)});
296 }
catch (
const std::bad_cast &) {
297 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
325 this->
fValue = std::max(this->fValue, othercast.
fValue);
326 }
catch (
const std::bad_cast &) {
327 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
380 const auto &othercast =
dynamic_cast<const RMergeableMean &
>(other);
381 const auto &othervalue = othercast.
fValue;
382 const auto &othercounts = othercast.fCounts;
385 const auto num = this->
fValue * fCounts + othervalue * othercounts;
389 this->
fValue = num / denum;
391 }
catch (
const std::bad_cast &) {
392 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
421 this->
fValue = std::min(this->fValue, othercast.
fValue);
422 }
catch (
const std::bad_cast &) {
423 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
479 const auto &othercounts = othercast.
fCounts;
480 const auto &othermean = othercast.fMean;
484 const auto thisvariance = std::pow(this->
fValue, 2);
485 const auto othervariance = std::pow(othercast.fValue, 2);
487 const auto delta = othermean -
fMean;
489 const auto m_a = thisvariance * (
fCounts - 1);
490 const auto m_b = othervariance * (othercounts - 1);
494 const auto M2 = m_a + m_b + std::pow(delta, 2) *
fCounts * othercounts / sumcounts;
496 const auto meannum =
fMean *
fCounts + othermean * othercounts;
499 this->
fValue = std::sqrt(M2 / (sumcounts - 1));
500 fMean = meannum / sumcounts;
502 }
catch (
const std::bad_cast &) {
503 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
537 }
catch (
const std::bad_cast &) {
538 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
572 std::vector<std::unique_ptr<RMergeableValueBase>>
fValues{};
627 template <
typename T1,
typename... Ts>
646 for (std::size_t i = 0; i <
fValues.size(); i++) {
686 auto it = std::find(std::begin(
fKeys), std::end(
fKeys), variationName);
687 if (it == std::end(
fKeys)) {
688 throw std::runtime_error(
"RMergeableVariations: no result with key \"" + variationName +
"\".");
690 auto pos = std::distance(std::begin(
fKeys), it);
702template <
class... Ts>
703using conjunction = std::is_same<bool_pack<
true, Ts::value...>, bool_pack<Ts::value...,
true>>;
728template <
typename T,
typename... Ts>
733 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
736 using expander =
int[];
738 (void)expander{0, (OutputMergeable->Merge(*InputMergeables), 0)...};
740 return OutputMergeable;
762template <
typename T,
typename... Ts>
766 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
769 using expander =
int[];
771 (void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
796template <
typename T,
typename... Ts>
800 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
803 using expander =
int[];
805 (void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
unsigned long long ULong64_t
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 & operator=(RMergeableCount &&)=delete
RMergeableCount(RMergeableCount &&)=delete
RMergeableCount & operator=(const RMergeableCount &)=delete
Specialization of RMergeableValue for histograms and statistics.
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(RMergeableFill &&)=delete
RMergeableFill(const T &value)
Constructor that initializes data members.
RMergeableFill & operator=(RMergeableFill &&)=delete
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableFill & operator=(const RMergeableFill &)=delete
RMergeableFill(const RMergeableFill &)=delete
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 & operator=(const RMergeableMax &)=delete
RMergeableMax(RMergeableMax &&)=delete
RMergeableMax & operator=(RMergeableMax &&)=delete
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()=default
Default constructor.
RMergeableMean & operator=(const RMergeableMean &)=delete
void Merge(const RMergeableValue< Double_t > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableMean(RMergeableMean &&)=delete
RMergeableMean & operator=(RMergeableMean &&)=delete
RMergeableMin()=default
Default constructor.
RMergeableMin(RMergeableMin &&)=delete
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 & operator=(const RMergeableMin &)=delete
RMergeableMin & operator=(RMergeableMin &&)=delete
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
RMergeableStdDev & operator=(RMergeableStdDev &&)=delete
ULong64_t fCounts
Number of entries of the set.
RMergeableStdDev(RMergeableStdDev &&)=delete
Double_t fMean
Average of the set.
RMergeableStdDev & operator=(const RMergeableStdDev &)=delete
RMergeableStdDev()=default
Default constructor.
RMergeableSum()=default
Default constructor.
RMergeableSum(const T &value)
Constructor that initializes data members.
RMergeableSum(const RMergeableSum &)=delete
RMergeableSum & operator=(RMergeableSum &&)=delete
RMergeableSum(RMergeableSum &&)=delete
void Merge(const RMergeableValue< T > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableSum & operator=(const RMergeableSum &)=delete
Base class of RMergeableValue.
RMergeableValueBase()=default
Default constructor.
RMergeableValueBase(RMergeableValueBase &&)=delete
RMergeableValueBase & operator=(RMergeableValueBase &&)=delete
virtual ~RMergeableValueBase()=default
RMergeableValueBase & operator=(const RMergeableValueBase &)=delete
RMergeableValueBase(const RMergeableValueBase &)=delete
A result of an RDataFrame execution, that knows how to merge with other results of the same type.
RMergeableValue()=default
Default constructor.
RMergeableValue(const RMergeableValue &)=delete
RMergeableValue(RMergeableValue &&)=delete
const T & GetValue() const
Retrieve the result wrapped by this mergeable.
RMergeableValue & operator=(const RMergeableValue &)=delete
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.
RMergeableValue & operator=(RMergeableValue &&)=delete
A container for variation names and variation results.
RMergeableVariationsBase()=default
Default constructor.
RMergeableVariationsBase & operator=(RMergeableVariationsBase &&)=delete
std::vector< std::unique_ptr< RMergeableValueBase > > fValues
RMergeableVariationsBase(std::vector< std::string > &&keys, std::vector< std::unique_ptr< RMergeableValueBase > > &&values)
Constructor that initializes data members.
~RMergeableVariationsBase() override=default
void AddNominal(std::unique_ptr< RMergeableValueBase > value)
Add an entry for the "nominal" value.
std::vector< std::string > fKeys
RMergeableVariationsBase & operator=(const RMergeableVariationsBase &)=delete
RMergeableVariationsBase(const RMergeableVariationsBase &)=delete
RMergeableVariationsBase(RMergeableVariationsBase &&other)
Constructor that moves the data members from the input object.
A container for variation names and variation results that knows how to merge with others of the same...
void Merge(const RMergeableVariations< T > &other)
Aggregate the information contained in another RMergeableVariations into this.
const T & GetVariation(const std::string &variationName) const
Get the final value from the mergeable corresponding to a certain variation name.
RMergeableVariations & operator=(const RMergeableVariations &)=delete
~RMergeableVariations() final=default
RMergeableVariations()=default
Default constructor.
RMergeableVariations & operator=(RMergeableVariations &&)=delete
const std::vector< std::string > & GetKeys() const
Get the list of variation names.
RMergeableVariations(RMergeableVariations &&)=delete
friend void MergeValues(RMergeableVariations< T1 > &OutputMergeable, const RMergeableVariations< Ts > &... InputMergeables)
RMergeableVariations(const RMergeableVariations &)=delete
Collection abstract base class.
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...