19#ifndef ROOT_RDFOPERATIONS
20#define ROOT_RDFOPERATIONS
75 std::vector<TBranch *> fBranches;
76 std::vector<std::string> fNames;
81 auto it = std::find(fNames.begin(), fNames.end(),
name);
82 if (it == fNames.end())
84 return fBranches[std::distance(fNames.begin(), it)];
87 void Insert(
const std::string &
name,
TBranch *address)
89 if (address ==
nullptr) {
90 throw std::logic_error(
"Trying to insert a null branch address.");
92 if (std::find(fBranches.begin(), fBranches.end(), address) != fBranches.end()) {
93 throw std::logic_error(
"Trying to insert a branch address that's already present.");
95 if (std::find(fNames.begin(), fNames.end(),
name) != fNames.end()) {
96 throw std::logic_error(
"Trying to insert a branch name that's already present.");
98 fNames.emplace_back(
name);
99 fBranches.emplace_back(address);
108 void AssertNoNullBranchAddresses()
110 std::vector<TBranch *> branchesWithNullAddress;
111 std::copy_if(fBranches.begin(), fBranches.end(), std::back_inserter(branchesWithNullAddress),
112 [](
TBranch *
b) { return b->GetAddress() == nullptr; });
114 if (branchesWithNullAddress.empty())
118 std::vector<std::string> missingBranchNames;
119 std::transform(branchesWithNullAddress.begin(), branchesWithNullAddress.end(),
120 std::back_inserter(missingBranchNames), [](
TBranch *
b) { return b->GetName(); });
121 std::string msg =
"RDataFrame::Snapshot:";
122 if (missingBranchNames.size() == 1) {
123 msg +=
" branch " + missingBranchNames[0] +
124 " is needed as it provides the size for one or more branches containing dynamically sized arrays, but "
128 for (
const auto &bName : missingBranchNames)
130 msg.resize(msg.size() - 2);
132 " are needed as they provide the size of other branches containing dynamically sized arrays, but they are";
134 msg +=
" not part of the set of branches that are being written out.";
135 throw std::runtime_error(msg);
144using Results = std::conditional_t<std::is_same<T, bool>::value, std::deque<T>, std::vector<T>>;
147class R__CLING_PTRCHECK(off) ForeachSlotHelper :
public RActionImpl<ForeachSlotHelper<F>> {
153 ForeachSlotHelper(ForeachSlotHelper &&) =
default;
154 ForeachSlotHelper(
const ForeachSlotHelper &) =
delete;
158 template <
typename... Args>
159 void Exec(
unsigned int slot, Args &&... args)
162 static_assert(std::is_same<TypeList<std::decay_t<Args>...>, ColumnTypes_t>
::value,
"");
163 fCallable(slot, std::forward<Args>(args)...);
170 std::string GetActionName() {
return "ForeachSlot"; }
173class R__CLING_PTRCHECK(off) CountHelper :
public RActionImpl<CountHelper> {
174 std::shared_ptr<ULong64_t> fResultCount;
175 Results<ULong64_t> fCounts;
179 CountHelper(
const std::shared_ptr<ULong64_t> &resultCount,
const unsigned int nSlots);
180 CountHelper(CountHelper &&) =
default;
181 CountHelper(
const CountHelper &) =
delete;
183 void Exec(
unsigned int slot);
190 return std::make_unique<RMergeableCount>(*fResultCount);
193 ULong64_t &PartialUpdate(
unsigned int slot);
195 std::string GetActionName() {
return "Count"; }
197 CountHelper MakeNew(
void *newResult)
199 auto &
result = *
static_cast<std::shared_ptr<ULong64_t> *
>(newResult);
200 return CountHelper(
result, fCounts.size());
204template <
typename RNode_t>
205class R__CLING_PTRCHECK(off) ReportHelper :
public RActionImpl<ReportHelper<RNode_t>> {
206 std::shared_ptr<RCutFlowReport> fReport;
210 bool fReturnEmptyReport;
214 ReportHelper(
const std::shared_ptr<RCutFlowReport> &report, RNode_t *node,
bool emptyRep)
215 : fReport(report), fNode(node), fReturnEmptyReport(emptyRep){};
216 ReportHelper(ReportHelper &&) =
default;
217 ReportHelper(
const ReportHelper &) =
delete;
219 void Exec(
unsigned int ) {}
223 if (!fReturnEmptyReport)
224 fNode->Report(*fReport);
227 std::string GetActionName() {
return "Report"; }
239class R__CLING_PTRCHECK(off) BufferedFillHelper :
public RActionImpl<BufferedFillHelper> {
241 static constexpr unsigned int fgTotalBufSize = 2097152;
243 using Buf_t = std::vector<BufEl_t>;
245 std::vector<Buf_t> fBuffers;
246 std::vector<Buf_t> fWBuffers;
247 std::shared_ptr<Hist_t> fResultHist;
248 unsigned int fNSlots;
249 unsigned int fBufSize;
251 Results<std::unique_ptr<Hist_t>> fPartialHists;
255 void UpdateMinMax(
unsigned int slot,
double v);
258 BufferedFillHelper(
const std::shared_ptr<Hist_t> &
h,
const unsigned int nSlots);
259 BufferedFillHelper(BufferedFillHelper &&) =
default;
260 BufferedFillHelper(
const BufferedFillHelper &) =
delete;
262 void Exec(
unsigned int slot,
double v);
263 void Exec(
unsigned int slot,
double v,
double w);
265 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
266 void Exec(
unsigned int slot,
const T &vs)
268 auto &thisBuf = fBuffers[slot];
270 for (
auto v = vs.begin();
v != vs.end(); ++
v) {
271 UpdateMinMax(slot, *
v);
272 thisBuf.emplace_back(*
v);
276 template <typename T, typename W, std::enable_if_t<IsDataContainer<T>::value && IsDataContainer<W>::value,
int> = 0>
277 void Exec(
unsigned int slot,
const T &vs,
const W &ws)
279 auto &thisBuf = fBuffers[slot];
282 UpdateMinMax(slot,
v);
283 thisBuf.emplace_back(
v);
286 auto &thisWBuf = fWBuffers[slot];
288 thisWBuf.emplace_back(
w);
292 template <typename T, typename W, std::enable_if_t<IsDataContainer<T>::value && !IsDataContainer<W>::value,
int> = 0>
293 void Exec(
unsigned int slot,
const T &vs,
const W
w)
295 auto &thisBuf = fBuffers[slot];
297 UpdateMinMax(slot,
v);
298 thisBuf.emplace_back(
v);
301 auto &thisWBuf = fWBuffers[slot];
302 thisWBuf.insert(thisWBuf.end(), vs.size(),
w);
305 template <typename T, typename W, std::enable_if_t<IsDataContainer<W>::value && !IsDataContainer<T>::value,
int> = 0>
306 void Exec(
unsigned int slot,
const T
v,
const W &ws)
308 UpdateMinMax(slot,
v);
309 auto &thisBuf = fBuffers[slot];
310 thisBuf.insert(thisBuf.end(), ws.size(),
v);
312 auto &thisWBuf = fWBuffers[slot];
313 thisWBuf.insert(thisWBuf.end(), ws.begin(), ws.end());
316 Hist_t &PartialUpdate(
unsigned int);
325 return std::make_unique<RMergeableFill<Hist_t>>(*fResultHist);
328 std::string GetActionName()
330 return std::string(fResultHist->IsA()->GetName()) +
"\\n" + std::string(fResultHist->GetName());
333 BufferedFillHelper MakeNew(
void *newResult)
335 auto &
result = *
static_cast<std::shared_ptr<Hist_t> *
>(newResult);
337 result->SetDirectory(
nullptr);
338 return BufferedFillHelper(
result, fNSlots);
344template <
typename HIST = Hist_t>
345class R__CLING_PTRCHECK(off) FillHelper :
public RActionImpl<FillHelper<HIST>> {
346 std::vector<HIST *> fObjects;
348 template <typename H = HIST, typename = decltype(std::declval<H>().Reset())>
349 void ResetIfPossible(
H *
h)
357 void ResetIfPossible(...)
359 throw std::runtime_error(
360 "A systematic variation was requested for a custom Fill action, but the type of the object to be filled does "
361 "not implement a Reset method, so we cannot safely re-initialize variations of the result. Aborting.");
364 void UnsetDirectoryIfPossible(
TH1 *
h) {
365 h->SetDirectory(
nullptr);
368 void UnsetDirectoryIfPossible(...) {}
371 template <typename H, typename = std::enable_if_t<std::is_base_of<TObject, H>::value,
int>>
372 auto Merge(std::vector<H *> &objs,
int )
376 for (
auto it = ++objs.begin(); it != objs.end(); ++it)
382 template <
typename H>
383 auto Merge(std::vector<H *> &objs,
double )
384 ->
decltype(objs[0]->Merge(std::vector<HIST *>{}),
void())
386 objs[0]->Merge({++objs.begin(), objs.end()});
390 template <
typename T>
393 static_assert(
sizeof(
T) < 0,
394 "The type passed to Fill does not provide a Merge(TCollection*) or Merge(const std::vector&) method.");
398 template <
typename T>
399 class ScalarConstIterator {
403 ScalarConstIterator(
const T *obj) : obj_(obj) {}
405 ScalarConstIterator<T> &operator++() {
return *
this; }
413 template <typename T, std::enable_if_t<!IsDataContainer<T>::value,
int> = 0>
414 ScalarConstIterator<T> MakeBegin(
const T &val)
416 return ScalarConstIterator<T>(&val);
420 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
421 auto MakeBegin(
const T &val)
423 return std::begin(val);
427 template <typename T, std::enable_if_t<!IsDataContainer<T>::value,
int> = 0>
428 std::size_t GetSize(
const T &)
434 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
435 std::size_t GetSize(
const T &val)
437#if __cplusplus >= 201703L
438 return std::size(val);
444 template <std::size_t ColIdx,
typename End_t,
typename... Its>
445 void ExecLoop(
unsigned int slot, End_t end, Its... its)
447 auto *thisSlotH = fObjects[slot];
450 auto nop = [](
auto &&...) {};
451 for (; GetNthElement<ColIdx>(its...) !=
end; nop(++its...)) {
452 thisSlotH->Fill(*its...);
457 FillHelper(FillHelper &&) =
default;
458 FillHelper(
const FillHelper &) =
delete;
460 FillHelper(
const std::shared_ptr<HIST> &
h,
const unsigned int nSlots) : fObjects(nSlots, nullptr)
462 fObjects[0] =
h.get();
464 for (
unsigned int i = 1; i < nSlots; ++i) {
465 fObjects[i] =
new HIST(*fObjects[0]);
466 UnsetDirectoryIfPossible(fObjects[i]);
473 template <
typename... ValTypes, std::enable_if_t<!Disjunction<IsDataContainer<ValTypes>...>
::value,
int> = 0>
474 auto Exec(
unsigned int slot,
const ValTypes &...
x) ->
decltype(fObjects[slot]->Fill(
x...),
void())
476 fObjects[slot]->Fill(
x...);
480 template <
typename... Xs, std::enable_if_t<Disjunction<IsDataContainer<Xs>...>
::value,
int> = 0>
481 auto Exec(
unsigned int slot,
const Xs &...xs) ->
decltype(fObjects[slot]->Fill(*MakeBegin(xs)...),
void())
484 constexpr std::array<
bool,
sizeof...(Xs)> isContainer{IsDataContainer<Xs>::value...};
487 constexpr std::size_t colidx =
FindIdxTrue(isContainer);
489 static_assert(colidx <
sizeof...(Xs),
"Error: index of collection-type argument not found.");
492 auto const xrefend = std::end(GetNthElement<colidx>(xs...));
495 std::array<std::size_t,
sizeof...(xs)> sizes = {{GetSize(xs)...}};
497 for (std::size_t i = 0; i <
sizeof...(xs); ++i) {
498 if (isContainer[i] && sizes[i] != sizes[colidx]) {
499 throw std::runtime_error(
"Cannot fill histogram with values in containers of different sizes.");
503 ExecLoop<colidx>(slot, xrefend, MakeBegin(xs)...);
506 template <
typename T = HIST>
509 static_assert(
sizeof(
T) < 0,
510 "When filling an object with RDataFrame (e.g. via a Fill action) the number or types of the "
511 "columns passed did not match the signature of the object's `Fill` method.");
518 if (fObjects.size() == 1)
524 for (
auto it = ++fObjects.begin(); it != fObjects.end(); ++it)
528 HIST &PartialUpdate(
unsigned int slot) {
return *fObjects[slot]; }
533 return std::make_unique<RMergeableFill<HIST>>(*fObjects[0]);
537 template <typename T = HIST, std::enable_if_t<std::is_base_of<TObject, T>::value,
int> = 0>
538 std::string GetActionName()
540 return std::string(fObjects[0]->
IsA()->GetName()) +
"\\n" + std::string(fObjects[0]->GetName());
544 template <typename T = HIST, std::enable_if_t<!std::is_base_of<TObject, T>::value,
int> = 0>
545 std::string GetActionName()
547 return "Fill custom object";
550 template <
typename H = HIST>
551 FillHelper MakeNew(
void *newResult)
553 auto &
result = *
static_cast<std::shared_ptr<H> *
>(newResult);
554 ResetIfPossible(
result.get());
555 UnsetDirectoryIfPossible(
result.get());
556 return FillHelper(
result, fObjects.size());
565 std::vector<::TGraph *> fGraphs;
568 FillTGraphHelper(FillTGraphHelper &&) =
default;
569 FillTGraphHelper(
const FillTGraphHelper &) =
delete;
571 FillTGraphHelper(
const std::shared_ptr<::TGraph> &
g,
const unsigned int nSlots) : fGraphs(nSlots, nullptr)
573 fGraphs[0] =
g.get();
575 for (
unsigned int i = 1; i < nSlots; ++i) {
576 fGraphs[i] =
new TGraph(*fGraphs[0]);
584 template <
typename X0,
typename X1,
585 std::enable_if_t<IsDataContainer<X0>::value && IsDataContainer<X1>::value,
int> = 0>
586 void Exec(
unsigned int slot,
const X0 &x0s,
const X1 &x1s)
588 if (x0s.size() != x1s.size()) {
589 throw std::runtime_error(
"Cannot fill Graph with values in containers of different sizes.");
591 auto *thisSlotG = fGraphs[slot];
592 auto x0sIt = std::begin(x0s);
593 const auto x0sEnd = std::end(x0s);
594 auto x1sIt = std::begin(x1s);
595 for (; x0sIt != x0sEnd; x0sIt++, x1sIt++) {
596 thisSlotG->SetPoint(thisSlotG->GetN(), *x0sIt, *x1sIt);
601 template <
typename X0,
typename X1,
602 std::enable_if_t<!IsDataContainer<X0>::value && !IsDataContainer<X1>::value,
int> = 0>
603 void Exec(
unsigned int slot, X0 x0, X1
x1)
605 auto thisSlotG = fGraphs[slot];
606 thisSlotG->SetPoint(thisSlotG->GetN(), x0,
x1);
611 template <
typename X0,
typename X1,
typename... ExtraArgsToLowerPriority>
612 void Exec(
unsigned int, X0, X1, ExtraArgsToLowerPriority...)
614 throw std::runtime_error(
"Graph was applied to a mix of scalar values and collections. This is not supported.");
619 const auto nSlots = fGraphs.size();
620 auto resGraph = fGraphs[0];
623 for (
unsigned int slot = 1; slot < nSlots; ++slot) {
624 l.Add(fGraphs[slot]);
632 return std::make_unique<RMergeableFill<Result_t>>(*fGraphs[0]);
635 std::string GetActionName() {
return "Graph"; }
637 Result_t &PartialUpdate(
unsigned int slot) {
return *fGraphs[slot]; }
639 FillTGraphHelper MakeNew(
void *newResult)
641 auto &
result = *
static_cast<std::shared_ptr<TGraph> *
>(newResult);
643 return FillTGraphHelper(
result, fGraphs.size());
647class R__CLING_PTRCHECK(off) FillTGraphAsymmErrorsHelper
653 std::vector<::TGraphAsymmErrors *> fGraphAsymmErrors;
656 FillTGraphAsymmErrorsHelper(FillTGraphAsymmErrorsHelper &&) =
default;
657 FillTGraphAsymmErrorsHelper(
const FillTGraphAsymmErrorsHelper &) =
delete;
659 FillTGraphAsymmErrorsHelper(
const std::shared_ptr<::TGraphAsymmErrors> &
g,
const unsigned int nSlots)
660 : fGraphAsymmErrors(nSlots, nullptr)
662 fGraphAsymmErrors[0] =
g.get();
664 for (
unsigned int i = 1; i < nSlots; ++i) {
674 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
675 std::enable_if_t<IsDataContainer<X>::value && IsDataContainer<Y>::value && IsDataContainer<EXL>::value &&
676 IsDataContainer<EXH>::value && IsDataContainer<EYL>::value && IsDataContainer<EYH>::value,
679 Exec(
unsigned int slot,
const X &xs,
const Y &ys,
const EXL &exls,
const EXH &exhs,
const EYL &eyls,
const EYH &eyhs)
681 if ((xs.size() != ys.size()) || (xs.size() != exls.size()) || (xs.size() != exhs.size()) ||
682 (xs.size() != eyls.size()) || (xs.size() != eyhs.size())) {
683 throw std::runtime_error(
"Cannot fill GraphAsymmErrors with values in containers of different sizes.");
685 auto *thisSlotG = fGraphAsymmErrors[slot];
686 auto xsIt = std::begin(xs);
687 auto ysIt = std::begin(ys);
688 auto exlsIt = std::begin(exls);
689 auto exhsIt = std::begin(exhs);
690 auto eylsIt = std::begin(eyls);
691 auto eyhsIt = std::begin(eyhs);
692 while (xsIt != std::end(xs)) {
693 const auto n = thisSlotG->GetN();
694 thisSlotG->SetPoint(
n, *xsIt++, *ysIt++);
695 thisSlotG->SetPointError(
n, *exlsIt++, *exhsIt++, *eylsIt++, *eyhsIt++);
701 typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
702 std::enable_if_t<!IsDataContainer<X>::value && !IsDataContainer<Y>::value && !IsDataContainer<EXL>::value &&
703 !IsDataContainer<EXH>::value && !IsDataContainer<EYL>::value && !IsDataContainer<EYH>::value,
705 void Exec(
unsigned int slot,
X x, Y
y, EXL exl, EXH exh, EYL eyl, EYH eyh)
707 auto thisSlotG = fGraphAsymmErrors[slot];
708 const auto n = thisSlotG->GetN();
709 thisSlotG->SetPoint(
n,
x,
y);
710 thisSlotG->SetPointError(
n, exl, exh, eyl, eyh);
715 template <
typename X,
typename Y,
typename EXL,
typename EXH,
typename EYL,
typename EYH,
716 typename... ExtraArgsToLowerPriority>
717 void Exec(
unsigned int,
X, Y, EXL, EXH, EYL, EYH, ExtraArgsToLowerPriority...)
719 throw std::runtime_error(
720 "GraphAsymmErrors was applied to a mix of scalar values and collections. This is not supported.");
725 const auto nSlots = fGraphAsymmErrors.size();
726 auto resGraphAsymmErrors = fGraphAsymmErrors[0];
729 for (
unsigned int slot = 1; slot < nSlots; ++slot) {
730 l.Add(fGraphAsymmErrors[slot]);
732 resGraphAsymmErrors->Merge(&
l);
738 return std::make_unique<RMergeableFill<Result_t>>(*fGraphAsymmErrors[0]);
741 std::string GetActionName() {
return "GraphAsymmErrors"; }
743 Result_t &PartialUpdate(
unsigned int slot) {
return *fGraphAsymmErrors[slot]; }
745 FillTGraphAsymmErrorsHelper MakeNew(
void *newResult)
747 auto &
result = *
static_cast<std::shared_ptr<TGraphAsymmErrors> *
>(newResult);
749 return FillTGraphAsymmErrorsHelper(
result, fGraphAsymmErrors.size());
759template <
typename V,
typename COLL>
760void FillColl(V&&
v, COLL&
c) {
765template <
typename COLL>
766void FillColl(
bool v, COLL&
c) {
772template <
typename RealT_t,
typename T,
typename COLL>
773class R__CLING_PTRCHECK(off) TakeHelper :
public RActionImpl<TakeHelper<RealT_t, T, COLL>> {
774 Results<std::shared_ptr<COLL>> fColls;
778 TakeHelper(
const std::shared_ptr<COLL> &resultColl,
const unsigned int nSlots)
780 fColls.emplace_back(resultColl);
781 for (
unsigned int i = 1; i < nSlots; ++i)
782 fColls.emplace_back(std::make_shared<COLL>());
784 TakeHelper(TakeHelper &&);
785 TakeHelper(
const TakeHelper &) =
delete;
789 void Exec(
unsigned int slot, T &
v) { FillColl(
v, *fColls[slot]); }
795 auto rColl = fColls[0];
796 for (
unsigned int i = 1; i < fColls.size(); ++i) {
797 const auto &coll = fColls[i];
798 const auto end = coll->end();
801 for (
auto j = coll->begin(); j !=
end; j++) {
802 FillColl(*j, *rColl);
807 COLL &PartialUpdate(
unsigned int slot) {
return *fColls[slot].get(); }
809 std::string GetActionName() {
return "Take"; }
811 TakeHelper MakeNew(
void *newResult)
813 auto &
result = *
static_cast<std::shared_ptr<COLL> *
>(newResult);
815 return TakeHelper(
result, fColls.size());
821template <
typename RealT_t,
typename T>
822class R__CLING_PTRCHECK(off) TakeHelper<RealT_t,
T, std::vector<T>>
823 :
public RActionImpl<TakeHelper<RealT_t, T, std::vector<T>>> {
824 Results<std::shared_ptr<std::vector<T>>> fColls;
828 TakeHelper(
const std::shared_ptr<std::vector<T>> &resultColl,
const unsigned int nSlots)
830 fColls.emplace_back(resultColl);
831 for (
unsigned int i = 1; i < nSlots; ++i) {
832 auto v = std::make_shared<std::vector<T>>();
834 fColls.emplace_back(
v);
837 TakeHelper(TakeHelper &&);
838 TakeHelper(
const TakeHelper &) =
delete;
842 void Exec(
unsigned int slot, T &
v) { FillColl(
v, *fColls[slot]); }
850 for (
auto &coll : fColls)
851 totSize += coll->
size();
852 auto rColl = fColls[0];
853 rColl->reserve(totSize);
854 for (
unsigned int i = 1; i < fColls.size(); ++i) {
855 auto &coll = fColls[i];
856 rColl->insert(rColl->end(), coll->begin(), coll->end());
860 std::vector<T> &PartialUpdate(
unsigned int slot) {
return *fColls[slot]; }
862 std::string GetActionName() {
return "Take"; }
864 TakeHelper MakeNew(
void *newResult)
866 auto &
result = *
static_cast<std::shared_ptr<std::vector<T>
> *>(newResult);
868 return TakeHelper(
result, fColls.size());
874template <
typename RealT_t,
typename COLL>
875class R__CLING_PTRCHECK(off) TakeHelper<RealT_t,
RVec<RealT_t>, COLL>
876 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, COLL>> {
877 Results<std::shared_ptr<COLL>> fColls;
881 TakeHelper(
const std::shared_ptr<COLL> &resultColl,
const unsigned int nSlots)
883 fColls.emplace_back(resultColl);
884 for (
unsigned int i = 1; i < nSlots; ++i)
885 fColls.emplace_back(std::make_shared<COLL>());
887 TakeHelper(TakeHelper &&);
888 TakeHelper(
const TakeHelper &) =
delete;
898 auto rColl = fColls[0];
899 for (
unsigned int i = 1; i < fColls.size(); ++i) {
900 auto &coll = fColls[i];
901 for (
auto &
v : *coll) {
902 rColl->emplace_back(
v);
907 std::string GetActionName() {
return "Take"; }
909 TakeHelper MakeNew(
void *newResult)
911 auto &
result = *
static_cast<std::shared_ptr<COLL> *
>(newResult);
913 return TakeHelper(
result, fColls.size());
919template <
typename RealT_t>
920class R__CLING_PTRCHECK(off) TakeHelper<RealT_t,
RVec<RealT_t>, std::vector<RealT_t>>
921 :
public RActionImpl<TakeHelper<RealT_t, RVec<RealT_t>, std::vector<RealT_t>>> {
923 Results<std::shared_ptr<std::vector<std::vector<RealT_t>>>> fColls;
927 TakeHelper(
const std::shared_ptr<std::vector<std::vector<RealT_t>>> &resultColl,
const unsigned int nSlots)
929 fColls.emplace_back(resultColl);
930 for (
unsigned int i = 1; i < nSlots; ++i) {
931 auto v = std::make_shared<std::vector<RealT_t>>();
933 fColls.emplace_back(
v);
936 TakeHelper(TakeHelper &&);
937 TakeHelper(
const TakeHelper &) =
delete;
949 for (
auto &coll : fColls)
950 totSize += coll->
size();
951 auto rColl = fColls[0];
952 rColl->reserve(totSize);
953 for (
unsigned int i = 1; i < fColls.size(); ++i) {
954 auto &coll = fColls[i];
955 rColl->insert(rColl->end(), coll->begin(), coll->end());
959 std::string GetActionName() {
return "Take"; }
961 TakeHelper MakeNew(
void *newResult)
963 auto &
result = *
static_cast<typename decltype(fColls)::value_type *
>(newResult);
965 return TakeHelper(
result, fColls.size());
972template <
typename RealT_t,
typename T,
typename COLL>
973TakeHelper<RealT_t, T, COLL>::TakeHelper(TakeHelper<RealT_t, T, COLL> &&) =
default;
974template <
typename RealT_t,
typename T>
975TakeHelper<RealT_t, T, std::vector<T>>::TakeHelper(TakeHelper<RealT_t, T, std::vector<T>> &&) =
default;
976template <
typename RealT_t,
typename COLL>
977TakeHelper<RealT_t, RVec<RealT_t>, COLL>::TakeHelper(TakeHelper<RealT_t,
RVec<RealT_t>, COLL> &&) =
default;
978template <
typename RealT_t>
979TakeHelper<RealT_t, RVec<RealT_t>, std::vector<RealT_t>>::TakeHelper(TakeHelper<RealT_t,
RVec<RealT_t>, std::vector<RealT_t>> &&) =
default;
983extern template class TakeHelper<bool, bool, std::vector<bool>>;
984extern template class TakeHelper<unsigned int, unsigned int, std::vector<unsigned int>>;
985extern template class TakeHelper<unsigned long, unsigned long, std::vector<unsigned long>>;
986extern template class TakeHelper<unsigned long long, unsigned long long, std::vector<unsigned long long>>;
987extern template class TakeHelper<int, int, std::vector<int>>;
988extern template class TakeHelper<long, long, std::vector<long>>;
989extern template class TakeHelper<long long, long long, std::vector<long long>>;
990extern template class TakeHelper<float, float, std::vector<float>>;
991extern template class TakeHelper<double, double, std::vector<double>>;
994template <
typename ResultType>
995class R__CLING_PTRCHECK(off) MinHelper :
public RActionImpl<MinHelper<ResultType>> {
996 std::shared_ptr<ResultType> fResultMin;
997 Results<ResultType> fMins;
1000 MinHelper(MinHelper &&) =
default;
1001 MinHelper(
const std::shared_ptr<ResultType> &minVPtr,
const unsigned int nSlots)
1002 : fResultMin(minVPtr), fMins(nSlots, std::numeric_limits<ResultType>::
max())
1006 void Exec(
unsigned int slot, ResultType
v) { fMins[slot] = std::min(
v, fMins[slot]); }
1010 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
1011 void Exec(
unsigned int slot,
const T &vs)
1014 fMins[slot] = std::min(static_cast<ResultType>(
v), fMins[slot]);
1021 *fResultMin = std::numeric_limits<ResultType>::max();
1022 for (
auto &
m : fMins)
1023 *fResultMin = std::min(
m, *fResultMin);
1029 return std::make_unique<RMergeableMin<ResultType>>(*fResultMin);
1032 ResultType &PartialUpdate(
unsigned int slot) {
return fMins[slot]; }
1034 std::string GetActionName() {
return "Min"; }
1036 MinHelper MakeNew(
void *newResult)
1038 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(newResult);
1039 return MinHelper(
result, fMins.size());
1043template <
typename ResultType>
1044class R__CLING_PTRCHECK(off) MaxHelper :
public RActionImpl<MaxHelper<ResultType>> {
1045 std::shared_ptr<ResultType> fResultMax;
1046 Results<ResultType> fMaxs;
1049 MaxHelper(MaxHelper &&) =
default;
1050 MaxHelper(
const MaxHelper &) =
delete;
1051 MaxHelper(
const std::shared_ptr<ResultType> &maxVPtr,
const unsigned int nSlots)
1052 : fResultMax(maxVPtr), fMaxs(nSlots, std::numeric_limits<ResultType>::lowest())
1057 void Exec(
unsigned int slot, ResultType
v) { fMaxs[slot] = std::max(
v, fMaxs[slot]); }
1059 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
1060 void Exec(
unsigned int slot,
const T &vs)
1063 fMaxs[slot] = std::
max(static_cast<ResultType>(
v), fMaxs[slot]);
1070 *fResultMax = std::numeric_limits<ResultType>::lowest();
1071 for (
auto &
m : fMaxs) {
1072 *fResultMax = std::max(
m, *fResultMax);
1079 return std::make_unique<RMergeableMax<ResultType>>(*fResultMax);
1082 ResultType &PartialUpdate(
unsigned int slot) {
return fMaxs[slot]; }
1084 std::string GetActionName() {
return "Max"; }
1086 MaxHelper MakeNew(
void *newResult)
1088 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(newResult);
1089 return MaxHelper(
result, fMaxs.size());
1093template <
typename ResultType>
1094class R__CLING_PTRCHECK(off) SumHelper :
public RActionImpl<SumHelper<ResultType>> {
1095 std::shared_ptr<ResultType> fResultSum;
1096 Results<ResultType> fSums;
1097 Results<ResultType> fCompensations;
1102 template <
typename T = ResultType>
1103 auto NeutralElement(
const T &
v,
int ) ->
decltype(
v -
v)
1108 template <
typename T = ResultType,
typename Dummy =
int>
1109 ResultType NeutralElement(
const T &, Dummy)
1111 return ResultType{};
1115 SumHelper(SumHelper &&) =
default;
1116 SumHelper(
const SumHelper &) =
delete;
1117 SumHelper(
const std::shared_ptr<ResultType> &sumVPtr,
const unsigned int nSlots)
1118 : fResultSum(sumVPtr), fSums(nSlots, NeutralElement(*sumVPtr, -1)),
1119 fCompensations(nSlots, NeutralElement(*sumVPtr, -1))
1124 void Exec(
unsigned int slot, ResultType
x)
1127 ResultType
y =
x - fCompensations[slot];
1128 ResultType t = fSums[slot] +
y;
1129 fCompensations[slot] = (t - fSums[slot]) -
y;
1133 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
1134 void Exec(
unsigned int slot,
const T &vs)
1136 for (
auto &&
v : vs) {
1145 ResultType
sum(NeutralElement(ResultType{}, -1));
1146 ResultType compensation(NeutralElement(ResultType{}, -1));
1147 ResultType
y(NeutralElement(ResultType{}, -1));
1148 ResultType t(NeutralElement(ResultType{}, -1));
1149 for (
auto &
m : fSums) {
1151 y =
m - compensation;
1153 compensation = (t -
sum) -
y;
1162 return std::make_unique<RMergeableSum<ResultType>>(*fResultSum);
1165 ResultType &PartialUpdate(
unsigned int slot) {
return fSums[slot]; }
1167 std::string GetActionName() {
return "Sum"; }
1169 SumHelper MakeNew(
void *newResult)
1171 auto &
result = *
static_cast<std::shared_ptr<ResultType> *
>(newResult);
1173 return SumHelper(
result, fSums.size());
1177class R__CLING_PTRCHECK(off) MeanHelper :
public RActionImpl<MeanHelper> {
1178 std::shared_ptr<double> fResultMean;
1179 std::vector<ULong64_t> fCounts;
1180 std::vector<double> fSums;
1181 std::vector<double> fPartialMeans;
1182 std::vector<double> fCompensations;
1185 MeanHelper(
const std::shared_ptr<double> &meanVPtr,
const unsigned int nSlots);
1186 MeanHelper(MeanHelper &&) =
default;
1187 MeanHelper(
const MeanHelper &) =
delete;
1189 void Exec(
unsigned int slot,
double v);
1191 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
1192 void Exec(
unsigned int slot,
const T &vs)
1194 for (
auto &&
v : vs) {
1198 double y =
v - fCompensations[slot];
1199 double t = fSums[slot] +
y;
1200 fCompensations[slot] = (t - fSums[slot]) -
y;
1212 const ULong64_t counts = std::accumulate(fCounts.begin(), fCounts.end(), 0ull);
1213 return std::make_unique<RMergeableMean>(*fResultMean, counts);
1216 double &PartialUpdate(
unsigned int slot);
1218 std::string GetActionName() {
return "Mean"; }
1220 MeanHelper MakeNew(
void *newResult)
1222 auto &
result = *
static_cast<std::shared_ptr<double> *
>(newResult);
1223 return MeanHelper(
result, fSums.size());
1227class R__CLING_PTRCHECK(off) StdDevHelper :
public RActionImpl<StdDevHelper> {
1229 unsigned int fNSlots;
1230 std::shared_ptr<double> fResultStdDev;
1232 std::vector<ULong64_t> fCounts;
1234 std::vector<double> fMeans;
1236 std::vector<double> fDistancesfromMean;
1239 StdDevHelper(
const std::shared_ptr<double> &meanVPtr,
const unsigned int nSlots);
1240 StdDevHelper(StdDevHelper &&) =
default;
1241 StdDevHelper(
const StdDevHelper &) =
delete;
1243 void Exec(
unsigned int slot,
double v);
1245 template <typename T, std::enable_if_t<IsDataContainer<T>::value,
int> = 0>
1246 void Exec(
unsigned int slot,
const T &vs)
1248 for (
auto &&
v : vs) {
1260 const ULong64_t counts = std::accumulate(fCounts.begin(), fCounts.end(), 0ull);
1262 std::inner_product(fMeans.begin(), fMeans.end(), fCounts.begin(), 0.) /
static_cast<Double_t>(counts);
1263 return std::make_unique<RMergeableStdDev>(*fResultStdDev, counts, mean);
1266 std::string GetActionName() {
return "StdDev"; }
1268 StdDevHelper MakeNew(
void *newResult)
1270 auto &
result = *
static_cast<std::shared_ptr<double> *
>(newResult);
1271 return StdDevHelper(
result, fCounts.size());
1275template <
typename PrevNodeType>
1276class R__CLING_PTRCHECK(off) DisplayHelper :
public RActionImpl<DisplayHelper<PrevNodeType>> {
1279 std::shared_ptr<Display_t> fDisplayerHelper;
1280 std::shared_ptr<PrevNodeType> fPrevNode;
1281 size_t fEntriesToProcess;
1284 DisplayHelper(
size_t nRows,
const std::shared_ptr<Display_t> &
d,
const std::shared_ptr<PrevNodeType> &prevNode)
1285 : fDisplayerHelper(
d), fPrevNode(prevNode), fEntriesToProcess(nRows)
1288 DisplayHelper(DisplayHelper &&) =
default;
1289 DisplayHelper(
const DisplayHelper &) =
delete;
1292 template <
typename...
Columns>
1293 void Exec(
unsigned int, Columns &... columns)
1295 if (fEntriesToProcess == 0)
1298 fDisplayerHelper->AddRow(columns...);
1299 --fEntriesToProcess;
1301 if (fEntriesToProcess == 0) {
1306 fPrevNode->StopProcessing();
1314 std::string GetActionName() {
return "Display"; }
1317template <
typename T>
1323template <
typename T>
1329template <
typename T>
1330void SetBranchesHelper(
TTree *inputTree,
TTree &outputTree,
const std::string &inName,
const std::string &
name,
1331 TBranch *&branch,
void *&branchAddress, T *address, RBranchSet &outputBranches,
1334 static TClassRef TBOClRef(
"TBranchObject");
1336 TBranch *inputBranch =
nullptr;
1338 inputBranch = inputTree->
GetBranch(inName.c_str());
1340 inputBranch = inputTree->
FindBranch(inName.c_str());
1343 auto *outputBranch = outputBranches.Get(
name);
1346 if (inputBranch && inputBranch->
IsA() == TBOClRef) {
1347 outputBranch->SetAddress(
reinterpret_cast<T **
>(inputBranch->
GetAddress()));
1349 branchAddress = address;
1350 outputBranch->SetAddress(&branchAddress);
1352 outputBranch->SetAddress(address);
1353 branchAddress = address;
1366 if (inputBranch->
IsA() == TBOClRef) {
1369 outputTree.
Branch(
name.c_str(),
reinterpret_cast<T **
>(inputBranch->
GetAddress()), bufSize, splitLevel);
1371 outputBranch = outputTree.
Branch(
name.c_str(), address, bufSize, splitLevel);
1374 outputBranch = outputTree.
Branch(
name.c_str(), address);
1376 outputBranches.Insert(
name, outputBranch);
1379 branchAddress =
nullptr;
1392template <
typename T>
1393void SetBranchesHelper(
TTree *inputTree,
TTree &outputTree,
const std::string &inName,
const std::string &outName,
1394 TBranch *&branch,
void *&branchAddress,
RVec<T> *ab, RBranchSet &outputBranches,
bool isDefine)
1396 TBranch *inputBranch =
nullptr;
1398 inputBranch = inputTree->
GetBranch(inName.c_str());
1400 inputBranch = inputTree->
FindBranch(inName.c_str());
1402 auto *outputBranch = outputBranches.Get(outName);
1405 bool mustWriteRVec = (inputBranch ==
nullptr || isDefine);
1407 if (!mustWriteRVec && std::string_view(inputBranch->
GetClassName()) ==
"TClonesArray") {
1408 mustWriteRVec =
true;
1410 "Branch \"%s\" contains TClonesArrays but the type specified to Snapshot was RVec<T>. The branch will "
1411 "be written out as a RVec instead of a TClonesArray. Specify that the type of the branch is "
1412 "TClonesArray as a Snapshot template parameter to write out a TClonesArray instead.",
1416 if (!mustWriteRVec) {
1419 mustWriteRVec =
true;
1422 if (mustWriteRVec) {
1429 outputBranch->SetObject(ab);
1431 auto *
b = outputTree.
Branch(outName.c_str(), ab);
1432 outputBranches.Insert(outName,
b);
1438 auto dataPtr = ab->
data();
1442 branchAddress = dataPtr;
1443 outputBranch->SetAddress(&branchAddress);
1445 outputBranch->SetAddress(dataPtr);
1450 const auto bname = leaf->
GetName();
1451 auto *sizeLeaf = leaf->GetLeafCount();
1452 const auto sizeLeafName = sizeLeaf ? std::string(sizeLeaf->GetName()) : std::to_string(leaf->GetLenStatic());
1454 if (sizeLeaf && !outputBranches.Get(sizeLeafName)) {
1459 const auto sizeBufSize = sizeLeaf->GetBranch()->GetBasketSize();
1461 auto *sizeBranch = outputTree.
Branch(sizeLeafName.c_str(), (
void *)
nullptr,
1462 (sizeLeafName +
'/' + sizeTypeStr).c_str(), sizeBufSize);
1463 outputBranches.Insert(sizeLeafName, sizeBranch);
1466 const auto btype = leaf->GetTypeName();
1468 if (rootbtype ==
' ') {
1470 "RDataFrame::Snapshot: could not correctly construct a leaflist for C-style array in column %s. This "
1471 "column will not be written out.",
1474 const auto leaflist = std::string(bname) +
"[" + sizeLeafName +
"]/" + rootbtype;
1475 outputBranch = outputTree.
Branch(outName.c_str(), dataPtr, leaflist.c_str());
1477 outputBranches.Insert(outName, outputBranch);
1478 branch = outputBranch;
1479 branchAddress = ab->
data();
1487template <
typename... ColTypes>
1488class R__CLING_PTRCHECK(off) SnapshotHelper :
public RActionImpl<SnapshotHelper<ColTypes...>> {
1489 std::string fFileName;
1490 std::string fDirName;
1491 std::string fTreeName;
1493 std::unique_ptr<TFile> fOutputFile;
1494 std::unique_ptr<TTree> fOutputTree;
1495 bool fBranchAddressesNeedReset{
true};
1498 TTree *fInputTree =
nullptr;
1500 std::vector<TBranch *> fBranches;
1501 std::vector<void *> fBranchAddresses;
1502 RBranchSet fOutputBranches;
1503 std::vector<bool> fIsDefine;
1506 using ColumnTypes_t =
TypeList<ColTypes...>;
1507 SnapshotHelper(std::string_view
filename, std::string_view dirname, std::string_view treename,
1509 std::vector<bool> &&isDefine)
1510 : fFileName(
filename), fDirName(dirname), fTreeName(treename), fOptions(options), fInputBranchNames(vbnames),
1512 fBranchAddresses(vbnames.
size(), nullptr), fIsDefine(std::move(isDefine))
1517 SnapshotHelper(
const SnapshotHelper &) =
delete;
1518 SnapshotHelper(SnapshotHelper &&) =
default;
1521 if (!fTreeName.empty() && !fOutputFile && fOptions.
fLazy)
1522 Warning(
"Snapshot",
"A lazy Snapshot action was booked but never triggered.");
1528 fInputTree =
r->GetTree();
1529 fBranchAddressesNeedReset =
true;
1532 void Exec(
unsigned int , ColTypes &... values)
1534 using ind_t = std::index_sequence_for<ColTypes...>;
1535 if (!fBranchAddressesNeedReset) {
1536 UpdateCArraysPtrs(values..., ind_t{});
1538 SetBranches(values..., ind_t{});
1539 fBranchAddressesNeedReset =
false;
1541 fOutputTree->Fill();
1544 template <std::size_t...
S>
1545 void UpdateCArraysPtrs(ColTypes &... values, std::index_sequence<S...> )
1553 int expander[] = {(fBranches[
S] && fBranchAddresses[
S] != GetData(values)
1554 ? fBranches[
S]->SetAddress(GetData(values)),
1555 fBranchAddresses[
S] = GetData(values), 0 : 0, 0)...,
1560 template <std::size_t...
S>
1561 void SetBranches(ColTypes &... values, std::index_sequence<S...> )
1564 int expander[] = {(SetBranchesHelper(fInputTree, *fOutputTree, fInputBranchNames[S], fOutputBranchNames[S],
1565 fBranches[S], fBranchAddresses[S], &values, fOutputBranches, fIsDefine[S]),
1568 fOutputBranches.AssertNoNullBranchAddresses();
1578 throw std::runtime_error(
"Snapshot: could not create output file " + fFileName);
1581 if (!fDirName.empty()) {
1584 if (checkupdate ==
"update")
1585 outputDir = fOutputFile->
mkdir(fDirName.c_str(),
"",
true);
1587 outputDir = fOutputFile->
mkdir(fDirName.c_str());
1591 std::make_unique<TTree>(fTreeName.c_str(), fTreeName.c_str(), fOptions.
fSplitLevel, outputDir);
1594 fOutputTree->SetAutoFlush(fOptions.
fAutoFlush);
1599 assert(fOutputTree !=
nullptr);
1600 assert(fOutputFile !=
nullptr);
1603 fOutputTree->AutoSave(
"flushbaskets");
1605 fOutputTree.reset();
1606 fOutputFile->Close();
1609 std::string GetActionName() {
return "Snapshot"; }
1613 return [
this](
unsigned int,
const RSampleInfo &)
mutable { fBranchAddressesNeedReset =
true; };
1627 SnapshotHelper MakeNew(
void *newName)
1629 const std::string finalName = *
reinterpret_cast<const std::string *
>(newName);
1630 return SnapshotHelper{
1631 finalName, fDirName, fTreeName, fInputBranchNames, fOutputBranchNames, fOptions, std::vector<bool>(fIsDefine)};
1636template <
typename... ColTypes>
1637class R__CLING_PTRCHECK(off) SnapshotHelperMT :
public RActionImpl<SnapshotHelperMT<ColTypes...>> {
1638 unsigned int fNSlots;
1639 std::unique_ptr<ROOT::TBufferMerger> fMerger;
1640 std::vector<std::shared_ptr<ROOT::TBufferMergerFile>> fOutputFiles;
1641 std::vector<std::unique_ptr<TTree>> fOutputTrees;
1642 std::vector<int> fBranchAddressesNeedReset;
1643 std::string fFileName;
1644 std::string fDirName;
1645 std::string fTreeName;
1649 std::vector<TTree *> fInputTrees;
1651 std::vector<std::vector<TBranch *>> fBranches;
1653 std::vector<std::vector<void *>> fBranchAddresses;
1654 std::vector<RBranchSet> fOutputBranches;
1655 std::vector<bool> fIsDefine;
1658 using ColumnTypes_t =
TypeList<ColTypes...>;
1659 SnapshotHelperMT(
const unsigned int nSlots, std::string_view
filename, std::string_view dirname,
1662 : fNSlots(nSlots), fOutputFiles(fNSlots), fOutputTrees(fNSlots), fBranchAddressesNeedReset(fNSlots, 1),
1663 fFileName(
filename), fDirName(dirname), fTreeName(treename), fOptions(options), fInputBranchNames(vbnames),
1665 fBranches(fNSlots, std::vector<
TBranch *>(vbnames.
size(), nullptr)),
1666 fBranchAddresses(fNSlots, std::vector<
void *>(vbnames.
size(), nullptr)), fOutputBranches(fNSlots),
1667 fIsDefine(std::move(isDefine))
1671 SnapshotHelperMT(
const SnapshotHelperMT &) =
delete;
1672 SnapshotHelperMT(SnapshotHelperMT &&) =
default;
1675 if (!fTreeName.empty() && fOptions.
fLazy && !fOutputFiles.empty() &&
1676 std::all_of(fOutputFiles.begin(), fOutputFiles.end(), [](
const auto &
f) { return !f; }) )
1677 Warning(
"Snapshot",
"A lazy Snapshot action was booked but never triggered.");
1683 if (!fOutputFiles[slot]) {
1685 fOutputFiles[slot] = fMerger->GetFile();
1687 TDirectory *treeDirectory = fOutputFiles[slot].get();
1688 if (!fDirName.empty()) {
1690 treeDirectory = fOutputFiles[slot]->
mkdir(fDirName.c_str(),
"",
true);
1694 fOutputTrees[slot] =
1695 std::make_unique<TTree>(fTreeName.c_str(), fTreeName.c_str(), fOptions.
fSplitLevel, treeDirectory);
1698 fOutputTrees[slot]->SetImplicitMT(
false);
1700 fOutputTrees[slot]->SetAutoFlush(fOptions.
fAutoFlush);
1703 fInputTrees[slot] =
r->GetTree();
1705 fBranchAddressesNeedReset[slot] = 1;
1708 void FinalizeTask(
unsigned int slot)
1710 if (fOutputTrees[slot]->GetEntries() > 0)
1711 fOutputFiles[slot]->Write();
1713 fOutputTrees[slot].reset(
nullptr);
1714 fOutputBranches[slot].Clear();
1717 void Exec(
unsigned int slot, ColTypes &... values)
1719 using ind_t = std::index_sequence_for<ColTypes...>;
1720 if (fBranchAddressesNeedReset[slot] == 0) {
1721 UpdateCArraysPtrs(slot, values..., ind_t{});
1723 SetBranches(slot, values..., ind_t{});
1724 fBranchAddressesNeedReset[slot] = 0;
1726 fOutputTrees[slot]->Fill();
1727 auto entries = fOutputTrees[slot]->GetEntries();
1728 auto autoFlush = fOutputTrees[slot]->GetAutoFlush();
1729 if ((autoFlush > 0) && (entries % autoFlush == 0))
1730 fOutputFiles[slot]->Write();
1733 template <std::size_t...
S>
1734 void UpdateCArraysPtrs(
unsigned int slot, ColTypes &... values, std::index_sequence<S...> )
1742 int expander[] = {(fBranches[slot][
S] && fBranchAddresses[slot][
S] != GetData(values)
1743 ? fBranches[slot][
S]->SetAddress(GetData(values)),
1744 fBranchAddresses[slot][
S] = GetData(values), 0 : 0, 0)...,
1750 template <std::size_t...
S>
1751 void SetBranches(
unsigned int slot, ColTypes &... values, std::index_sequence<S...> )
1754 int expander[] = {(SetBranchesHelper(fInputTrees[slot], *fOutputTrees[slot], fInputBranchNames[S],
1755 fOutputBranchNames[S], fBranches[slot][S], fBranchAddresses[slot][S],
1756 &values, fOutputBranches[slot], fIsDefine[S]),
1759 fOutputBranches[slot].AssertNoNullBranchAddresses();
1766 auto out_file =
TFile::Open(fFileName.c_str(), fOptions.
fMode.c_str(), fFileName.c_str(), cs);
1768 throw std::runtime_error(
"Snapshot: could not create output file " + fFileName);
1769 fMerger = std::make_unique<ROOT::TBufferMerger>(std::unique_ptr<TFile>(out_file));
1774 assert(std::any_of(fOutputFiles.begin(), fOutputFiles.end(), [](
const auto &ptr) { return ptr != nullptr; }));
1776 auto fileWritten =
false;
1777 for (
auto &file : fOutputFiles) {
1787 "No input entries (input TTree was empty or no entry passed the Filters). Output TTree is empty.");
1791 fOutputFiles.clear();
1795 std::string GetActionName() {
return "Snapshot"; }
1799 return [
this](
unsigned int slot,
const RSampleInfo &)
mutable { fBranchAddressesNeedReset[slot] = 1; };
1813 SnapshotHelperMT MakeNew(
void *newName)
1815 const std::string finalName = *
reinterpret_cast<const std::string *
>(newName);
1816 return SnapshotHelperMT{fNSlots, finalName, fDirName, fTreeName,
1817 fInputBranchNames, fOutputBranchNames, fOptions, std::vector<bool>(fIsDefine)};
1821template <
typename Acc,
typename Merge,
typename R,
typename T,
typename U,
1822 bool MustCopyAssign = std::is_same<R, U>::value>
1823class R__CLING_PTRCHECK(off) AggregateHelper
1824 :
public RActionImpl<AggregateHelper<Acc, Merge, R, T, U, MustCopyAssign>> {
1827 std::shared_ptr<U> fResult;
1828 Results<U> fAggregators;
1833 AggregateHelper(Acc &&
f, Merge &&
m,
const std::shared_ptr<U> &
result,
const unsigned int nSlots)
1834 : fAggregate(std::move(
f)), fMerge(std::move(
m)), fResult(
result), fAggregators(nSlots, *
result)
1838 AggregateHelper(Acc &
f, Merge &
m,
const std::shared_ptr<U> &
result,
const unsigned int nSlots)
1839 : fAggregate(
f), fMerge(
m), fResult(
result), fAggregators(nSlots, *
result)
1843 AggregateHelper(AggregateHelper &&) =
default;
1844 AggregateHelper(
const AggregateHelper &) =
delete;
1848 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<MustCopyAssign_,
int> = 0>
1849 void Exec(
unsigned int slot,
const T &
value)
1851 fAggregators[slot] = fAggregate(fAggregators[slot],
value);
1854 template <
bool MustCopyAssign_ = MustCopyAssign, std::enable_if_t<!MustCopyAssign_,
int> = 0>
1855 void Exec(
unsigned int slot,
const T &
value)
1857 fAggregate(fAggregators[slot],
value);
1862 template <typename MergeRet = typename CallableTraits<Merge>::ret_type,
1863 bool MergeAll = std::is_same<void, MergeRet>::value>
1864 std::enable_if_t<MergeAll, void> Finalize()
1866 fMerge(fAggregators);
1867 *fResult = fAggregators[0];
1870 template <typename MergeRet = typename CallableTraits<Merge>::ret_type,
1871 bool MergeTwoByTwo = std::is_same<U, MergeRet>::value>
1872 std::enable_if_t<MergeTwoByTwo, void> Finalize(...)
1874 for (
const auto &acc : fAggregators)
1875 *fResult = fMerge(*fResult, acc);
1878 U &PartialUpdate(
unsigned int slot) {
return fAggregators[slot]; }
1880 std::string GetActionName() {
return "Aggregate"; }
1882 AggregateHelper MakeNew(
void *newResult)
1884 auto &
result = *
static_cast<std::shared_ptr<U> *
>(newResult);
1885 return AggregateHelper(fAggregate, fMerge,
result, fAggregators.size());
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
unsigned long long ULong64_t
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
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 r
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.
iterator begin() noexcept
pointer data() noexcept
Return a pointer to the vector's buffer, even if empty().
This class is the textual representation of the content of a columnar dataset.
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
typename RemoveFirstParameter< T >::type RemoveFirstParameter_t
A "std::vector"-like collection of values implementing handy operation to analyse them.
A TTree is a list of TBranches.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
virtual char * GetAddress() const
Int_t GetSplitLevel() const
TClass * IsA() const override
virtual Int_t GetBasketSize() const
TObjArray * GetListOfLeaves()
TClassRef is used to implement a permanent reference to a TClass object.
Collection abstract base class.
TDirectory::TContext keeps track and restore the current directory.
Describe directory structure in memory.
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
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.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
TObject * UncheckedAt(Int_t i) const
Statistical variable, defined by its mean and variance (RMS).
void ToLower()
Change string to lower-case.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
A TTree represents a columnar dataset.
virtual TBranch * FindBranch(const char *name)
Return the branch that correspond to the path 'branchname', which can include the name of the tree or...
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
@ kEntriesReshuffled
If set, signals that this TTree is the output of the processing of another TTree, and the entries are...
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 .
std::vector< std::string > ReplaceDotWithUnderscore(const std::vector< std::string > &columnNames)
Replace occurrences of '.
void ValidateSnapshotOutput(const RSnapshotOptions &opts, const std::string &treeName, const std::string &fileName)
char TypeName2ROOTTypeName(const std::string &b)
Convert type name (e.g.
constexpr std::size_t FindIdxTrue(const T &arr)
void(off) SmallVectorTemplateBase< T
std::vector< std::string > ColumnNames_t
std::function< void(unsigned int, const ROOT::RDF::RSampleInfo &)> SampleCallback_t
The type of a data-block callback, registered with an RDataFrame computation graph via e....
ROOT type_traits extensions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
int CompressionSettings(RCompressionSetting::EAlgorithm::EValues algorithm, int compressionLevel)
RooArgSet S(Args_t &&... args)
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
__device__ AFloat max(AFloat x, AFloat y)
void Initialize(Bool_t useTMVAStyle=kTRUE)
A collection of options to steer the creation of the dataset on file.
int fAutoFlush
AutoFlush value for output tree.
std::string fMode
Mode of creation of output file.
ECAlgo fCompressionAlgorithm
Compression algorithm of output file.
int fSplitLevel
Split level of output tree.
bool fLazy
Do not start the event loop when Snapshot is called.
int fCompressionLevel
Compression level of output file.
Lightweight storage for a collection of types.
static uint64_t sum(uint64_t i)