19#ifndef ROOT_RDFOPERATIONS
20#define ROOT_RDFOPERATIONS
72using Results = std::conditional_t<std::is_same<T, bool>::value, std::deque<T>, std::vector<T>>;
86 template <
typename... Args>
87 void Exec(
unsigned int slot, Args &&... args)
90 static_assert(std::is_same<TypeList<std::decay_t<Args>...>, ColumnTypes_t>
::value,
"");
98 std::string GetActionName() {
return "ForeachSlot"; }
118 return std::make_unique<RMergeableCount>(*
fResultCount);
123 std::string GetActionName() {
return "Count"; }
132template <
typename RNode_t>
134 std::shared_ptr<RCutFlowReport>
fReport;
147 void Exec(
unsigned int ) {}
155 std::string GetActionName() {
return "Report"; }
159 auto &&
result = *
static_cast<std::shared_ptr<RCutFlowReport> *
>(
newResult);
161 std::static_pointer_cast<RNode_t>(fNode->GetVariedFilter(std::string(
variation))).get(),
177 using Buf_t = std::vector<BufEl_t>;
179 std::vector<Buf_t> fBuffers;
182 unsigned int fNSlots;
183 unsigned int fBufSize;
197 void Exec(
unsigned int slot,
double v,
double w);
211 void Exec(
unsigned int slot,
const T &
vs,
const W &ws)
240 void Exec(
unsigned int slot,
const T
v,
const W &ws)
250 Hist_t &PartialUpdate(
unsigned int);
259 return std::make_unique<RMergeableFill<Hist_t>>(*fResultHist);
262 std::string GetActionName()
271 result->SetDirectory(
nullptr);
282 using iterator_category = std::forward_iterator_tag;
283 using difference_type = std::ptrdiff_t;
284 using value_type = T;
286 using reference = T &;
296 if constexpr (IsDataContainer<T>::value) {
297 return std::begin(val);
305std::size_t GetSize(
const T &val)
307 if constexpr (IsDataContainer<T>::value) {
308 return std::size(val);
329template <
typename HIST = Hist_t>
331 std::vector<HIST *> fObjects;
335 auto Merge(std::vector<H *> &
objs,
int )
345 template <
typename H>
346 auto Merge(std::vector<H *> &
objs,
double )
347 ->
decltype(
objs[0]->Merge(std::vector<HIST *>{}),
void())
353 template <
typename T>
356 static_assert(
sizeof(T) < 0,
357 "The type passed to Fill does not provide a Merge(TCollection*) or Merge(const std::vector&) method.");
360 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
374 fObjects[0] =
h.get();
376 for (
unsigned int i = 1; i <
nSlots; ++i) {
377 fObjects[i] =
new HIST(*fObjects[0]);
385 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
388 fObjects[
slot]->Fill(
x...);
392 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
396 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
401 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
407 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
409 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
411 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
418 template <
typename T = HIST>
421 static_assert(
sizeof(T) < 0,
422 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
423 "columns passed did not match the signature of the object's `Fill` method.");
430 if (fObjects.size() == 1)
436 for (
auto it = ++fObjects.begin(); it != fObjects.end(); ++it)
440 HIST &PartialUpdate(
unsigned int slot) {
return *fObjects[
slot]; }
445 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
450 std::string GetActionName()
452 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
457 std::string GetActionName()
459 return "Fill custom object";
462 template <
typename H = HIST>
477 std::vector<::TGraph *> fGraphs;
485 fGraphs[0] =
g.get();
487 for (
unsigned int i = 1; i <
nSlots; ++i) {
488 fGraphs[i] =
new TGraph(*fGraphs[0]);
496 template <
typename X0,
typename X1,
497 std::enable_if_t<IsDataContainer<X0>::value && IsDataContainer<X1>::value,
int> = 0>
500 if (
x0s.size() !=
x1s.size()) {
501 throw std::runtime_error(
"Cannot fill Graph with values in containers of different sizes.");
513 template <
typename X0,
typename X1,
514 std::enable_if_t<!IsDataContainer<X0>::value && !IsDataContainer<X1>::value,
int> = 0>
526 throw std::runtime_error(
"Graph was applied to a mix of scalar values and collections. This is not supported.");
531 const auto nSlots = fGraphs.size();
536 l.Add(fGraphs[
slot]);
544 return std::make_unique<RMergeableFill<Result_t>>(*fGraphs[0]);
547 std::string GetActionName() {
return "Graph"; }
549 Result_t &PartialUpdate(
unsigned int slot) {
return *fGraphs[
slot]; }
576 for (
unsigned int i = 1; i <
nSlots; ++i) {
586 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
587 std::enable_if_t<IsDataContainer<X>::value && IsDataContainer<Y>::value && IsDataContainer<EXL>::value &&
588 IsDataContainer<EXH>::value && IsDataContainer<EYL>::value && IsDataContainer<EYH>::value,
593 if ((
xs.size() !=
ys.size()) || (
xs.size() !=
exls.size()) || (
xs.size() !=
exhs.size()) ||
594 (
xs.size() !=
eyls.size()) || (
xs.size() !=
eyhs.size())) {
595 throw std::runtime_error(
"Cannot fill GraphAsymmErrors with values in containers of different sizes.");
598 auto xsIt = std::begin(
xs);
599 auto ysIt = std::begin(
ys);
604 while (
xsIt != std::end(
xs)) {
613 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
614 std::enable_if_t<!IsDataContainer<X>::value && !IsDataContainer<Y>::value && !IsDataContainer<EXL>::value &&
615 !IsDataContainer<EXH>::value && !IsDataContainer<EYL>::value && !IsDataContainer<EYH>::value,
627 template <
typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
631 throw std::runtime_error(
632 "GraphAsymmErrors was applied to a mix of scalar values and collections. This is not supported.");
653 std::string GetActionName() {
return "GraphAsymmErrors"; }
659 auto &
result = *
static_cast<std::shared_ptr<TGraphAsymmErrors> *
>(
newResult);
666template <
typename HIST>
668 std::vector<std::shared_ptr<HIST>> fObjects;
669 std::vector<std::unique_ptr<std::mutex>>
fMutexPtrs;
672 template <
typename T,
typename... Args>
679 template <
typename T,
typename... Args>
682 std::scoped_lock lock{mutex};
683 object.Fill(args...);
686 template <std::size_t
ColIdx,
typename End_t,
typename...
Its>
702 fObjects.front() =
h;
704 std::generate(fObjects.begin() + 1, fObjects.end(), [
h]() {
705 auto hist = std::make_shared<HIST>(*h);
706 UnsetDirectoryIfPossible(hist.get());
716 template <
typename...
ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
724 template <
typename...
Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
728 constexpr std::array<
bool,
sizeof...(Xs)>
isContainer{IsDataContainer<Xs>::value...};
733 static_assert(
colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
739 std::array<std::size_t,
sizeof...(xs)>
sizes = {{GetSize(
xs)...}};
741 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
743 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
750 template <
typename T = HIST>
753 static_assert(
sizeof(T) < 0,
754 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
755 "columns passed did not match the signature of the object's `FillThreadSafe` method.");
762 if (fObjects.size() > 1) {
764 for (
auto it = fObjects.cbegin() + 1; it != fObjects.end(); ++it) {
767 fObjects[0]->Merge(&list);
777 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
782 std::string GetActionName()
784 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
787 template <
typename H = HIST>
803template <
typename V,
typename COLL>
809template <
typename COLL>
816template <
typename RealT_t,
typename T,
typename COLL>
825 for (
unsigned int i = 1; i <
nSlots; ++i)
826 fColls.emplace_back(std::make_shared<COLL>());
840 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
853 std::string GetActionName() {
return "Take"; }
865template <
typename RealT_t,
typename T>
867 :
public RActionImpl<TakeHelper<RealT_t, T, std::vector<T>>> {
875 for (
unsigned int i = 1; i <
nSlots; ++i) {
876 auto v = std::make_shared<std::vector<T>>();
898 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
904 std::vector<T> &PartialUpdate(
unsigned int slot) {
return *
fColls[
slot]; }
906 std::string GetActionName() {
return "Take"; }
910 auto &
result = *
static_cast<std::shared_ptr<std::vector<T>
> *>(
newResult);
918template <
typename RealT_t,
typename COLL>
920 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, COLL>> {
928 for (
unsigned int i = 1; i <
nSlots; ++i)
929 fColls.emplace_back(std::make_shared<COLL>());
943 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
945 for (
auto &
v : *
coll) {
951 std::string GetActionName() {
return "Take"; }
963template <
typename RealT_t>
965 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, std::vector<RealT_t>>> {
974 for (
unsigned int i = 1; i <
nSlots; ++i) {
975 auto v = std::make_shared<std::vector<RealT_t>>();
997 for (
unsigned int i = 1; i <
fColls.size(); ++i) {
1003 std::string GetActionName() {
return "Take"; }
1016template <
typename RealT_t,
typename T,
typename COLL>
1018template <
typename RealT_t,
typename T>
1020template <
typename RealT_t,
typename COLL>
1022template <
typename RealT_t>
1038template <
typename ResultType>
1065 *
fResultMin = std::numeric_limits<ResultType>::max();
1073 return std::make_unique<RMergeableMin<ResultType>>(*fResultMin);
1078 std::string GetActionName() {
return "Min"; }
1082 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1087template <
typename ResultType>
1114 *
fResultMax = std::numeric_limits<ResultType>::lowest();
1123 return std::make_unique<RMergeableMax<ResultType>>(*fResultMax);
1128 std::string GetActionName() {
return "Max"; }
1132 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1137template <
typename ResultType>
1146 template <
typename T = ResultType>
1152 template <
typename T = ResultType,
typename Dummy =
int>
1180 for (
auto &&
v :
vs) {
1206 return std::make_unique<RMergeableSum<ResultType>>(*fResultSum);
1211 std::string GetActionName() {
return "Sum"; }
1215 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(
newResult);
1223 std::vector<ULong64_t> fCounts;
1224 std::vector<double>
fSums;
1238 for (
auto &&
v :
vs) {
1256 const ULong64_t counts = std::accumulate(fCounts.begin(), fCounts.end(), 0ull);
1260 double &PartialUpdate(
unsigned int slot);
1262 std::string GetActionName() {
return "Mean"; }
1273 unsigned int fNSlots;
1276 std::vector<ULong64_t> fCounts;
1278 std::vector<double> fMeans;
1292 for (
auto &&
v :
vs) {
1304 const ULong64_t counts = std::accumulate(fCounts.begin(), fCounts.end(), 0ull);
1306 std::inner_product(fMeans.begin(), fMeans.end(), fCounts.begin(), 0.) /
static_cast<Double_t>(
counts);
1310 std::string GetActionName() {
return "StdDev"; }
1319template <
typename PrevNodeType>
1324 std::shared_ptr<PrevNodeType> fPrevNode;
1325 size_t fEntriesToProcess;
1328 DisplayHelper(
size_t nRows,
const std::shared_ptr<Display_t> &
d,
const std::shared_ptr<PrevNodeType> &prevNode)
1332 DisplayHelper(DisplayHelper &&) =
default;
1333 DisplayHelper(
const DisplayHelper &) =
delete;
1336 template <
typename...
Columns>
1339 if (fEntriesToProcess == 0)
1343 --fEntriesToProcess;
1345 if (fEntriesToProcess == 0) {
1350 fPrevNode->StopProcessing();
1358 std::string GetActionName() {
return "Display"; }
1361template <
typename Acc,
typename Merge,
typename R,
typename T,
typename U,
1364 :
public RActionImpl<AggregateHelper<Acc, Merge, R, T, U, MustCopyAssign>> {
1367 std::shared_ptr<U> fResult;
1388 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<MustCopyAssign_,
int> = 0>
1394 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<!MustCopyAssign_,
int> = 0>
1403 bool MergeAll = std::is_same<void, MergeRet>::value>
1404 std::enable_if_t<MergeAll, void> Finalize()
1412 std::enable_if_t<MergeTwoByTwo, void> Finalize(...)
1415 *fResult = fMerge(*fResult,
acc);
1420 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
TClass * IsA() const override
TTime operator*(const TTime &t1, const TTime &t2)
Base class for action helpers, see RInterface::Book() for more information.
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.
Namespace for new ROOT classes and functions.
void Initialize(Bool_t useTMVAStyle=kTRUE)
static uint64_t sum(uint64_t i)