34 return (leaves.find(leaf) != leaves.end());
41 const std::string &friendName)
44 if (!friendName.empty()) {
46 const auto friendBName = friendName +
"." + branchName;
47 if (bNamesReg.insert(friendBName).second)
48 bNames.push_back(friendBName);
51 if (bNamesReg.insert(branchName).second)
52 bNames.push_back(branchName);
58 const std::string &friendName, std::set<TLeaf *> &foundLeaves,
TLeaf *leaf,
bool allowDuplicates)
60 const bool canAdd = allowDuplicates ? true : !
ContainsLeaf(foundLeaves, leaf);
65 UpdateList(bNamesReg, bNames, branchName, friendName);
67 foundLeaves.insert(leaf);
71 std::string &friendName)
73 for (
auto sb : *
b->GetListOfBranches()) {
75 auto subBranchName = std::string(subBranch->
GetName());
76 auto fullName = prefix + subBranchName;
78 std::string newPrefix;
80 newPrefix = fullName +
".";
82 ExploreBranch(t, bNamesReg, bNames, subBranch, newPrefix, friendName);
85 UpdateList(bNamesReg, bNames, fullName, friendName);
87 }
else if (t.
GetBranch(subBranchName.c_str())) {
88 UpdateList(bNamesReg, bNames, subBranchName, friendName);
94 std::set<TTree *> &analysedTrees, std::string &friendName,
bool allowDuplicates)
96 std::set<TLeaf *> foundLeaves;
97 if (!analysedTrees.insert(&t).second) {
106 std::string err(
"GetBranchNames: error in opening the tree ");
108 throw std::runtime_error(err);
111 for (
auto b : *branches) {
113 const auto branchName = std::string(branch->
GetName());
117 if (listOfLeaves->GetEntries() == 1) {
118 auto leaf =
static_cast<TLeaf *
>(listOfLeaves->At(0));
119 const auto leafName = std::string(leaf->GetName());
120 if (leafName == branchName) {
121 UpdateList(bNamesReg, bNames, branchName, friendName, foundLeaves, leaf, allowDuplicates);
125 for (
auto leaf : *listOfLeaves) {
126 auto castLeaf =
static_cast<TLeaf *
>(leaf);
127 const auto leafName = std::string(leaf->GetName());
128 const auto fullName = branchName +
"." + leafName;
129 UpdateList(bNamesReg, bNames, fullName, friendName, foundLeaves, castLeaf, allowDuplicates);
133 ExploreBranch(t, bNamesReg, bNames, branch, branchName +
".", friendName);
134 UpdateList(bNamesReg, bNames, branchName, friendName);
139 bool dotIsImplied =
false;
142 throw std::runtime_error(
"GetBranchNames: unsupported branch type");
144 if (be->GetType() == 3 || be->GetType() == 4)
147 if (dotIsImplied || branchName.back() ==
'.')
150 ExploreBranch(t, bNamesReg, bNames, branch, branchName +
".", friendName);
152 UpdateList(bNamesReg, bNames, branchName, friendName);
162 for (
auto friendTreeObj : *friendTrees) {
167 if (alias !=
nullptr)
168 frName = std::string(alias);
170 frName = std::string(friendTree->GetName());
172 GetBranchNamesImpl(*friendTree, bNamesReg, bNames, analysedTrees, frName, allowDuplicates);
180 std::set<std::string> bNamesSet;
182 std::set<TTree *> analysedTrees;
183 std::string emptyFrName =
"";
184 GetBranchNamesImpl(t, bNamesSet, bNames, analysedTrees, emptyFrName, allowDuplicates);
190 : fTree(std::shared_ptr<
TTree>(
tree, [](
TTree *) {})), fDefaultColumns(defaultBranches),
205 fDataSource(std::move(ds))
213 auto friends =
fTree->GetListOfFriends();
216 for (
auto friendElObj : *friends) {
218 auto friendTree = friendEl->
GetTree();
219 if (friendTree && friendTree->GetTreeIndex()) {
220 std::string err =
fTree->GetName();
221 err +=
" has a friend, \"";
222 err += friendTree->GetName();
223 err +=
"\", which has an index. This is not supported.";
224 throw std::runtime_error(err);
238 std::vector<std::pair<ULong64_t, ULong64_t>> entryRanges;
246 entryRanges.emplace_back(start, end);
251 auto genFunction = [
this, &slotStack](
const std::pair<ULong64_t, ULong64_t> &range) {
252 auto slot = slotStack.
GetSlot();
254 for (
auto currEntry = range.first; currEntry < range.second; ++currEntry) {
262 pool.
Foreach(genFunction, entryRanges);
284 auto tp = std::make_unique<ROOT::TTreeProcessorMT>(*
fTree, entryList);
286 std::atomic<ULong64_t> entryCount(0ull);
288 tp->Process([
this, &slotStack, &entryCount](
TTreeReader &
r) ->
void {
289 auto slot = slotStack.
GetSlot();
291 const auto entryRange =
r.GetEntriesRange();
292 const auto nEntries = entryRange.second - entryRange.first;
293 auto count = entryCount.fetch_add(nEntries);
309 if (0 ==
fTree->GetEntriesFast())
327 while (!ranges.empty()) {
330 for (
const auto &range : ranges) {
331 auto end = range.second;
332 for (
auto entry = range.first; entry < end; ++entry) {
354 auto runOnRange = [
this, &slotStack](
const std::pair<ULong64_t, ULong64_t> &range) {
355 const auto slot = slotStack.
GetSlot();
358 const auto end = range.second;
359 for (
auto entry = range.first; entry < end; ++entry) {
371 while (!ranges.empty()) {
372 pool.
Foreach(runOnRange, ranges);
384 actionPtr->Run(slot, entry);
386 namedFilterPtr->CheckFilters(slot, entry);
399 ptr->InitSlot(
r, slot);
401 ptr->InitSlot(
r, slot);
439 ptr->ResetChildrenCount();
441 ptr->ResetChildrenCount();
451 ptr->FinalizeSlot(slot);
453 ptr->ClearTask(slot);
488 actionPtr->TriggerChildrenCount();
490 namedFilterPtr->TriggerChildrenCount();
495 static unsigned int id = 0;
577 fPtr->FillReport(rep);
582 if (everyNEvents == 0ull)
590 std::vector<std::string>
filters;
592 auto name = (filter->HasName() ? filter->GetName() :
"Unnamed Filter");
600 std::vector<RDFInternal::RActionBase *> actions;
617 auto thisNode = std::make_shared<ROOT::Internal::RDF::GraphDrawing::GraphNode>(
name);
619 thisNode->SetCounter(0);
void GetBranchNamesImpl(TTree &t, std::set< std::string > &bNamesReg, ColumnNames_t &bNames, std::set< TTree * > &analysedTrees, std::string &friendName, bool allowDuplicates)
void UpdateList(std::set< std::string > &bNamesReg, ColumnNames_t &bNames, const std::string &branchName, const std::string &friendName)
This overload does not perform any check on the duplicates.
void ExploreBranch(TTree &t, std::set< std::string > &bNamesReg, ColumnNames_t &bNames, TBranch *b, std::string prefix, std::string &friendName)
bool ContainsLeaf(const std::set< TLeaf * > &leaves, TLeaf *leaf)
unsigned long long ULong64_t
RLoopManager(TTree *tree, const ColumnNames_t &defaultBranches)
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.
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.
const ColumnNames_t & GetBranchNames()
Return all valid TTree::Branch names (caching results for subsequent calls).
bool fMustRunNamedFilters
std::shared_ptr< TTree > fTree
Shared pointer to the input TTree.
const ULong64_t fNEmptyEntries
std::string fToJitExec
Code that should be just-in-time executed right before the event loop.
void RunTreeReader()
Run event loop over one or multiple ROOT files, in sequence.
std::vector< RDFInternal::RActionBase * > GetAllActions()
For all the actions, either booked or run.
void CleanUpTask(unsigned int slot)
Perform clean-up operations. To be called at the end of each task execution.
std::vector< RDFInternal::RActionBase * > fRunActions
Non-owning pointers to actions already run.
void Run()
Start the event loop with a different mechanism depending on IMT/no IMT, data source/no data source.
std::vector< RRangeBase * > fBookedRanges
std::vector< TCallback > fCallbacks
Registered callbacks.
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 CheckIndexedFriends()
std::vector< RDFInternal::RActionBase * > fBookedActions
Non-owning pointers to actions to be run.
void JitDeclarations()
Declare to the interpreter type aliases and other entities required by RDF jitted nodes.
std::shared_ptr< ROOT::Internal::RDF::GraphDrawing::GraphNode > GetGraph()
const ELoopType fLoopType
The kind of event loop that is going to be run (e.g. on ROOT files, on no files)
ColumnNames_t fValidBranchNames
Cache of the tree/chain branch names. Never access directy, always use GetBranchNames().
std::vector< RCustomColumnBase * > fCustomColumns
Non-owning container of all custom columns created so far.
const unsigned int fNSlots
const ColumnNames_t & GetDefaultColumnNames() const
Return the list of default columns – empty if none was provided when constructing the RDataFrame.
std::vector< TOneTimeCallback > fCallbacksOnce
Registered callbacks to invoke just once before running the loop.
void RunDataSourceMT()
Run event loop over data accessed through a DataSource, in parallel.
std::string fToJitDeclare
Code that should be just-in-time declared right before the event loop.
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.
static unsigned int GetNextID()
const ColumnNames_t fDefaultColumns
void Book(RDFInternal::RActionBase *actionPtr)
void InitNodeSlots(TTreeReader *r, unsigned int slot)
Build TTreeReaderValues for all nodes This method loops over all filters, actions and other booked ob...
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.
unsigned int fNStopsReceived
Number of times that a children node signaled to stop processing entries.
unsigned int fNChildren
Number of nodes of the functional graph hanging from this object.
This is an helper class to allow to pick a slot resorting to a map indexed by thread ids.
void ReturnSlot(unsigned int slotNumber)
This class provides a simple interface to execute the same task multiple times in parallel,...
void Foreach(F func, unsigned nTimes, unsigned nChunks=0)
Execute func (with no arguments) nTimes in parallel.
A Branch for the case of an object.
A TTree is a list of TBranches.
TObjArray * GetListOfLeaves()
A List of entry numbers in a TTree or TChain.
A TFriendElement TF describes a TTree object TF in a file.
virtual TTree * GetTree()
Return pointer to friend TTree.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetName() const
Returns name of object.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
A TTree represents a columnar dataset.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual TObjArray * GetListOfBranches()
virtual TTree * GetTree() const
virtual TList * GetListOfFriends() const
virtual const char * GetFriendAlias(TTree *) const
If the 'tree' is a friend, this method returns its alias name.
ColumnNames_t GetBranchNames(TTree &t, bool allowDuplicates=true)
Get all the branches names, including the ones of the friend trees.
Long64_t InterpreterCalc(const std::string &code, const std::string &context)
void InterpreterDeclare(const std::string &code)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Namespace for new ROOT classes and functions.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
ROOT::Detail::RDF::ColumnNames_t ColumnNames_t