Logo ROOT  
Reference Guide
RLoopManager.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9#include "RConfigure.h" // R__USE_IMT
10#include "ROOT/RDataSource.hxx"
12#include "ROOT/InternalTreeUtils.hxx" // GetTreeFullPaths
19#include "ROOT/RLogger.hxx"
20#include "RtypesCore.h" // Long64_t
21#include "TStopwatch.h"
22#include "TBranchElement.h"
23#include "TBranchObject.h"
24#include "TChain.h"
25#include "TEntryList.h"
26#include "TFile.h"
27#include "TFriendElement.h"
28#include "TROOT.h" // IsImplicitMTEnabled
29#include "TTreeReader.h"
30#include "TTree.h" // For MaxTreeSizeRAII. Revert when #6640 will be solved.
31
32#ifdef R__USE_IMT
35#include "ROOT/RSlotStack.hxx"
36#endif
37
38#include <algorithm>
39#include <atomic>
40#include <cassert>
41#include <functional>
42#include <iostream>
43#include <memory>
44#include <stdexcept>
45#include <string>
46#include <sstream>
47#include <thread>
48#include <unordered_map>
49#include <vector>
50#include <set>
51#include <limits> // For MaxTreeSizeRAII. Revert when #6640 will be solved.
52
53using namespace ROOT::Detail::RDF;
54using namespace ROOT::Internal::RDF;
55
56namespace {
57/// A helper function that returns all RDF code that is currently scheduled for just-in-time compilation.
58/// This allows different RLoopManager instances to share these data.
59/// We want RLoopManagers to be able to add their code to a global "code to execute via cling",
60/// so that, lazily, we can jit everything that's needed by all RDFs in one go, which is potentially
61/// much faster than jitting each RLoopManager's code separately.
62static std::string &GetCodeToJit()
63{
64 static std::string code;
65 return code;
66}
67
68static bool ContainsLeaf(const std::set<TLeaf *> &leaves, TLeaf *leaf)
69{
70 return (leaves.find(leaf) != leaves.end());
71}
72
73///////////////////////////////////////////////////////////////////////////////
74/// This overload does not check whether the leaf/branch is already in bNamesReg. In case this is a friend leaf/branch,
75/// `allowDuplicates` controls whether we add both `friendname.bname` and `bname` or just the shorter version.
76static void InsertBranchName(std::set<std::string> &bNamesReg, ColumnNames_t &bNames, const std::string &branchName,
77 const std::string &friendName, bool allowDuplicates)
78{
79 if (!friendName.empty()) {
80 // In case of a friend tree, users might prepend its name/alias to the branch names
81 const auto friendBName = friendName + "." + branchName;
82 if (bNamesReg.insert(friendBName).second)
83 bNames.push_back(friendBName);
84 }
85
86 if (allowDuplicates || friendName.empty()) {
87 if (bNamesReg.insert(branchName).second)
88 bNames.push_back(branchName);
89 }
90}
91
92///////////////////////////////////////////////////////////////////////////////
93/// This overload makes sure that the TLeaf has not been already inserted.
94static void InsertBranchName(std::set<std::string> &bNamesReg, ColumnNames_t &bNames, const std::string &branchName,
95 const std::string &friendName, std::set<TLeaf *> &foundLeaves, TLeaf *leaf,
96 bool allowDuplicates)
97{
98 const bool canAdd = allowDuplicates ? true : !ContainsLeaf(foundLeaves, leaf);
99 if (!canAdd) {
100 return;
101 }
102
103 InsertBranchName(bNamesReg, bNames, branchName, friendName, allowDuplicates);
104
105 foundLeaves.insert(leaf);
106}
107
108static void ExploreBranch(TTree &t, std::set<std::string> &bNamesReg, ColumnNames_t &bNames, TBranch *b,
109 std::string prefix, std::string &friendName, bool allowDuplicates)
110{
111 for (auto sb : *b->GetListOfBranches()) {
112 TBranch *subBranch = static_cast<TBranch *>(sb);
113 auto subBranchName = std::string(subBranch->GetName());
114 auto fullName = prefix + subBranchName;
115
116 std::string newPrefix;
117 if (!prefix.empty())
118 newPrefix = fullName + ".";
119
120 ExploreBranch(t, bNamesReg, bNames, subBranch, newPrefix, friendName, allowDuplicates);
121
122 auto branchDirectlyFromTree = t.GetBranch(fullName.c_str());
123 if (!branchDirectlyFromTree)
124 branchDirectlyFromTree = t.FindBranch(fullName.c_str()); // try harder
125 if (branchDirectlyFromTree)
126 InsertBranchName(bNamesReg, bNames, std::string(branchDirectlyFromTree->GetFullName()), friendName,
127 allowDuplicates);
128
129 if (bNamesReg.find(subBranchName) == bNamesReg.end() && t.GetBranch(subBranchName.c_str()))
130 InsertBranchName(bNamesReg, bNames, subBranchName, friendName, allowDuplicates);
131 }
132}
133
134static void GetBranchNamesImpl(TTree &t, std::set<std::string> &bNamesReg, ColumnNames_t &bNames,
135 std::set<TTree *> &analysedTrees, std::string &friendName, bool allowDuplicates)
136{
137 std::set<TLeaf *> foundLeaves;
138 if (!analysedTrees.insert(&t).second) {
139 return;
140 }
141
142 const auto branches = t.GetListOfBranches();
143 // Getting the branches here triggered the read of the first file of the chain if t is a chain.
144 // We check if a tree has been successfully read, otherwise we throw (see ROOT-9984) to avoid further
145 // operations
146 if (!t.GetTree()) {
147 std::string err("GetBranchNames: error in opening the tree ");
148 err += t.GetName();
149 throw std::runtime_error(err);
150 }
151 if (branches) {
152 for (auto b : *branches) {
153 TBranch *branch = static_cast<TBranch *>(b);
154 const auto branchName = std::string(branch->GetName());
155 if (branch->IsA() == TBranch::Class()) {
156 // Leaf list
157 auto listOfLeaves = branch->GetListOfLeaves();
158 if (listOfLeaves->GetEntriesUnsafe() == 1) {
159 auto leaf = static_cast<TLeaf *>(listOfLeaves->UncheckedAt(0));
160 InsertBranchName(bNamesReg, bNames, branchName, friendName, foundLeaves, leaf, allowDuplicates);
161 }
162
163 for (auto leaf : *listOfLeaves) {
164 auto castLeaf = static_cast<TLeaf *>(leaf);
165 const auto leafName = std::string(leaf->GetName());
166 const auto fullName = branchName + "." + leafName;
167 InsertBranchName(bNamesReg, bNames, fullName, friendName, foundLeaves, castLeaf, allowDuplicates);
168 }
169 } else if (branch->IsA() == TBranchObject::Class()) {
170 // TBranchObject
171 ExploreBranch(t, bNamesReg, bNames, branch, branchName + ".", friendName, allowDuplicates);
172 InsertBranchName(bNamesReg, bNames, branchName, friendName, allowDuplicates);
173 } else {
174 // TBranchElement
175 // Check if there is explicit or implicit dot in the name
176
177 bool dotIsImplied = false;
178 auto be = dynamic_cast<TBranchElement *>(b);
179 if (!be)
180 throw std::runtime_error("GetBranchNames: unsupported branch type");
181 // TClonesArray (3) and STL collection (4)
182 if (be->GetType() == 3 || be->GetType() == 4)
183 dotIsImplied = true;
184
185 if (dotIsImplied || branchName.back() == '.')
186 ExploreBranch(t, bNamesReg, bNames, branch, "", friendName, allowDuplicates);
187 else
188 ExploreBranch(t, bNamesReg, bNames, branch, branchName + ".", friendName, allowDuplicates);
189
190 InsertBranchName(bNamesReg, bNames, branchName, friendName, allowDuplicates);
191 }
192 }
193 }
194
195 // The list of friends needs to be accessed via GetTree()->GetListOfFriends()
196 // (and not via GetListOfFriends() directly), otherwise when `t` is a TChain we
197 // might not recover the list correctly (https://github.com/root-project/root/issues/6741).
198 auto friendTrees = t.GetTree()->GetListOfFriends();
199
200 if (!friendTrees)
201 return;
202
203 for (auto friendTreeObj : *friendTrees) {
204 auto friendTree = ((TFriendElement *)friendTreeObj)->GetTree();
205
206 std::string frName;
207 auto alias = t.GetFriendAlias(friendTree);
208 if (alias != nullptr)
209 frName = std::string(alias);
210 else
211 frName = std::string(friendTree->GetName());
212
213 GetBranchNamesImpl(*friendTree, bNamesReg, bNames, analysedTrees, frName, allowDuplicates);
214 }
215}
216
217static void ThrowIfNSlotsChanged(unsigned int nSlots)
218{
219 const auto currentSlots = RDFInternal::GetNSlots();
220 if (currentSlots != nSlots) {
221 std::string msg = "RLoopManager::Run: when the RDataFrame was constructed the number of slots required was " +
222 std::to_string(nSlots) + ", but when starting the event loop it was " +
223 std::to_string(currentSlots) + ".";
224 if (currentSlots > nSlots)
225 msg += " Maybe EnableImplicitMT() was called after the RDataFrame was constructed?";
226 else
227 msg += " Maybe DisableImplicitMT() was called after the RDataFrame was constructed?";
228 throw std::runtime_error(msg);
229 }
230}
231
232/**
233\struct MaxTreeSizeRAII
234\brief Scope-bound change of `TTree::fgMaxTreeSize`.
235
236This RAII object stores the current value result of `TTree::GetMaxTreeSize`,
237changes it to maximum at construction time and restores it back at destruction
238time. Needed for issue #6523 and should be reverted when #6640 will be solved.
239*/
240struct MaxTreeSizeRAII {
241 Long64_t fOldMaxTreeSize;
242
243 MaxTreeSizeRAII() : fOldMaxTreeSize(TTree::GetMaxTreeSize())
244 {
245 TTree::SetMaxTreeSize(std::numeric_limits<Long64_t>::max());
246 }
247
248 ~MaxTreeSizeRAII() { TTree::SetMaxTreeSize(fOldMaxTreeSize); }
249};
250
251struct DatasetLogInfo {
252 std::string fDataSet;
253 ULong64_t fRangeStart;
254 ULong64_t fRangeEnd;
255 unsigned int fSlot;
256};
257
258std::string LogRangeProcessing(const DatasetLogInfo &info)
259{
260 std::stringstream msg;
261 msg << "Processing " << info.fDataSet << ": entry range [" << info.fRangeStart << "," << info.fRangeEnd - 1
262 << "], using slot " << info.fSlot << " in thread " << std::this_thread::get_id() << '.';
263 return msg.str();
264}
265
266DatasetLogInfo TreeDatasetLogInfo(const TTreeReader &r, unsigned int slot)
267{
268 const auto tree = r.GetTree();
269 const auto chain = dynamic_cast<TChain *>(tree);
270 std::string what;
271 if (chain) {
272 auto files = chain->GetListOfFiles();
273 std::vector<std::string> treeNames;
274 std::vector<std::string> fileNames;
275 for (TObject *f : *files) {
276 treeNames.emplace_back(f->GetName());
277 fileNames.emplace_back(f->GetTitle());
278 }
279 what = "trees {";
280 for (const auto &t : treeNames) {
281 what += t + ",";
282 }
283 what.back() = '}';
284 what += " in files {";
285 for (const auto &f : fileNames) {
286 what += f + ",";
287 }
288 what.back() = '}';
289 } else {
290 assert(tree != nullptr); // to make clang-tidy happy
291 const auto treeName = tree->GetName();
292 what = std::string("tree \"") + treeName + "\"";
293 const auto file = tree->GetCurrentFile();
294 if (file)
295 what += std::string(" in file \"") + file->GetName() + "\"";
296 }
297 const auto entryRange = r.GetEntriesRange();
298 const ULong64_t end = entryRange.second == -1ll ? tree->GetEntries() : entryRange.second;
299 return {std::move(what), static_cast<ULong64_t>(entryRange.first), end, slot};
300}
301
302static auto MakeDatasetColReadersKey(const std::string &colName, const std::type_info &ti)
303{
304 // We use a combination of column name and column type name as the key because in some cases we might end up
305 // with concrete readers that use different types for the same column, e.g. std::vector and RVec here:
306 // df.Sum<vector<int>>("stdVectorBranch");
307 // df.Sum<RVecI>("stdVectorBranch");
308 return colName + ':' + ti.name();
309}
310} // anonymous namespace
311
312namespace ROOT {
313namespace Detail {
314namespace RDF {
315
316/// A RAII object that calls RLoopManager::CleanUpTask at destruction
319 unsigned int fArg;
321
322 RCallCleanUpTask(RLoopManager &lm, unsigned int arg = 0u, TTreeReader *reader = nullptr)
323 : fLoopManager(lm), fArg(arg), fReader(reader)
324 {
325 }
327};
328
329} // namespace RDF
330} // namespace Detail
331} // namespace ROOT
332
333///////////////////////////////////////////////////////////////////////////////
334/// Get all the branches names, including the ones of the friend trees
336{
337 std::set<std::string> bNamesSet;
338 ColumnNames_t bNames;
339 std::set<TTree *> analysedTrees;
340 std::string emptyFrName = "";
341 GetBranchNamesImpl(t, bNamesSet, bNames, analysedTrees, emptyFrName, allowDuplicates);
342 return bNames;
343}
344
345RLoopManager::RLoopManager(TTree *tree, const ColumnNames_t &defaultBranches)
346 : fTree(std::shared_ptr<TTree>(tree, [](TTree *) {})), fDefaultColumns(defaultBranches),
347 fNSlots(RDFInternal::GetNSlots()),
348 fLoopType(ROOT::IsImplicitMTEnabled() ? ELoopType::kROOTFilesMT : ELoopType::kROOTFiles),
349 fNewSampleNotifier(fNSlots), fSampleInfos(fNSlots), fDatasetColumnReaders(fNSlots)
350{
351}
352
354 : fNEmptyEntries(nEmptyEntries), fNSlots(RDFInternal::GetNSlots()),
355 fLoopType(ROOT::IsImplicitMTEnabled() ? ELoopType::kNoFilesMT : ELoopType::kNoFiles), fNewSampleNotifier(fNSlots),
356 fSampleInfos(fNSlots), fDatasetColumnReaders(fNSlots)
357{
358}
359
360RLoopManager::RLoopManager(std::unique_ptr<RDataSource> ds, const ColumnNames_t &defaultBranches)
361 : fDefaultColumns(defaultBranches), fNSlots(RDFInternal::GetNSlots()),
362 fLoopType(ROOT::IsImplicitMTEnabled() ? ELoopType::kDataSourceMT : ELoopType::kDataSource),
363 fDataSource(std::move(ds)), fNewSampleNotifier(fNSlots), fSampleInfos(fNSlots), fDatasetColumnReaders(fNSlots)
364{
365 fDataSource->SetNSlots(fNSlots);
366}
367
369 : fBeginEntry(spec.GetEntryRangeBegin()), fEndEntry(spec.GetEntryRangeEnd()),
370 fDatasetGroups(spec.MoveOutDatasetGroups()), fNSlots(RDFInternal::GetNSlots()),
371 fLoopType(ROOT::IsImplicitMTEnabled() ? ELoopType::kROOTFilesMT : ELoopType::kROOTFiles),
372 fNewSampleNotifier(fNSlots), fSampleInfos(fNSlots), fDatasetColumnReaders(fNSlots)
373{
374 auto chain = std::make_shared<TChain>("");
375 for (auto &group : fDatasetGroups) {
376 const auto &trees = group.GetTreeNames();
377 const auto &files = group.GetFileNameGlobs();
378 for (auto i = 0u; i < files.size(); ++i) {
379 const auto fullpath = files[i] + "/" + trees[i]; // TODO: use ?# once #11483 is solved
380 chain->Add(fullpath.c_str());
381 fDatasetGroupMap[fullpath] = &group;
382 }
383 }
384
385 SetTree(std::move(chain));
386
387 // Create the friends from the list of friends
388 const auto &friendInfo = spec.GetFriendInfo();
389 const auto &friendNames = friendInfo.fFriendNames;
390 const auto &friendFileNames = friendInfo.fFriendFileNames;
391 const auto &friendChainSubNames = friendInfo.fFriendChainSubNames;
392 const auto nFriends = friendNames.size();
393
394 for (auto i = 0u; i < nFriends; ++i) {
395 const auto &thisFriendName = friendNames[i].first;
396 const auto &thisFriendAlias = friendNames[i].second;
397 const auto &thisFriendFiles = friendFileNames[i];
398 const auto &thisFriendChainSubNames = friendChainSubNames[i];
399
400 // Build a friend chain
401 auto frChain = std::make_unique<TChain>(thisFriendName.c_str());
402 const auto nFileNames = friendFileNames[i].size();
403 if (thisFriendChainSubNames.empty()) {
404 // If there are no chain subnames, the friend was a TTree. It's safe
405 // to add to the chain the filename directly.
406 for (auto j = 0u; j < nFileNames; ++j) {
407 frChain->Add(thisFriendFiles[j].c_str());
408 }
409 } else {
410 // Otherwise, the new friend chain needs to be built using the nomenclature
411 // "filename/treename" as argument to `TChain::Add`
412 for (auto j = 0u; j < nFileNames; ++j) {
413 frChain->Add((thisFriendFiles[j] + "/" + thisFriendChainSubNames[j]).c_str());
414 }
415 }
416
417 // Make it friends with the main chain
418 fTree->AddFriend(frChain.get(), thisFriendAlias.c_str());
419 // the friend trees must have same lifetime as fTree
420 fFriends.emplace_back(std::move(frChain));
421 }
422}
423
424/// Run event loop with no source files, in parallel.
426{
427#ifdef R__USE_IMT
429 // Working with an empty tree.
430 // Evenly partition the entries according to fNSlots. Produce around 2 tasks per slot.
431 const auto nEntriesPerSlot = fNEmptyEntries / (fNSlots * 2);
432 auto remainder = fNEmptyEntries % (fNSlots * 2);
433 std::vector<std::pair<ULong64_t, ULong64_t>> entryRanges;
434 ULong64_t start = 0;
435 while (start < fNEmptyEntries) {
436 ULong64_t end = start + nEntriesPerSlot;
437 if (remainder > 0) {
438 ++end;
439 --remainder;
440 }
441 entryRanges.emplace_back(start, end);
442 start = end;
443 }
444
445 // Each task will generate a subrange of entries
446 auto genFunction = [this, &slotStack](const std::pair<ULong64_t, ULong64_t> &range) {
447 ROOT::Internal::RSlotStackRAII slotRAII(slotStack);
448 auto slot = slotRAII.fSlot;
449 RCallCleanUpTask cleanup(*this, slot);
450 InitNodeSlots(nullptr, slot);
451 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing({"an empty source", range.first, range.second, slot});
452 try {
453 UpdateSampleInfo(slot, range);
454 for (auto currEntry = range.first; currEntry < range.second; ++currEntry) {
455 RunAndCheckFilters(slot, currEntry);
456 }
457 } catch (...) {
458 // Error might throw in experiment frameworks like CMSSW
459 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
460 throw;
461 }
462 };
463
465 pool.Foreach(genFunction, entryRanges);
466
467#endif // not implemented otherwise
468}
469
470/// Run event loop with no source files, in sequence.
472{
473 InitNodeSlots(nullptr, 0);
474 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing({"an empty source", 0, fNEmptyEntries, 0u});
475 RCallCleanUpTask cleanup(*this);
476 try {
477 UpdateSampleInfo(/*slot*/0, {0, fNEmptyEntries});
478 for (ULong64_t currEntry = 0; currEntry < fNEmptyEntries && fNStopsReceived < fNChildren; ++currEntry) {
479 RunAndCheckFilters(0, currEntry);
480 }
481 } catch (...) {
482 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
483 throw;
484 }
485}
486
487/// Run event loop over one or multiple ROOT files, in parallel.
489{
490#ifdef R__USE_IMT
491 if (fEndEntry == fBeginEntry) // empty range => no work needed
492 return;
494 const auto &entryList = fTree->GetEntryList() ? *fTree->GetEntryList() : TEntryList();
495 auto tp = (fBeginEntry != 0 || fEndEntry != std::numeric_limits<Long64_t>::max())
496 ? std::make_unique<ROOT::TTreeProcessorMT>(*fTree, fNSlots, std::make_pair(fBeginEntry, fEndEntry))
497 : std::make_unique<ROOT::TTreeProcessorMT>(*fTree, entryList, fNSlots);
498
499 std::atomic<ULong64_t> entryCount(0ull);
500
501 tp->Process([this, &slotStack, &entryCount](TTreeReader &r) -> void {
502 ROOT::Internal::RSlotStackRAII slotRAII(slotStack);
503 auto slot = slotRAII.fSlot;
504 RCallCleanUpTask cleanup(*this, slot, &r);
505 InitNodeSlots(&r, slot);
506 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing(TreeDatasetLogInfo(r, slot));
507 const auto entryRange = r.GetEntriesRange(); // we trust TTreeProcessorMT to call SetEntriesRange
508 const auto nEntries = entryRange.second - entryRange.first;
509 auto count = entryCount.fetch_add(nEntries);
510 try {
511 // recursive call to check filters and conditionally execute actions
512 while (r.Next()) {
513 if (fNewSampleNotifier.CheckFlag(slot)) {
514 UpdateSampleInfo(slot, r);
515 }
516 RunAndCheckFilters(slot, count++);
517 }
518 } catch (...) {
519 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
520 throw;
521 }
522 // fNStopsReceived < fNChildren is always true at the moment as we don't support event loop early quitting in
523 // multi-thread runs, but it costs nothing to be safe and future-proof in case we add support for that later.
524 if (r.GetEntryStatus() != TTreeReader::kEntryBeyondEnd && fNStopsReceived < fNChildren) {
525 // something went wrong in the TTreeReader event loop
526 throw std::runtime_error("An error was encountered while processing the data. TTreeReader status code is: " +
527 std::to_string(r.GetEntryStatus()));
528 }
529 });
530#endif // no-op otherwise (will not be called)
531}
532
533/// Run event loop over one or multiple ROOT files, in sequence.
535{
536 TTreeReader r(fTree.get(), fTree->GetEntryList());
537 if (0 == fTree->GetEntriesFast() || fBeginEntry == fEndEntry)
538 return;
539 // Apply the range if there is any
540 // In case of a chain with a total of N entries, calling SetEntriesRange(N + 1, ...) does not error out
541 // This is a bug, reported here: https://github.com/root-project/root/issues/10774
542 if (fBeginEntry != 0 || fEndEntry != std::numeric_limits<Long64_t>::max())
543 if (r.SetEntriesRange(fBeginEntry, fEndEntry) != TTreeReader::kEntryValid)
544 throw std::logic_error("Something went wrong in initializing the TTreeReader.");
545
546 RCallCleanUpTask cleanup(*this, 0u, &r);
547 InitNodeSlots(&r, 0);
548 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing(TreeDatasetLogInfo(r, 0u));
549
550 // recursive call to check filters and conditionally execute actions
551 // in the non-MT case processing can be stopped early by ranges, hence the check on fNStopsReceived
552 try {
553 while (r.Next() && fNStopsReceived < fNChildren) {
555 UpdateSampleInfo(/*slot*/0, r);
556 }
557 RunAndCheckFilters(0, r.GetCurrentEntry());
558 }
559 } catch (...) {
560 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
561 throw;
562 }
563 if (r.GetEntryStatus() != TTreeReader::kEntryBeyondEnd && fNStopsReceived < fNChildren) {
564 // something went wrong in the TTreeReader event loop
565 throw std::runtime_error("An error was encountered while processing the data. TTreeReader status code is: " +
566 std::to_string(r.GetEntryStatus()));
567 }
568}
569
570/// Run event loop over data accessed through a DataSource, in sequence.
572{
573 assert(fDataSource != nullptr);
574 fDataSource->Initialize();
575 auto ranges = fDataSource->GetEntryRanges();
576 while (!ranges.empty() && fNStopsReceived < fNChildren) {
577 InitNodeSlots(nullptr, 0u);
578 fDataSource->InitSlot(0u, 0ull);
579 RCallCleanUpTask cleanup(*this);
580 try {
581 for (const auto &range : ranges) {
582 const auto start = range.first;
583 const auto end = range.second;
584 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing({fDataSource->GetLabel(), start, end, 0u});
585 for (auto entry = start; entry < end && fNStopsReceived < fNChildren; ++entry) {
586 if (fDataSource->SetEntry(0u, entry)) {
587 RunAndCheckFilters(0u, entry);
588 }
589 }
590 }
591 } catch (...) {
592 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
593 throw;
594 }
595 fDataSource->FinalizeSlot(0u);
596 ranges = fDataSource->GetEntryRanges();
597 }
598 fDataSource->Finalize();
599}
600
601/// Run event loop over data accessed through a DataSource, in parallel.
603{
604#ifdef R__USE_IMT
605 assert(fDataSource != nullptr);
608
609 // Each task works on a subrange of entries
610 auto runOnRange = [this, &slotStack](const std::pair<ULong64_t, ULong64_t> &range) {
611 ROOT::Internal::RSlotStackRAII slotRAII(slotStack);
612 const auto slot = slotRAII.fSlot;
613 InitNodeSlots(nullptr, slot);
614 RCallCleanUpTask cleanup(*this, slot);
615 fDataSource->InitSlot(slot, range.first);
616 const auto start = range.first;
617 const auto end = range.second;
618 R__LOG_DEBUG(0, RDFLogChannel()) << LogRangeProcessing({fDataSource->GetLabel(), start, end, slot});
619 try {
620 for (auto entry = start; entry < end; ++entry) {
621 if (fDataSource->SetEntry(slot, entry)) {
622 RunAndCheckFilters(slot, entry);
623 }
624 }
625 } catch (...) {
626 std::cerr << "RDataFrame::Run: event loop was interrupted\n";
627 throw;
628 }
629 fDataSource->FinalizeSlot(slot);
630 };
631
632 fDataSource->Initialize();
633 auto ranges = fDataSource->GetEntryRanges();
634 while (!ranges.empty()) {
635 pool.Foreach(runOnRange, ranges);
636 ranges = fDataSource->GetEntryRanges();
637 }
638 fDataSource->Finalize();
639#endif // not implemented otherwise (never called)
640}
641
642/// Execute actions and make sure named filters are called for each event.
643/// Named filters must be called even if the analysis logic would not require it, lest they report confusing results.
644void RLoopManager::RunAndCheckFilters(unsigned int slot, Long64_t entry)
645{
646 // data-block callbacks run before the rest of the graph
647 if (fNewSampleNotifier.CheckFlag(slot)) {
648 for (auto &callback : fSampleCallbacks)
649 callback.second(slot, fSampleInfos[slot]);
651 }
652
653 for (auto *actionPtr : fBookedActions)
654 actionPtr->Run(slot, entry);
655 for (auto *namedFilterPtr : fBookedNamedFilters)
656 namedFilterPtr->CheckFilters(slot, entry);
657 for (auto &callback : fCallbacks)
658 callback(slot);
659}
660
661/// Build TTreeReaderValues for all nodes
662/// This method loops over all filters, actions and other booked objects and
663/// calls their `InitSlot` method, to get them ready for running a task.
665{
666 SetupSampleCallbacks(r, slot);
667 for (auto *ptr : fBookedActions)
668 ptr->InitSlot(r, slot);
669 for (auto *ptr : fBookedFilters)
670 ptr->InitSlot(r, slot);
671 for (auto *ptr : fBookedDefines)
672 ptr->InitSlot(r, slot);
673 for (auto *ptr : fBookedVariations)
674 ptr->InitSlot(r, slot);
675
676 for (auto &callback : fCallbacksOnce)
677 callback(slot);
678}
679
681 if (r != nullptr) {
682 // we need to set a notifier so that we run the callbacks every time we switch to a new TTree
683 // `PrependLink` inserts this notifier into the TTree/TChain's linked list of notifiers
684 fNewSampleNotifier.GetChainNotifyLink(slot).PrependLink(*r->GetTree());
685 }
686 // Whatever the data source, initially set the "new data block" flag:
687 // - for TChains, this ensures that we don't skip the first data block because
688 // the correct tree is already loaded
689 // - for RDataSources and empty sources, which currently don't have data blocks, this
690 // ensures that we run once per task
692}
693
694void RLoopManager::UpdateSampleInfo(unsigned int slot, const std::pair<ULong64_t, ULong64_t> &range) {
696 "Empty source, range: {" + std::to_string(range.first) + ", " + std::to_string(range.second) + "}", range);
697}
698
700 // one GetTree to retrieve the TChain, another to retrieve the underlying TTree
701 auto *tree = r.GetTree()->GetTree();
702 R__ASSERT(tree != nullptr);
703 const std::string treename = ROOT::Internal::TreeUtils::GetTreeFullPaths(*tree)[0];
704 auto *file = tree->GetCurrentFile();
705 const std::string fname = file != nullptr ? file->GetName() : "#inmemorytree#";
706
707 std::pair<Long64_t, Long64_t> range = r.GetEntriesRange();
708 R__ASSERT(range.first >= 0);
709 if (range.second == -1) {
710 range.second = tree->GetEntries(); // convert '-1', i.e. 'until the end', to the actual entry number
711 }
712 const std::string &id = fname + "/" + treename;
713 fSampleInfos[slot] =
714 fDatasetGroupMap.empty() ? RSampleInfo(id, range) : RSampleInfo(id, range, fDatasetGroupMap[id]);
715}
716
717/// Initialize all nodes of the functional graph before running the event loop.
718/// This method is called once per event-loop and performs generic initialization
719/// operations that do not depend on the specific processing slot (i.e. operations
720/// that are common for all threads).
722{
724 for (auto *filter : fBookedFilters)
725 filter->InitNode();
726 for (auto *range : fBookedRanges)
727 range->InitNode();
728 for (auto *ptr : fBookedActions)
729 ptr->Initialize();
730}
731
732/// Perform clean-up operations. To be called at the end of each event loop.
734{
735 fMustRunNamedFilters = false;
736
737 // forget RActions and detach TResultProxies
738 for (auto *ptr : fBookedActions)
739 ptr->Finalize();
740
741 fRunActions.insert(fRunActions.begin(), fBookedActions.begin(), fBookedActions.end());
742 fBookedActions.clear();
743
744 // reset children counts
745 fNChildren = 0;
746 fNStopsReceived = 0;
747 for (auto *ptr : fBookedFilters)
748 ptr->ResetChildrenCount();
749 for (auto *ptr : fBookedRanges)
750 ptr->ResetChildrenCount();
751
752 fCallbacks.clear();
753 fCallbacksOnce.clear();
754 fSampleCallbacks.clear();
755}
756
757/// Perform clean-up operations. To be called at the end of each task execution.
758void RLoopManager::CleanUpTask(TTreeReader *r, unsigned int slot)
759{
760 if (r != nullptr)
761 fNewSampleNotifier.GetChainNotifyLink(slot).RemoveLink(*r->GetTree());
762 for (auto *ptr : fBookedActions)
763 ptr->FinalizeSlot(slot);
764 for (auto *ptr : fBookedFilters)
765 ptr->FinalizeSlot(slot);
766 for (auto *ptr : fBookedDefines)
767 ptr->FinalizeSlot(slot);
768
770 // we are reading from a tree/chain and we need to re-create the RTreeColumnReaders at every task
771 // because the TTreeReader object changes at every task
772 for (auto &v : fDatasetColumnReaders[slot])
773 v.second.reset();
774 }
775}
776
777/// Add RDF nodes that require just-in-time compilation to the computation graph.
778/// This method also clears the contents of GetCodeToJit().
780{
781 // TODO this should be a read lock unless we find GetCodeToJit non-empty
783
784 const std::string code = std::move(GetCodeToJit());
785 if (code.empty()) {
786 R__LOG_INFO(RDFLogChannel()) << "Nothing to jit and execute.";
787 return;
788 }
789
791 s.Start();
792 RDFInternal::InterpreterCalc(code, "RLoopManager::Run");
793 s.Stop();
794 R__LOG_INFO(RDFLogChannel()) << "Just-in-time compilation phase completed"
795 << (s.RealTime() > 1e-3 ? " in " + std::to_string(s.RealTime()) + " seconds."
796 : " in less than 1ms.");
797}
798
799/// Trigger counting of number of children nodes for each node of the functional graph.
800/// This is done once before starting the event loop. Each action sends an `increase children count` signal
801/// upstream, which is propagated until RLoopManager. Each time a node receives the signal, in increments its
802/// children counter. Each node only propagates the signal once, even if it receives it multiple times.
803/// Named filters also send an `increase children count` signal, just like actions, as they always execute during
804/// the event loop so the graph branch they belong to must count as active even if it does not end in an action.
806{
807 for (auto *actionPtr : fBookedActions)
808 actionPtr->TriggerChildrenCount();
809 for (auto *namedFilterPtr : fBookedNamedFilters)
810 namedFilterPtr->TriggerChildrenCount();
811}
812
813/// Start the event loop with a different mechanism depending on IMT/no IMT, data source/no data source.
814/// Also perform a few setup and clean-up operations (jit actions if necessary, clear booked actions after the loop...).
815/// The jitting phase is skipped if the `jit` parameter is `false` (unsafe, use with care).
816void RLoopManager::Run(bool jit)
817{
818 // Change value of TTree::GetMaxTreeSize only for this scope. Revert when #6640 will be solved.
819 MaxTreeSizeRAII ctxtmts;
820
821 R__LOG_INFO(RDFLogChannel()) << "Starting event loop number " << fNRuns << '.';
822
823 ThrowIfNSlotsChanged(GetNSlots());
824
825 if (jit)
826 Jit();
827
828 InitNodes();
829
831 s.Start();
832 switch (fLoopType) {
836 case ELoopType::kNoFiles: RunEmptySource(); break;
839 }
840 s.Stop();
841
842 CleanUpNodes();
843
844 fNRuns++;
845
846 R__LOG_INFO(RDFLogChannel()) << "Finished event loop number " << fNRuns - 1 << " (" << s.CpuTime() << "s CPU, "
847 << s.RealTime() << "s elapsed).";
848}
849
850/// Return the list of default columns -- empty if none was provided when constructing the RDataFrame
852{
853 return fDefaultColumns;
854}
855
857{
858 return fTree.get();
859}
860
862{
863 fBookedActions.emplace_back(actionPtr);
864 AddSampleCallback(actionPtr, actionPtr->GetSampleCallback());
865}
866
868{
871 fSampleCallbacks.erase(actionPtr);
872}
873
875{
876 fBookedFilters.emplace_back(filterPtr);
877 if (filterPtr->HasName()) {
878 fBookedNamedFilters.emplace_back(filterPtr);
880 }
881}
882
884{
887}
888
890{
891 fBookedRanges.emplace_back(rangePtr);
892}
893
895{
897}
898
900{
901 fBookedDefines.emplace_back(ptr);
902}
903
905{
907 fSampleCallbacks.erase(ptr);
908}
909
911{
912 fBookedVariations.emplace_back(v);
913}
914
916{
918}
919
920// dummy call, end of recursive chain of calls
922{
923 return true;
924}
925
926/// Call `FillReport` on all booked filters
928{
929 for (const auto *fPtr : fBookedNamedFilters)
930 fPtr->FillReport(rep);
931}
932
933void RLoopManager::SetTree(std::shared_ptr<TTree> tree)
934{
935 fTree = std::move(tree);
936
937 TChain *ch = nullptr;
938 if ((ch = dynamic_cast<TChain *>(fTree.get())))
940}
941
942void RLoopManager::ToJitExec(const std::string &code) const
943{
945 GetCodeToJit().append(code);
946}
947
948void RLoopManager::RegisterCallback(ULong64_t everyNEvents, std::function<void(unsigned int)> &&f)
949{
950 if (everyNEvents == 0ull)
951 fCallbacksOnce.emplace_back(std::move(f), fNSlots);
952 else
953 fCallbacks.emplace_back(everyNEvents, std::move(f), fNSlots);
954}
955
956std::vector<std::string> RLoopManager::GetFiltersNames()
957{
958 std::vector<std::string> filters;
959 for (auto *filter : fBookedFilters) {
960 auto name = (filter->HasName() ? filter->GetName() : "Unnamed Filter");
961 filters.push_back(name);
962 }
963 return filters;
964}
965
966std::vector<RNodeBase *> RLoopManager::GetGraphEdges() const
967{
968 std::vector<RNodeBase *> nodes(fBookedFilters.size() + fBookedRanges.size());
969 auto it = std::copy(fBookedFilters.begin(), fBookedFilters.end(), nodes.begin());
970 std::copy(fBookedRanges.begin(), fBookedRanges.end(), it);
971 return nodes;
972}
973
974std::vector<RDFInternal::RActionBase *> RLoopManager::GetAllActions() const
975{
976 std::vector<RDFInternal::RActionBase *> actions(fBookedActions.size() + fRunActions.size());
977 auto it = std::copy(fBookedActions.begin(), fBookedActions.end(), actions.begin());
978 std::copy(fRunActions.begin(), fRunActions.end(), it);
979 return actions;
980}
981
982std::shared_ptr<ROOT::Internal::RDF::GraphDrawing::GraphNode> RLoopManager::GetGraph(
983 std::unordered_map<void *, std::shared_ptr<ROOT::Internal::RDF::GraphDrawing::GraphNode>> &visitedMap)
984{
985 // If there is already a node for the RLoopManager return it. If there is not, return a new one.
986 auto duplicateRLoopManagerIt = visitedMap.find((void *)this);
987 if (duplicateRLoopManagerIt != visitedMap.end())
988 return duplicateRLoopManagerIt->second;
989
990 std::string name;
991 if (fDataSource) {
992 name = fDataSource->GetLabel();
993 } else if (fTree) {
994 name = fTree->GetName();
995 } else {
996 name = "Empty source\\nEntries: " + std::to_string(fNEmptyEntries);
997 }
998 auto thisNode = std::make_shared<ROOT::Internal::RDF::GraphDrawing::GraphNode>(
1000 visitedMap[(void *)this] = thisNode;
1001 return thisNode;
1002}
1003
1004////////////////////////////////////////////////////////////////////////////
1005/// Return all valid TTree::Branch names (caching results for subsequent calls).
1006/// Never use fBranchNames directy, always request it through this method.
1008{
1009 if (fValidBranchNames.empty() && fTree) {
1010 fValidBranchNames = RDFInternal::GetBranchNames(*fTree, /*allowRepetitions=*/true);
1011 }
1012 return fValidBranchNames;
1013}
1014
1015/// Return true if AddDataSourceColumnReaders was called for column name col.
1016bool RLoopManager::HasDataSourceColumnReaders(const std::string &col, const std::type_info &ti) const
1017{
1018 const auto key = MakeDatasetColReadersKey(col, ti);
1019 assert(fDataSource != nullptr);
1020 // since data source column readers are always added for all slots at the same time,
1021 // if the reader is present for slot 0 we have it for all other slots as well.
1022 return fDatasetColumnReaders[0].find(key) != fDatasetColumnReaders[0].end();
1023}
1024
1026 std::vector<std::unique_ptr<RColumnReaderBase>> &&readers,
1027 const std::type_info &ti)
1028{
1029 const auto key = MakeDatasetColReadersKey(col, ti);
1030 assert(fDataSource != nullptr && !HasDataSourceColumnReaders(col, ti));
1031 assert(readers.size() == fNSlots);
1032
1033 for (auto slot = 0u; slot < fNSlots; ++slot) {
1034 fDatasetColumnReaders[slot][key] = std::move(readers[slot]);
1035 }
1036}
1037
1038// Differently from AddDataSourceColumnReaders, this can be called from multiple threads concurrently
1039/// \brief Register a new RTreeColumnReader with this RLoopManager.
1040/// \return A shared pointer to the inserted column reader.
1041RColumnReaderBase *RLoopManager::AddTreeColumnReader(unsigned int slot, const std::string &col,
1042 std::unique_ptr<RColumnReaderBase> &&reader,
1043 const std::type_info &ti)
1044{
1045 auto &readers = fDatasetColumnReaders[slot];
1046 const auto key = MakeDatasetColReadersKey(col, ti);
1047 // if a reader for this column and this slot was already there, we are doing something wrong
1048 assert(readers.find(key) == readers.end() || readers[key] == nullptr);
1049 auto *rptr = reader.get();
1050 readers[key] = std::move(reader);
1051 return rptr;
1052}
1053
1055RLoopManager::GetDatasetColumnReader(unsigned int slot, const std::string &col, const std::type_info &ti) const
1056{
1057 const auto key = MakeDatasetColReadersKey(col, ti);
1058 auto it = fDatasetColumnReaders[slot].find(key);
1059 if (it != fDatasetColumnReaders[slot].end())
1060 return it->second.get();
1061 else
1062 return nullptr;
1063}
1064
1066{
1067 if (callback)
1068 fSampleCallbacks.insert({nodePtr, std::move(callback)});
1069}
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Definition: RLogger.hxx:365
#define R__LOG_INFO(...)
Definition: RLogger.hxx:364
#define f(i)
Definition: RSha256.hxx:104
#define e(i)
Definition: RSha256.hxx:103
long long Long64_t
Definition: RtypesCore.h:80
unsigned long long ULong64_t
Definition: RtypesCore.h:81
#define R__ASSERT(e)
Definition: TError.h:118
const char * filters[]
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 b
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
char name[80]
Definition: TGX11.cxx:110
R__EXTERN TVirtualMutex * gROOTMutex
Definition: TROOT.h:63
#define R__LOCKGUARD(mutex)
The head node of a RDF computation graph.
void UpdateSampleInfo(unsigned int slot, const std::pair< ULong64_t, ULong64_t > &range)
RLoopManager(TTree *tree, const ColumnNames_t &defaultBranches)
unsigned int fNRuns
Number of event loops run.
bool CheckFilters(unsigned int, Long64_t) final
void EvalChildrenCounts()
Trigger counting of number of children nodes for each node of the functional graph.
void CleanUpNodes()
Perform clean-up operations. To be called at the end of each event loop.
void RunEmptySource()
Run event loop with no source files, in sequence.
void Report(ROOT::RDF::RCutFlowReport &rep) const final
Call FillReport on all booked filters.
void AddSampleCallback(void *nodePtr, ROOT::RDF::SampleCallback_t &&callback)
std::vector< RFilterBase * > fBookedNamedFilters
Contains a subset of fBookedFilters, i.e. only the named filters.
void RunEmptySourceMT()
Run event loop with no source files, in parallel.
std::unordered_map< std::string, ROOT::RDF::Experimental::RDatasetGroup * > fDatasetGroupMap
Keys are fname + "/" + treename as RSampleInfo::fID; Values are pointers to the corresponding group.
std::shared_ptr< ROOT::Internal::RDF::GraphDrawing::GraphNode > GetGraph(std::unordered_map< void *, std::shared_ptr< ROOT::Internal::RDF::GraphDrawing::GraphNode > > &visitedMap) final
std::vector< ROOT::RDF::Experimental::RDatasetGroup > fDatasetGroups
Groups need to survive throughout the whole event loop, hence stored as an attribute.
const ColumnNames_t & GetBranchNames()
Return all valid TTree::Branch names (caching results for subsequent calls).
void ToJitExec(const std::string &) const
std::vector< RDFInternal::RActionBase * > GetAllActions() const
Return all actions, either booked or already run.
std::vector< ROOT::RDF::RSampleInfo > fSampleInfos
void SetTree(std::shared_ptr< TTree > tree)
std::shared_ptr< TTree > fTree
Shared pointer to the input TTree.
std::vector< std::unique_ptr< TTree > > fFriends
Friends of the fTree. Only used if we constructed fTree ourselves.
std::vector< RDefineBase * > fBookedDefines
void RunTreeReader()
Run event loop over one or multiple ROOT files, in sequence.
ROOT::Internal::TreeUtils::RNoCleanupNotifier fNoCleanupNotifier
std::vector< RDFInternal::RActionBase * > fRunActions
Non-owning pointers to actions already run.
RColumnReaderBase * GetDatasetColumnReader(unsigned int slot, const std::string &col, const std::type_info &ti) const
std::vector< RRangeBase * > fBookedRanges
std::vector< std::string > ColumnNames_t
void RunAndCheckFilters(unsigned int slot, Long64_t entry)
Execute actions and make sure named filters are called for each event.
std::vector< RFilterBase * > fBookedFilters
void Run(bool jit=true)
Start the event loop with a different mechanism depending on IMT/no IMT, data source/no data source.
std::unordered_map< void *, ROOT::RDF::SampleCallback_t > fSampleCallbacks
Registered callbacks to call at the beginning of each "data block".
std::vector< RDFInternal::RActionBase * > fBookedActions
Non-owning pointers to actions to be run.
std::vector< RDFInternal::RCallback > fCallbacks
Registered callbacks.
RColumnReaderBase * AddTreeColumnReader(unsigned int slot, const std::string &col, std::unique_ptr< RColumnReaderBase > &&reader, const std::type_info &ti)
Register a new RTreeColumnReader with this RLoopManager.
const ELoopType fLoopType
The kind of event loop that is going to be run (e.g. on ROOT files, on no files)
void AddDataSourceColumnReaders(const std::string &col, std::vector< std::unique_ptr< RColumnReaderBase > > &&readers, const std::type_info &ti)
void SetupSampleCallbacks(TTreeReader *r, unsigned int slot)
ColumnNames_t fValidBranchNames
Cache of the tree/chain branch names. Never access directy, always use GetBranchNames().
void CleanUpTask(TTreeReader *r, unsigned int slot)
Perform clean-up operations. To be called at the end of each task execution.
std::vector< std::unordered_map< std::string, std::unique_ptr< RColumnReaderBase > > > fDatasetColumnReaders
Readers for TTree/RDataSource columns (one per slot), shared by all nodes in the computation graph.
void Register(RDFInternal::RActionBase *actionPtr)
const ColumnNames_t & GetDefaultColumnNames() const
Return the list of default columns – empty if none was provided when constructing the RDataFrame.
std::vector< RDFInternal::RVariationBase * > fBookedVariations
std::vector< RNodeBase * > GetGraphEdges() const
Return all graph edges known to RLoopManager This includes Filters and Ranges but not Defines.
unsigned int GetNSlots() const
void RunDataSourceMT()
Run event loop over data accessed through a DataSource, in parallel.
std::vector< std::string > GetFiltersNames()
For each booked filter, returns either the name or "Unnamed Filter".
const std::unique_ptr< RDataSource > fDataSource
Owning pointer to a data-source object. Null if no data-source.
RDFInternal::RNewSampleNotifier fNewSampleNotifier
const ColumnNames_t fDefaultColumns
void InitNodeSlots(TTreeReader *r, unsigned int slot)
Build TTreeReaderValues for all nodes This method loops over all filters, actions and other booked ob...
std::vector< RDFInternal::ROneTimeCallback > fCallbacksOnce
Registered callbacks to invoke just once before running the loop.
void RegisterCallback(ULong64_t everyNEvents, std::function< void(unsigned int)> &&f)
void RunDataSource()
Run event loop over data accessed through a DataSource, in sequence.
void Jit()
Add RDF nodes that require just-in-time compilation to the computation graph.
void RunTreeProcessorMT()
Run event loop over one or multiple ROOT files, in parallel.
void Deregister(RDFInternal::RActionBase *actionPtr)
void InitNodes()
Initialize all nodes of the functional graph before running the event loop.
bool HasDataSourceColumnReaders(const std::string &col, const std::type_info &ti) const
Return true if AddDataSourceColumnReaders was called for column name col.
unsigned int fNStopsReceived
Number of times that a children node signaled to stop processing entries.
Definition: RNodeBase.hxx:47
unsigned int fNChildren
Number of nodes of the functional graph hanging from this object.
Definition: RNodeBase.hxx:46
virtual ROOT::RDF::SampleCallback_t GetSampleCallback()=0
bool CheckFlag(unsigned int slot) const
TNotifyLink< RNewSampleFlag > & GetChainNotifyLink(unsigned int slot)
This type includes all parts of RVariation that do not depend on the callable signature.
A thread-safe stack of N indexes (0 to size - 1).
Definition: RSlotStack.hxx:30
A dataset specification for RDataFrame.
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
Definition: RSampleInfo.hxx:35
This class provides a simple interface to execute the same task multiple times in parallel threads,...
void Foreach(F func, unsigned nTimes, unsigned nChunks=0)
Execute a function without arguments several times in parallel, dividing the execution in nChunks.
A Branch for the case of an object.
static TClass * Class()
A TTree is a list of TBranches.
Definition: TBranch.h:89
static TClass * Class()
TClass * IsA() const override
Definition: TBranch.h:291
TObjArray * GetListOfLeaves()
Definition: TBranch.h:243
A chain is a collection of files containing TTree objects.
Definition: TChain.h:33
A List of entry numbers in a TTree or TChain.
Definition: TEntryList.h:26
A TFriendElement TF describes a TTree object TF in a file.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:57
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:41
Stopwatch class.
Definition: TStopwatch.h:28
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition: TTreeReader.h:44
@ kEntryBeyondEnd
last entry loop has reached its end
Definition: TTreeReader.h:139
@ kEntryValid
data read okay
Definition: TTreeReader.h:132
A TTree represents a columnar dataset.
Definition: TTree.h:79
virtual TBranch * FindBranch(const char *name)
Return the branch that correspond to the path 'branchname', which can include the name of the tree or...
Definition: TTree.cxx:4809
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition: TTree.cxx:5262
static void SetMaxTreeSize(Long64_t maxsize=100000000000LL)
Set the maximum size in bytes of a Tree file (static function).
Definition: TTree.cxx:9161
virtual TObjArray * GetListOfBranches()
Definition: TTree.h:484
virtual TTree * GetTree() const
Definition: TTree.h:513
virtual TList * GetListOfFriends() const
Definition: TTree.h:486
virtual const char * GetFriendAlias(TTree *) const
If the 'tree' is a friend, this method returns its alias name.
Definition: TTree.cxx:6006
std::vector< std::string > GetTreeFullPaths(const TTree &tree)
Retrieve the full path(s) to a TTree or the trees in a TChain.
RVec< PromoteTypes< T0, T1 > > remainder(const T0 &x, const RVec< T1 > &v)
Definition: RVec.hxx:1781
ROOT::Experimental::RLogChannel & RDFLogChannel()
Definition: RDFUtils.cxx:37
std::vector< std::string > GetBranchNames(TTree &t, bool allowDuplicates=true)
Get all the branches names, including the ones of the friend trees.
unsigned int GetNSlots()
Definition: RDFUtils.cxx:283
void Erase(const T &that, std::vector< T > &v)
Erase that element from vector v
Definition: Utils.hxx:187
Long64_t InterpreterCalc(const std::string &code, const std::string &context="")
Jit code in the interpreter with TInterpreter::Calc, throw in case of errors.
Definition: RDFUtils.cxx:327
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 a RDataFrame computation graph via e....
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Definition: TROOT.cxx:558
static constexpr double s
Definition: file.py:1
Definition: tree.py:1
static const char * what
Definition: stlLoader.cc:6
A RAII object that calls RLoopManager::CleanUpTask at destruction.
RCallCleanUpTask(RLoopManager &lm, unsigned int arg=0u, TTreeReader *reader=nullptr)
A RAII object to pop and push slot numbers from a RSlotStack object.
Definition: RSlotStack.hxx:45