17#ifndef ROOT_RDF_RMERGEABLEVALUE
18#define ROOT_RDF_RMERGEABLEVALUE
44template <
typename T,
typename... Ts>
48template <
typename T,
typename... Ts>
51template <
typename T,
typename... Ts>
148 template <
typename T1,
typename... Ts>
151 template <
typename T1,
typename... Ts>
217 this->
fValue += othercast.fValue;
218 }
catch (
const std::bad_cast &) {
219 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
263 template <typename U, std::enable_if_t<std::is_base_of<TObject, U>::value,
int> = 0>
268 l.Add(
const_cast<U *
>(&other.fValue));
273 template <
typename U>
275 ->
decltype(this->
fValue.Merge(std::vector<U *>{}), void())
277 this->
fValue.Merge({
const_cast<U *
>(&other.fValue)});
300 }
catch (
const std::bad_cast &) {
301 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
329 this->
fValue = std::max(this->fValue, othercast.
fValue);
330 }
catch (
const std::bad_cast &) {
331 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
384 const auto &othercast =
dynamic_cast<const RMergeableMean &
>(other);
385 const auto &othervalue = othercast.fValue;
386 const auto &othercounts = othercast.fCounts;
389 const auto num = this->
fValue *
fCounts + othervalue * othercounts;
393 this->
fValue = num / denum;
395 }
catch (
const std::bad_cast &) {
396 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
425 this->
fValue = std::min(this->fValue, othercast.
fValue);
426 }
catch (
const std::bad_cast &) {
427 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
483 const auto &othercounts = othercast.fCounts;
484 const auto &othermean = othercast.fMean;
488 const auto thisvariance = std::pow(this->
fValue, 2);
489 const auto othervariance = std::pow(othercast.fValue, 2);
491 const auto delta = othermean -
fMean;
493 const auto m_a = thisvariance * (
fCounts - 1);
494 const auto m_b = othervariance * (othercounts - 1);
498 const auto M2 = m_a + m_b + std::pow(delta, 2) *
fCounts * othercounts / sumcounts;
500 const auto meannum =
fMean *
fCounts + othermean * othercounts;
503 this->
fValue = std::sqrt(M2 / (sumcounts - 1));
504 fMean = meannum / sumcounts;
506 }
catch (
const std::bad_cast &) {
507 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
540 this->
fValue += othercast.fValue;
541 }
catch (
const std::bad_cast &) {
542 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
580 for (
unsigned long i = 0; i <
fCutInfoVec.size(); i++) {
582 auto accumulated_pass = this->fCutInfoVec[i].GetPass() + othercast.fCutInfoVec[i].GetPass();
583 auto accumulated_all = this->fCutInfoVec[i].GetAll() + othercast.fCutInfoVec[i].GetAll();
588 if (this->fCutInfoVec[i].GetName() == othercast.fCutInfoVec[i].GetName()) {
590 report.
AddCut({this->fCutInfoVec[i].GetName(), accumulated_pass, accumulated_all});
592 throw std::runtime_error(
"Cutflow report with different cut names cannot be merged.");
633 std::vector<std::unique_ptr<RMergeableValueBase>>
fValues{};
688 template <
typename T1,
typename... Ts>
707 for (std::size_t i = 0; i <
fValues.size(); i++) {
747 auto it = std::find(std::begin(
fKeys), std::end(
fKeys), variationName);
748 if (it == std::end(
fKeys)) {
749 throw std::runtime_error(
"RMergeableVariations: no result with key \"" + variationName +
"\".");
751 auto pos = std::distance(std::begin(
fKeys), it);
763template <
class... Ts>
764using conjunction = std::is_same<bool_pack<
true, Ts::value...>, bool_pack<Ts::value...,
true>>;
789template <
typename T,
typename... Ts>
794 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
797 using expander =
int[];
799 (void)expander{0, (OutputMergeable->Merge(*InputMergeables), 0)...};
801 return OutputMergeable;
823template <
typename T,
typename... Ts>
827 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
830 using expander =
int[];
832 (void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
857template <
typename T,
typename... Ts>
861 static_assert(conjunction<std::is_same<Ts, T>...>
::value,
"Values must all be of the same type.");
864 using expander =
int[];
866 (void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
Basic types used by ROOT and required by TInterpreter.
double Double_t
Double 8 bytes.
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
#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
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
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
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
RMergeableReport & operator=(const RMergeableReport &)=delete
RMergeableReport()=default
Default constructor.
RMergeableReport(ROOT::RDF::RCutFlowReport value, std::vector< ROOT::RDF::TCutInfo > cutinfovec)
Constructor that initializes data members.
std::vector< ROOT::RDF::TCutInfo > fCutInfoVec
RMergeableReport(const RMergeableReport &)=delete
void Merge(const RMergeableValue< ROOT::RDF::RCutFlowReport > &other) final
Aggregate the information contained in another RMergeableValue into this.
RMergeableReport & operator=(RMergeableReport &&)=delete
RMergeableReport(RMergeableReport &&)=delete
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
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
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
void AddCut(TCutInfo &&ci)
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.
Special implementation of ROOT::RRangeCast for TCollection, including a check that the cast target ty...