19#ifndef ROOT_RDFOPERATIONS
20#define ROOT_RDFOPERATIONS
35#include "RConfigure.h"
81using Results = std::conditional_t<std::is_same<T, bool>::value, std::deque<T>, std::vector<T>>;
95 template <
typename... Args>
96 void Exec(
unsigned int slot, Args &&... args)
99 static_assert(std::is_same<TypeList<std::decay_t<Args>...>, ColumnTypes_t>
::value,
"");
107 std::string GetActionName() {
return "ForeachSlot"; }
127 return std::make_unique<RMergeableCount>(*
fResultCount);
132 std::string GetActionName() {
return "Count"; }
141template <
typename RNode_t>
143 std::shared_ptr<RCutFlowReport>
fReport;
156 void Exec(
unsigned int ) {}
164 std::string GetActionName() {
return "Report"; }
168 auto &&
result = *
static_cast<std::shared_ptr<RCutFlowReport> *
>(
newResult);
170 std::static_pointer_cast<RNode_t>(fNode->GetVariedFilter(std::string(
variation))).get(),
186 using Buf_t = std::vector<BufEl_t>;
188 std::vector<Buf_t> fBuffers;
191 unsigned int fNSlots;
192 unsigned int fBufSize;
206 void Exec(
unsigned int slot,
double v,
double w);
220 void Exec(
unsigned int slot,
const T &
vs,
const W &ws)
249 void Exec(
unsigned int slot,
const T
v,
const W &ws)
259 Hist_t &PartialUpdate(
unsigned int);
268 return std::make_unique<RMergeableFill<Hist_t>>(*fResultHist);
271 std::string GetActionName()
280 result->SetDirectory(
nullptr);
291 using iterator_category = std::forward_iterator_tag;
292 using difference_type = std::ptrdiff_t;
293 using value_type = T;
295 using reference = T &;
305 if constexpr (IsDataContainer<T>::value) {
306 return std::begin(val);
314std::size_t GetSize(
const T &val)
316 if constexpr (IsDataContainer<T>::value) {
317 return std::size(val);
338template <
typename HIST = Hist_t>
340 std::vector<HIST *> fObjects;
344 auto Merge(std::vector<H *> &
objs,
int )
354 template <
typename H>
355 auto Merge(std::vector<H *> &
objs,
double )
356 ->
decltype(
objs[0]->Merge(std::vector<HIST *>{}),
void())
362 template <
typename T>
365 static_assert(
sizeof(T) < 0,
366 "The type passed to Fill does not provide a Merge(TCollection*) or Merge(const std::vector&) method.");
369 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
383 fObjects[0] =
h.get();
385 for (
unsigned int i = 1; i <
nSlots; ++i) {
386 fObjects[i] =
new HIST(*fObjects[0]);
394 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
397 fObjects[
slot]->Fill(
x...);
401 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
405 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
410 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
416 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
418 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
420 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
427 template <
typename T = HIST>
430 static_assert(
sizeof(T) < 0,
431 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
432 "columns passed did not match the signature of the object's `Fill` method.");
439 if (fObjects.size() == 1)
445 for (
auto it = ++fObjects.begin(); it != fObjects.end(); ++it)
449 HIST &PartialUpdate(
unsigned int slot) {
return *fObjects[
slot]; }
454 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
459 std::string GetActionName()
461 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
466 std::string GetActionName()
468 return "Fill custom object";
471 template <
typename H = HIST>
482template <
typename BinContentType,
bool WithWeight = false>
489 std::unique_ptr<ROOT::Experimental::RHistConcurrentFiller<BinContentType>>
fFiller;
490 std::vector<std::shared_ptr<ROOT::Experimental::RHistFillContext<BinContentType>>> fContexts;
496 for (
unsigned int i = 0; i <
nSlots; i++) {
497 fContexts[i] =
fFiller->CreateFillContext();
506 std::shared_ptr<Result_t> GetResultPtr()
const {
return fFiller.GetHist(); }
511 template <
typename...
ColumnTypes,
const std::size_t...
I>
518 fContexts[
slot]->Fill(args, weight);
534 for (
auto &&context : fContexts) {
539 std::string GetActionName() {
return "Hist"; }
542template <
typename BinContentType,
bool WithWeight = false>
549 std::shared_ptr<Result_t> fHist;
559 std::shared_ptr<Result_t> GetResultPtr()
const {
return fHist; }
564 template <
typename...
ColumnTypes,
const std::size_t...
I>
570 fHist->FillAtomic(args, weight);
586 std::string GetActionName() {
return "Hist"; }
595 std::vector<::TGraph *> fGraphs;
603 fGraphs[0] =
g.get();
605 for (
unsigned int i = 1; i <
nSlots; ++i) {
606 fGraphs[i] =
new TGraph(*fGraphs[0]);
614 template <
typename X0,
typename X1,
615 std::enable_if_t<IsDataContainer<X0>::value && IsDataContainer<X1>::value,
int> = 0>
618 if (
x0s.size() !=
x1s.size()) {
619 throw std::runtime_error(
"Cannot fill Graph with values in containers of different sizes.");
631 template <
typename X0,
typename X1,
632 std::enable_if_t<!IsDataContainer<X0>::value && !IsDataContainer<X1>::value,
int> = 0>
644 throw std::runtime_error(
"Graph was applied to a mix of scalar values and collections. This is not supported.");
649 const auto nSlots = fGraphs.size();
654 l.Add(fGraphs[
slot]);
662 return std::make_unique<RMergeableFill<Result_t>>(*fGraphs[0]);
665 std::string GetActionName() {
return "Graph"; }
667 Result_t &PartialUpdate(
unsigned int slot) {
return *fGraphs[
slot]; }
694 for (
unsigned int i = 1; i <
nSlots; ++i) {
704 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
705 std::enable_if_t<IsDataContainer<X>::value && IsDataContainer<Y>::value && IsDataContainer<EXL>::value &&
706 IsDataContainer<EXH>::value && IsDataContainer<EYL>::value && IsDataContainer<EYH>::value,
711 if ((
xs.size() !=
ys.size()) || (
xs.size() !=
exls.size()) || (
xs.size() !=
exhs.size()) ||
712 (
xs.size() !=
eyls.size()) || (
xs.size() !=
eyhs.size())) {
713 throw std::runtime_error(
"Cannot fill GraphAsymmErrors with values in containers of different sizes.");
716 auto xsIt = std::begin(
xs);
717 auto ysIt = std::begin(
ys);
722 while (
xsIt != std::end(
xs)) {
731 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
732 std::enable_if_t<!IsDataContainer<X>::value && !IsDataContainer<Y>::value && !IsDataContainer<EXL>::value &&
733 !IsDataContainer<EXH>::value && !IsDataContainer<EYL>::value && !IsDataContainer<EYH>::value,
745 template <
typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
749 throw std::runtime_error(
750 "GraphAsymmErrors was applied to a mix of scalar values and collections. This is not supported.");
771 std::string GetActionName() {
return "GraphAsymmErrors"; }
777 auto &
result = *
static_cast<std::shared_ptr<TGraphAsymmErrors> *
>(
newResult);
784template <
typename HIST>
786 std::vector<std::shared_ptr<HIST>> fObjects;
787 std::vector<std::unique_ptr<std::mutex>>
fMutexPtrs;
790 template <
typename T,
typename... Args>
797 template <
typename T,
typename... Args>
800 std::scoped_lock lock{mutex};
801 object.Fill(args...);
804 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
820 fObjects.front() =
h;
822 std::generate(fObjects.begin() + 1, fObjects.end(), [
h]() {
823 auto hist = std::make_shared<HIST>(*h);
824 UnsetDirectoryIfPossible(hist.get());
834 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
842 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
846 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
851 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
857 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
859 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
861 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
868 template <
typename T = HIST>
871 static_assert(
sizeof(T) < 0,
872 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
873 "columns passed did not match the signature of the object's `FillThreadSafe` method.");
880 if (fObjects.size() > 1) {
882 for (
auto it = fObjects.cbegin() + 1; it != fObjects.end(); ++it) {
885 fObjects[0]->Merge(&list);
895 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
900 std::string GetActionName()
902 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
905 template <
typename H = HIST>
921template <
typename V,
typename COLL>
927template <
typename COLL>
934template <
typename RealT_t,
typename T,
typename COLL>
943 for (
unsigned int i = 1; i <
nSlots; ++i)
944 fColls.emplace_back(std::make_shared<COLL>());
958 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
971 std::string GetActionName() {
return "Take"; }
983template <
typename RealT_t,
typename T>
985 :
public RActionImpl<TakeHelper<RealT_t, T, std::vector<T>>> {
993 for (
unsigned int i = 1; i <
nSlots; ++i) {
994 auto v = std::make_shared<std::vector<T>>();
1016 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1022 std::vector<T> &PartialUpdate(
unsigned int slot) {
return *
fColls[
slot]; }
1024 std::string GetActionName() {
return "Take"; }
1028 auto &
result = *
static_cast<std::shared_ptr<std::vector<T>
> *>(
newResult);
1036template <
typename RealT_t,
typename COLL>
1038 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, COLL>> {
1046 for (
unsigned int i = 1; i <
nSlots; ++i)
1047 fColls.emplace_back(std::make_shared<COLL>());
1061 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1063 for (
auto &
v : *
coll) {
1069 std::string GetActionName() {
return "Take"; }
1081template <
typename RealT_t>
1083 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, std::vector<RealT_t>>> {
1092 for (
unsigned int i = 1; i <
nSlots; ++i) {
1093 auto v = std::make_shared<std::vector<RealT_t>>();
1115 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1121 std::string GetActionName() {
return "Take"; }
1134template <
typename RealT_t,
typename T,
typename COLL>
1136template <
typename RealT_t,
typename T>
1138template <
typename RealT_t,
typename COLL>
1140template <
typename RealT_t>
1156template <
typename ResultType>
1183 *
fResultMin = std::numeric_limits<ResultType>::max();
1191 return std::make_unique<RMergeableMin<ResultType>>(*fResultMin);
1196 std::string GetActionName() {
return "Min"; }
1200 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1205template <
typename ResultType>
1232 *
fResultMax = std::numeric_limits<ResultType>::lowest();
1241 return std::make_unique<RMergeableMax<ResultType>>(*fResultMax);
1246 std::string GetActionName() {
return "Max"; }
1250 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1255template <
typename ResultType>
1264 template <
typename T = ResultType>
1270 template <
typename T = ResultType,
typename Dummy =
int>
1298 for (
auto &&
v :
vs) {
1324 return std::make_unique<RMergeableSum<ResultType>>(*fResultSum);
1329 std::string GetActionName() {
return "Sum"; }
1333 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1341 std::vector<ULong64_t> fCounts;
1342 std::vector<double>
fSums;
1356 for (
auto &&
v :
vs) {
1378 double &PartialUpdate(
unsigned int slot);
1380 std::string GetActionName() {
return "Mean"; }
1391 unsigned int fNSlots;
1394 std::vector<ULong64_t> fCounts;
1396 std::vector<double> fMeans;
1410 for (
auto &&
v :
vs) {
1424 std::inner_product(fMeans.begin(), fMeans.end(), fCounts.begin(), 0.) /
static_cast<Double_t>(
counts);
1428 std::string GetActionName() {
return "StdDev"; }
1437template <
typename PrevNodeType>
1442 std::shared_ptr<PrevNodeType> fPrevNode;
1443 size_t fEntriesToProcess;
1446 DisplayHelper(
size_t nRows,
const std::shared_ptr<Display_t> &
d,
const std::shared_ptr<PrevNodeType> &prevNode)
1450 DisplayHelper(DisplayHelper &&) =
default;
1451 DisplayHelper(
const DisplayHelper &) =
delete;
1454 template <
typename...
Columns>
1457 if (fEntriesToProcess == 0)
1461 --fEntriesToProcess;
1463 if (fEntriesToProcess == 0) {
1468 fPrevNode->StopProcessing();
1476 std::string GetActionName() {
return "Display"; }
1479template <
typename Acc,
typename Merge,
typename R,
typename T,
typename U,
1482 :
public RActionImpl<AggregateHelper<Acc, Merge, R, T, U, MustCopyAssign>> {
1485 std::shared_ptr<U> fResult;
1506 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<MustCopyAssign_,
int> = 0>
1512 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<!MustCopyAssign_,
int> = 0>
1521 bool MergeAll = std::is_same<void, MergeRet>::value>
1522 std::enable_if_t<MergeAll, void> Finalize()
1530 std::enable_if_t<MergeTwoByTwo, void> Finalize(...)
1533 *fResult = fMerge(*fResult,
acc);
1538 std::string GetActionName() {
return "Aggregate"; }
Handle_t Display_t
Display handle.
#define R(a, b, c, d, e, f, g, h, i)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x1
Binding & operator=(OUT(*fun)(void))
TClass * IsA() const override
TTime operator*(const TTime &t1, const TTime &t2)
Base class for action helpers, see RInterface::Book() for more information.
A histogram data structure to bin data along multiple dimensions.
A histogram for aggregation of data along multiple dimensions.
This class is the textual representation of the content of a columnar dataset.
const_iterator begin() const
const_iterator end() const
A "std::vector"-like collection of values implementing handy operation to analyse them.
Collection abstract base class.
TGraph with asymmetric error bars.
A TGraph is an object made of two arrays X and Y with npoints each.
1-D histogram with a double per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
void Add(TObject *obj) override
Statistical variable, defined by its mean and variance (RMS).
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
RooCmdArg Columns(Int_t ncol)
CPYCPPYY_EXTERN bool Exec(const std::string &cmd)
std::unique_ptr< RMergeableVariations< T > > GetMergeableValue(ROOT::RDF::Experimental::RResultMap< T > &rmap)
Retrieve mergeable values after calling ROOT::RDF::VariationsFor .
void ResetIfPossible(TStatistic *h)
constexpr std::size_t FindIdxTrue(const T &arr)
void UnsetDirectoryIfPossible(TH1 *h)
auto FillThreadSafe(T &histo, Args... args) -> decltype(histo.FillThreadSafe(args...), void())
Entrypoint for thread-safe filling from RDataFrame.
ROOT type_traits extensions.
void Initialize(Bool_t useTMVAStyle=kTRUE)
A weight for filling histograms.
static uint64_t sum(uint64_t i)