16#ifndef ROOT_RDF_RMERGEABLEVALUE
17#define ROOT_RDF_RMERGEABLEVALUE
43template <
typename T,
typename... Ts>
47template <
typename T,
typename... Ts>
50template <
typename T,
typename... Ts>
146 template <
typename T1,
typename... Ts>
149 template <
typename T1,
typename... Ts>
214 this->
fValue += othercast.fValue;
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.");
379 const auto &othercast =
dynamic_cast<const RMergeableMean &
>(other);
380 const auto &othervalue = othercast.fValue;
381 const auto &othercounts = othercast.fCounts;
384 const auto num = this->
fValue *
fCounts + othervalue * othercounts;
388 this->
fValue = num / denum;
390 }
catch (
const std::bad_cast &) {
391 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
420 this->
fValue = std::min(this->fValue, othercast.
fValue);
421 }
catch (
const std::bad_cast &) {
422 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
477 const auto &othercounts = othercast.fCounts;
478 const auto &othermean = othercast.fMean;
482 const auto thisvariance = std::pow(this->
fValue, 2);
483 const auto othervariance = std::pow(othercast.fValue, 2);
485 const auto delta = othermean -
fMean;
487 const auto m_a = thisvariance * (
fCounts - 1);
488 const auto m_b = othervariance * (othercounts - 1);
492 const auto M2 = m_a + m_b + std::pow(delta, 2) *
fCounts * othercounts / sumcounts;
494 const auto meannum =
fMean *
fCounts + othermean * othercounts;
497 this->
fValue = std::sqrt(M2 / (sumcounts - 1));
498 fMean = meannum / sumcounts;
500 }
catch (
const std::bad_cast &) {
501 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
534 this->
fValue += othercast.fValue;
535 }
catch (
const std::bad_cast &) {
536 throw std::invalid_argument(
"Results from different actions cannot be merged together.");
573 for (
unsigned long i = 0; i <
fCutInfoVec.size(); i++) {
575 auto accumulated_pass = this->fCutInfoVec[i].GetPass() + othercast.fCutInfoVec[i].GetPass();
576 auto accumulated_all = this->fCutInfoVec[i].GetAll() + othercast.fCutInfoVec[i].GetAll();
581 if (this->fCutInfoVec[i].GetName() == othercast.fCutInfoVec[i].GetName()) {
583 report.
AddCut({this->fCutInfoVec[i].GetName(), accumulated_pass, accumulated_all});
585 throw std::runtime_error(
"Cutflow report with different cut names cannot be merged.");
625 std::vector<std::unique_ptr<RMergeableValueBase>>
fValues{};
679 template <
typename T1,
typename... Ts>
698 for (std::size_t i = 0; i <
fValues.size(); i++) {
738 auto it = std::find(std::begin(
fKeys), std::end(
fKeys), variationName);
739 if (it == std::end(
fKeys)) {
740 throw std::runtime_error(
"RMergeableVariations: no result with key \"" + variationName +
"\".");
742 auto pos = std::distance(std::begin(
fKeys), it);
754template <
class... Ts>
755using conjunction = std::is_same<bool_pack<
true, Ts::value...>, bool_pack<Ts::value...,
true>>;
780template <
typename T,
typename... Ts>
785 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
788 using expander =
int[];
790 (void)expander{0, (OutputMergeable->Merge(*InputMergeables), 0)...};
792 return OutputMergeable;
814template <
typename T,
typename... Ts>
818 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
821 using expander =
int[];
823 (void)expander{0, (OutputMergeable.
Merge(InputMergeables), 0)...};
848template <
typename T,
typename... Ts>
852 static_assert(conjunction<std::is_same<Ts, T>...>::value,
"Values must all be of the same type.");
855 using expander =
int[];
857 (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.
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...