11 #include "RConfigure.h"
16 #include "ROOT/TThreadExecutor.hxx"
28 using namespace ROOT::Detail::TDF;
29 using namespace ROOT::Internal::TDF;
35 TActionBase::TActionBase(
TLoopManager *implPtr,
const ColumnNames_t &tmpBranches)
36 : fImplPtr(implPtr), fTmpBranches(tmpBranches)
44 TCustomColumnBase::TCustomColumnBase(
TLoopManager *implPtr,
const ColumnNames_t &tmpBranches, std::string_view
name)
45 : fImplPtr(implPtr), fTmpBranches(tmpBranches), fName(name){};
63 : fImplPtr(implPtr), fTmpBranches(tmpBranches), fName(name){};
77 return !
fName.empty();
86 double perc = accepted;
87 if (all > 0) perc /= all;
89 Printf(
"%-10s: pass=%-10lld all=%-10lld -- %8.3f %%",
fName.c_str(), accepted, all, perc);
99 std::vector<unsigned int> fBuf;
103 TSlotStack() =
delete;
104 TSlotStack(
unsigned int size) : fCursor(size), fBuf(size) { std::iota(fBuf.begin(), fBuf.end(), 0U); }
105 void Push(
unsigned int slotNumber);
109 void TSlotStack::Push(
unsigned int slotNumber)
111 std::lock_guard<ROOT::TSpinMutex> guard(fMutex);
112 fBuf[fCursor++] = slotNumber;
113 assert(fCursor <= fBuf.size() &&
"TSlotStack assumes that at most a fixed number of values can be present in the "
114 "stack. fCursor is greater than the size of the internal buffer. This violates "
118 unsigned int TSlotStack::Pop()
120 assert(fCursor > 0 &&
121 "TSlotStack assumes that a value can be always popped. fCursor is <=0 and this violates such assumption.");
122 std::lock_guard<ROOT::TSpinMutex> guard(fMutex);
123 return fBuf[--fCursor];
127 : fTree(std::shared_ptr<TTree>(tree, [](TTree *) {})),
fDefaultBranches(defaultBranches),
136 void TLoopManager::RunAndCheckFilters(
unsigned int slot,
Long64_t entry)
138 for (
auto &actionPtr :
fBookedActions) actionPtr->Run(slot, entry);
139 for (
auto &namedFilterPtr :
fBookedNamedFilters) namedFilterPtr->CheckFilters(slot, entry);
154 std::vector<std::pair<Long64_t, Long64_t>> entryRanges;
157 Long64_t end = start + nEntriesPerSlot;
162 entryRanges.emplace_back(start, end);
167 auto genFunction = [
this, &slotStack](
const std::pair<Long64_t, Long64_t> &range) {
168 auto slot = slotStack.Pop();
170 for (
auto currEntry = range.first; currEntry < range.second; ++currEntry) {
173 slotStack.Push(slot);
176 ROOT::TThreadExecutor pool;
177 pool.Foreach(genFunction, entryRanges);
180 std::unique_ptr<ttpmt_t> tp;
181 tp.reset(
new ttpmt_t(*
fTree));
183 tp->Process([
this, &slotStack](
TTreeReader &
r) ->
void {
184 auto slot = slotStack.Pop();
190 slotStack.Push(slot);
220 *readiness.get() =
true;
223 fResProxyReadiness.clear();
236 for (
auto &bookedBranch :
fBookedBranches) bookedBranch.second->Init(r, slot);
251 for (
auto &bookedBranch :
fBookedBranches) bookedBranch.second->CreateSlots(nSlots);
288 if (filterPtr->HasName()) {
327 : fImplPtr(implPtr), fTmpBranches(tmpBranches), fStart(start), fStop(stop), fStride(stride)
RangeBaseVec_t fBookedRanges
FilterBaseVec_t fBookedFilters
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
TTree()
Default constructor and I/O constructor.
ColumnNames_t GetTmpBranches() const
void Report() const
Call PrintReport on all booked filters.
::TDirectory * GetDirectory() const
TLoopManager(TTree *tree, const ColumnNames_t &defaultBranches)
std::map< std::string, TmpBranchBasePtr_t > fBookedBranches
TRangeBase(TLoopManager *implPtr, const ColumnNames_t &tmpBranches, unsigned int start, unsigned int stop, unsigned int stride)
A spin mutex class which respects the STL interface for mutexes.
unsigned int fNChildren
Number of nodes of the functional graph hanging from this object.
void InitAllNodes(TTreeReader *r, unsigned int slot)
Build TTreeReaderValues for all nodes.
ColumnNames_t GetTmpBranches() const
void Book(const ActionBasePtr_t &actionPtr)
unsigned int GetNSlots() const
std::vector< ULong64_t > fAccepted
std::vector< ULong64_t > fRejected
std::shared_ptr< TFilterBase > FilterBasePtr_t
std::string GetName() const
Long64_t GetCurrentEntry() const
Returns the index of the current entry being read.
bool CheckFilters(int, unsigned int)
const ColumnNames_t fTmpBranches
TLoopManager * GetImplPtr() const
ActionBaseVec_t fBookedActions
void RunAndCheckFilters(unsigned int slot, Long64_t entry)
const Long64_t fNEmptyEntries
unsigned int fNStopsReceived
Number of times that a children node signaled to stop processing entries.
void CreateSlots(unsigned int nSlots)
Initialize all nodes of the functional graph before running the event loop.
std::shared_ptr< TCustomColumnBase > TmpBranchBasePtr_t
TLoopManager * fImplPtr
A raw pointer to the TLoopManager at the root of this functional graph.
const unsigned int fNSlots
const ColumnNames_t & GetDefaultBranches() const
FilterBaseVec_t fBookedNamedFilters
ColumnNames_t fTmpBranches
Describe directory structure in memory.
fNSlots(TDFInternal::GetNSlots())
ColumnNames_t fTmpBranches
TLoopManager * fImplPtr
A raw pointer to the TLoopManager at the root of this functional graph.
const ColumnNames_t fDefaultBranches
TLoopManager * GetImplPtr() const
TFilterBase(TLoopManager *df, const ColumnNames_t &tmpBranches, std::string_view name)
std::shared_ptr< TDFInternal::TActionBase > ActionBasePtr_t
TLoopManager * fImplPtr
A raw pointer to the TLoopManager at the root of this functional graph.
fDefaultBranches(defaultBranches)
TCustomColumnBase * GetBookedBranch(const std::string &name) const
TLoopManager * GetImplPtr()
TLoopManager * GetImplPtr() const
Bool_t Next()
Move to the next entry (or index of the TEntryList if that is set).
std::shared_ptr< TTree > fTree
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
ColumnNames_t GetTmpBranches() const
std::vector< std::shared_ptr< bool > > fResProxyReadiness
A class to process the entries of a TTree in parallel.
std::shared_ptr< TRangeBase > RangeBasePtr_t