19#ifndef ROOT_RDFOPERATIONS
20#define ROOT_RDFOPERATIONS
35#include "RConfigure.h"
80using Results = std::conditional_t<std::is_same<T, bool>::value, std::deque<T>, std::vector<T>>;
94 template <
typename... Args>
95 void Exec(
unsigned int slot, Args &&... args)
98 static_assert(std::is_same<TypeList<std::decay_t<Args>...>, ColumnTypes_t>
::value,
"");
106 std::string GetActionName() {
return "ForeachSlot"; }
126 return std::make_unique<RMergeableCount>(*
fResultCount);
131 std::string GetActionName() {
return "Count"; }
140template <
typename RNode_t>
142 std::shared_ptr<RCutFlowReport>
fReport;
155 void Exec(
unsigned int ) {}
163 std::string GetActionName() {
return "Report"; }
167 auto &&
result = *
static_cast<std::shared_ptr<RCutFlowReport> *
>(
newResult);
169 std::static_pointer_cast<RNode_t>(fNode->GetVariedFilter(std::string(
variation))).get(),
185 using Buf_t = std::vector<BufEl_t>;
187 std::vector<Buf_t> fBuffers;
190 unsigned int fNSlots;
191 unsigned int fBufSize;
205 void Exec(
unsigned int slot,
double v,
double w);
219 void Exec(
unsigned int slot,
const T &
vs,
const W &ws)
248 void Exec(
unsigned int slot,
const T
v,
const W &ws)
258 Hist_t &PartialUpdate(
unsigned int);
267 return std::make_unique<RMergeableFill<Hist_t>>(*fResultHist);
270 std::string GetActionName()
279 result->SetDirectory(
nullptr);
290 using iterator_category = std::forward_iterator_tag;
291 using difference_type = std::ptrdiff_t;
292 using value_type = T;
294 using reference = T &;
304 if constexpr (IsDataContainer<T>::value) {
305 return std::begin(val);
313std::size_t GetSize(
const T &val)
315 if constexpr (IsDataContainer<T>::value) {
316 return std::size(val);
337template <
typename HIST = Hist_t>
339 std::vector<HIST *> fObjects;
343 auto Merge(std::vector<H *> &
objs,
int )
353 template <
typename H>
354 auto Merge(std::vector<H *> &
objs,
double )
355 ->
decltype(
objs[0]->Merge(std::vector<HIST *>{}),
void())
361 template <
typename T>
364 static_assert(
sizeof(T) < 0,
365 "The type passed to Fill does not provide a Merge(TCollection*) or Merge(const std::vector&) method.");
368 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
382 fObjects[0] =
h.get();
384 for (
unsigned int i = 1; i <
nSlots; ++i) {
385 fObjects[i] =
new HIST(*fObjects[0]);
393 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
396 fObjects[
slot]->Fill(
x...);
400 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
404 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
409 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
415 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
417 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
419 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
426 template <
typename T = HIST>
429 static_assert(
sizeof(T) < 0,
430 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
431 "columns passed did not match the signature of the object's `Fill` method.");
438 if (fObjects.size() == 1)
444 for (
auto it = ++fObjects.begin(); it != fObjects.end(); ++it)
448 HIST &PartialUpdate(
unsigned int slot) {
return *fObjects[
slot]; }
453 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
458 std::string GetActionName()
460 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
465 std::string GetActionName()
467 return "Fill custom object";
470 template <
typename H = HIST>
481template <
typename BinContentType,
bool WithWeight = false>
488 std::unique_ptr<ROOT::Experimental::RHistConcurrentFiller<BinContentType>>
fFiller;
489 std::vector<std::shared_ptr<ROOT::Experimental::RHistFillContext<BinContentType>>> fContexts;
495 for (
unsigned int i = 0; i <
nSlots; i++) {
496 fContexts[i] =
fFiller->CreateFillContext();
505 std::shared_ptr<Result_t> GetResultPtr()
const {
return fFiller.GetHist(); }
510 template <
typename...
ColumnTypes,
const std::size_t...
I>
517 fContexts[
slot]->Fill(args, weight);
533 for (
auto &&context : fContexts) {
538 std::string GetActionName() {
return "Hist"; }
547 std::vector<::TGraph *> fGraphs;
555 fGraphs[0] =
g.get();
557 for (
unsigned int i = 1; i <
nSlots; ++i) {
558 fGraphs[i] =
new TGraph(*fGraphs[0]);
566 template <
typename X0,
typename X1,
567 std::enable_if_t<IsDataContainer<X0>::value && IsDataContainer<X1>::value,
int> = 0>
570 if (
x0s.size() !=
x1s.size()) {
571 throw std::runtime_error(
"Cannot fill Graph with values in containers of different sizes.");
583 template <
typename X0,
typename X1,
584 std::enable_if_t<!IsDataContainer<X0>::value && !IsDataContainer<X1>::value,
int> = 0>
596 throw std::runtime_error(
"Graph was applied to a mix of scalar values and collections. This is not supported.");
601 const auto nSlots = fGraphs.size();
606 l.Add(fGraphs[
slot]);
614 return std::make_unique<RMergeableFill<Result_t>>(*fGraphs[0]);
617 std::string GetActionName() {
return "Graph"; }
619 Result_t &PartialUpdate(
unsigned int slot) {
return *fGraphs[
slot]; }
646 for (
unsigned int i = 1; i <
nSlots; ++i) {
656 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
657 std::enable_if_t<IsDataContainer<X>::value && IsDataContainer<Y>::value && IsDataContainer<EXL>::value &&
658 IsDataContainer<EXH>::value && IsDataContainer<EYL>::value && IsDataContainer<EYH>::value,
663 if ((
xs.size() !=
ys.size()) || (
xs.size() !=
exls.size()) || (
xs.size() !=
exhs.size()) ||
664 (
xs.size() !=
eyls.size()) || (
xs.size() !=
eyhs.size())) {
665 throw std::runtime_error(
"Cannot fill GraphAsymmErrors with values in containers of different sizes.");
668 auto xsIt = std::begin(
xs);
669 auto ysIt = std::begin(
ys);
674 while (
xsIt != std::end(
xs)) {
683 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
684 std::enable_if_t<!IsDataContainer<X>::value && !IsDataContainer<Y>::value && !IsDataContainer<EXL>::value &&
685 !IsDataContainer<EXH>::value && !IsDataContainer<EYL>::value && !IsDataContainer<EYH>::value,
697 template <
typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
701 throw std::runtime_error(
702 "GraphAsymmErrors was applied to a mix of scalar values and collections. This is not supported.");
723 std::string GetActionName() {
return "GraphAsymmErrors"; }
729 auto &
result = *
static_cast<std::shared_ptr<TGraphAsymmErrors> *
>(
newResult);
736template <
typename HIST>
738 std::vector<std::shared_ptr<HIST>> fObjects;
739 std::vector<std::unique_ptr<std::mutex>>
fMutexPtrs;
742 template <
typename T,
typename... Args>
749 template <
typename T,
typename... Args>
752 std::scoped_lock lock{mutex};
753 object.Fill(args...);
756 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
772 fObjects.front() =
h;
774 std::generate(fObjects.begin() + 1, fObjects.end(), [
h]() {
775 auto hist = std::make_shared<HIST>(*h);
776 UnsetDirectoryIfPossible(hist.get());
786 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
794 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
798 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
803 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
809 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
811 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
813 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
820 template <
typename T = HIST>
823 static_assert(
sizeof(T) < 0,
824 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
825 "columns passed did not match the signature of the object's `FillThreadSafe` method.");
832 if (fObjects.size() > 1) {
834 for (
auto it = fObjects.cbegin() + 1; it != fObjects.end(); ++it) {
837 fObjects[0]->Merge(&list);
847 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
852 std::string GetActionName()
854 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
857 template <
typename H = HIST>
873template <
typename V,
typename COLL>
879template <
typename COLL>
886template <
typename RealT_t,
typename T,
typename COLL>
895 for (
unsigned int i = 1; i <
nSlots; ++i)
896 fColls.emplace_back(std::make_shared<COLL>());
910 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
923 std::string GetActionName() {
return "Take"; }
935template <
typename RealT_t,
typename T>
937 :
public RActionImpl<TakeHelper<RealT_t, T, std::vector<T>>> {
945 for (
unsigned int i = 1; i <
nSlots; ++i) {
946 auto v = std::make_shared<std::vector<T>>();
968 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
974 std::vector<T> &PartialUpdate(
unsigned int slot) {
return *
fColls[
slot]; }
976 std::string GetActionName() {
return "Take"; }
980 auto &
result = *
static_cast<std::shared_ptr<std::vector<T>
> *>(
newResult);
988template <
typename RealT_t,
typename COLL>
990 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, COLL>> {
998 for (
unsigned int i = 1; i <
nSlots; ++i)
999 fColls.emplace_back(std::make_shared<COLL>());
1013 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1015 for (
auto &
v : *
coll) {
1021 std::string GetActionName() {
return "Take"; }
1033template <
typename RealT_t>
1035 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, std::vector<RealT_t>>> {
1044 for (
unsigned int i = 1; i <
nSlots; ++i) {
1045 auto v = std::make_shared<std::vector<RealT_t>>();
1067 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1073 std::string GetActionName() {
return "Take"; }
1086template <
typename RealT_t,
typename T,
typename COLL>
1088template <
typename RealT_t,
typename T>
1090template <
typename RealT_t,
typename COLL>
1092template <
typename RealT_t>
1108template <
typename ResultType>
1135 *
fResultMin = std::numeric_limits<ResultType>::max();
1143 return std::make_unique<RMergeableMin<ResultType>>(*fResultMin);
1148 std::string GetActionName() {
return "Min"; }
1152 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1157template <
typename ResultType>
1184 *
fResultMax = std::numeric_limits<ResultType>::lowest();
1193 return std::make_unique<RMergeableMax<ResultType>>(*fResultMax);
1198 std::string GetActionName() {
return "Max"; }
1202 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1207template <
typename ResultType>
1216 template <
typename T = ResultType>
1222 template <
typename T = ResultType,
typename Dummy =
int>
1250 for (
auto &&
v :
vs) {
1276 return std::make_unique<RMergeableSum<ResultType>>(*fResultSum);
1281 std::string GetActionName() {
return "Sum"; }
1285 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1293 std::vector<ULong64_t> fCounts;
1294 std::vector<double>
fSums;
1308 for (
auto &&
v :
vs) {
1330 double &PartialUpdate(
unsigned int slot);
1332 std::string GetActionName() {
return "Mean"; }
1343 unsigned int fNSlots;
1346 std::vector<ULong64_t> fCounts;
1348 std::vector<double> fMeans;
1362 for (
auto &&
v :
vs) {
1376 std::inner_product(fMeans.begin(), fMeans.end(), fCounts.begin(), 0.) /
static_cast<Double_t>(
counts);
1380 std::string GetActionName() {
return "StdDev"; }
1389template <
typename PrevNodeType>
1394 std::shared_ptr<PrevNodeType> fPrevNode;
1395 size_t fEntriesToProcess;
1398 DisplayHelper(
size_t nRows,
const std::shared_ptr<Display_t> &
d,
const std::shared_ptr<PrevNodeType> &prevNode)
1402 DisplayHelper(DisplayHelper &&) =
default;
1403 DisplayHelper(
const DisplayHelper &) =
delete;
1406 template <
typename...
Columns>
1409 if (fEntriesToProcess == 0)
1413 --fEntriesToProcess;
1415 if (fEntriesToProcess == 0) {
1420 fPrevNode->StopProcessing();
1428 std::string GetActionName() {
return "Display"; }
1431template <
typename Acc,
typename Merge,
typename R,
typename T,
typename U,
1434 :
public RActionImpl<AggregateHelper<Acc, Merge, R, T, U, MustCopyAssign>> {
1437 std::shared_ptr<U> fResult;
1458 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<MustCopyAssign_,
int> = 0>
1464 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<!MustCopyAssign_,
int> = 0>
1473 bool MergeAll = std::is_same<void, MergeRet>::value>
1474 std::enable_if_t<MergeAll, void> Finalize()
1482 std::enable_if_t<MergeTwoByTwo, void> Finalize(...)
1485 *fResult = fMerge(*fResult,
acc);
1490 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 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)