Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROOT::TTreeProcessorMT Class Reference

A class to process the entries of a TTree in parallel.

By means of its Process method, ROOT::TTreeProcessorMT provides a way to process the entries of a TTree in parallel. When invoking TTreeProcessor::Process, the user passes a function whose only parameter is a TTreeReader. The function iterates on a subrange of entries by using that TTreeReader.

The implementation of ROOT::TTreeProcessorMT parallelizes the processing of the subranges, each corresponding to a cluster in the TTree. This is possible thanks to the use of a ROOT::TThreadedObject, so that each thread works with its own TFile and TTree objects.

Definition at line 80 of file TTreeProcessorMT.hxx.

Public Member Functions

 TTreeProcessorMT (const std::vector< std::string_view > &filenames, std::string_view treename="", UInt_t nThreads=0u, const std::pair< Long64_t, Long64_t > &globalRange={0, std::numeric_limits< Long64_t >::max()})
 
 TTreeProcessorMT (std::initializer_list< std::string_view > filenames, std::string_view treename="", UInt_t nThreads=0u, const std::pair< Long64_t, Long64_t > &globalRange={0, std::numeric_limits< Long64_t >::max()})
 
 TTreeProcessorMT (std::string_view filename, std::string_view treename="", UInt_t nThreads=0u, const std::pair< Long64_t, Long64_t > &globalRange={0, std::numeric_limits< Long64_t >::max()})
 
 TTreeProcessorMT (TTree &tree, const TEntryList &entries, UInt_t nThreads=0u, const std::vector< std::string > &suppressErrorsForMissingBranches={})
 Constructor based on a TTree and a TEntryList.
 
 TTreeProcessorMT (TTree &tree, UInt_t nThreads=0u, const std::pair< Long64_t, Long64_t > &globalRange={0, std::numeric_limits< Long64_t >::max()}, const std::vector< std::string > &suppressErrorsForMissingBranches={})
 
void Process (std::function< void(TTreeReader &)> func)
 Process the entries of a TTree in parallel.
 

Static Public Member Functions

static unsigned int GetTasksPerWorkerHint ()
 Retrieve the current value for the desired number of tasks per worker.
 
static void SetTasksPerWorkerHint (unsigned int m)
 Set the hint for the desired number of tasks created per worker.
 

Private Member Functions

std::vector< std::string > FindTreeNames ()
 Retrieve the names of the TTrees in each of the input files, throw if a TTree cannot be found.
 

Private Attributes

TEntryList fEntryList
 User-defined selection of entry numbers to be processed, empty if none was provided.
 
const std::vector< std::string > fFileNames
 Names of the files.
 
ROOT::TreeUtils::RFriendInfo fFriendInfo
 
std::pair< Long64_t, Long64_tfGlobalRange {0, std::numeric_limits<Long64_t>::max()}
 
ROOT::TThreadExecutor fPool
 ! Thread pool for processing.
 
std::vector< std::string > fSuppressErrorsForMissingBranches {}
 
const std::vector< std::string > fTreeNames
 TTree names (always same size and ordering as fFileNames)
 
ROOT::TThreadedObject< ROOT::Internal::TTreeViewfTreeView {TNumSlots{ROOT::GetThreadPoolSize()}}
 Thread-local TreeViews.
 

Static Private Attributes

static unsigned int fgTasksPerWorkerHint = 10U
 

#include <ROOT/TTreeProcessorMT.hxx>

Constructor & Destructor Documentation

◆ TTreeProcessorMT() [1/5]

ROOT::TTreeProcessorMT::TTreeProcessorMT ( std::string_view  filename,
std::string_view  treename = "",
UInt_t  nThreads = 0u,
const std::pair< Long64_t, Long64_t > &  globalRange = {0, std::numeric_limits< Long64_t >::max()} 
)

◆ TTreeProcessorMT() [2/5]

ROOT::TTreeProcessorMT::TTreeProcessorMT ( const std::vector< std::string_view > &  filenames,
std::string_view  treename = "",
UInt_t  nThreads = 0u,
const std::pair< Long64_t, Long64_t > &  globalRange = {0, std::numeric_limits< Long64_t >::max()} 
)

◆ TTreeProcessorMT() [3/5]

ROOT::TTreeProcessorMT::TTreeProcessorMT ( std::initializer_list< std::string_view >  filenames,
std::string_view  treename = "",
UInt_t  nThreads = 0u,
const std::pair< Long64_t, Long64_t > &  globalRange = {0, std::numeric_limits<Long64_t>::max()} 
)
inline

Definition at line 108 of file TTreeProcessorMT.hxx.

◆ TTreeProcessorMT() [4/5]

TTreeProcessorMT::TTreeProcessorMT ( TTree tree,
const TEntryList entries,
UInt_t  nThreads = 0u,
const std::vector< std::string > &  suppressErrorsForMissingBranches = {} 
)

Constructor based on a TTree and a TEntryList.

Parameters
[in]treeTree or chain of files containing the tree to process.
[in]entriesList of entry numbers to process.
[in]nThreadsNumber of threads to create in the underlying thread-pool. The semantics of this argument are the same as for TThreadExecutor.

Definition at line 414 of file TTreeProcessorMT.cxx.

◆ TTreeProcessorMT() [5/5]

ROOT::TTreeProcessorMT::TTreeProcessorMT ( TTree tree,
UInt_t  nThreads = 0u,
const std::pair< Long64_t, Long64_t > &  globalRange = {0, std::numeric_limits< Long64_t >::max()},
const std::vector< std::string > &  suppressErrorsForMissingBranches = {} 
)

Member Function Documentation

◆ FindTreeNames()

std::vector< std::string > TTreeProcessorMT::FindTreeNames ( )
private

Retrieve the names of the TTrees in each of the input files, throw if a TTree cannot be found.

Definition at line 330 of file TTreeProcessorMT.cxx.

◆ GetTasksPerWorkerHint()

unsigned int TTreeProcessorMT::GetTasksPerWorkerHint ( )
static

Retrieve the current value for the desired number of tasks per worker.

Returns
The desired number of tasks to be created per worker. TTreeProcessorMT uses this value as an hint.

Definition at line 535 of file TTreeProcessorMT.cxx.

◆ Process()

void TTreeProcessorMT::Process ( std::function< void(TTreeReader &)>  func)

Process the entries of a TTree in parallel.

The user-provided function receives a TTreeReader which can be used to iterate on a subrange of entries

// Select branches to read
while (readerSubRange.Next()) {
// Use content of current entry
}
});
void Process(std::function< void(TTreeReader &)> func)
Process the entries of a TTree in parallel.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:46
bool Next()
Move to the next entry (or index of the TEntryList if that is set).

The user needs to be aware that each of the subranges can potentially be processed in parallel. This means that the code of the user function should be thread safe.

Parameters
[in]funcUser-defined function that processes a subrange of entries

Definition at line 460 of file TTreeProcessorMT.cxx.

◆ SetTasksPerWorkerHint()

void TTreeProcessorMT::SetTasksPerWorkerHint ( unsigned int  tasksPerWorkerHint)
static

Set the hint for the desired number of tasks created per worker.

Parameters
[in]tasksPerWorkerHintDesired number of tasks per worker.

This allows to create a reasonable number of tasks even if any of the processed files features a bad clustering, for example with a lot of entries and just a few entries per cluster, or to limit the number of tasks spawned when a very large number of files and workers is used.

Definition at line 548 of file TTreeProcessorMT.cxx.

Member Data Documentation

◆ fEntryList

TEntryList ROOT::TTreeProcessorMT::fEntryList
private

User-defined selection of entry numbers to be processed, empty if none was provided.

Definition at line 85 of file TTreeProcessorMT.hxx.

◆ fFileNames

const std::vector<std::string> ROOT::TTreeProcessorMT::fFileNames
private

Names of the files.

Definition at line 82 of file TTreeProcessorMT.hxx.

◆ fFriendInfo

ROOT::TreeUtils::RFriendInfo ROOT::TTreeProcessorMT::fFriendInfo
private

Definition at line 86 of file TTreeProcessorMT.hxx.

◆ fGlobalRange

std::pair<Long64_t, Long64_t> ROOT::TTreeProcessorMT::fGlobalRange {0, std::numeric_limits<Long64_t>::max()}
private

Definition at line 96 of file TTreeProcessorMT.hxx.

◆ fgTasksPerWorkerHint

unsigned int ROOT::TTreeProcessorMT::fgTasksPerWorkerHint = 10U
staticprivate

Definition at line 94 of file TTreeProcessorMT.hxx.

◆ fPool

ROOT::TThreadExecutor ROOT::TTreeProcessorMT::fPool
private

! Thread pool for processing.

Definition at line 87 of file TTreeProcessorMT.hxx.

◆ fSuppressErrorsForMissingBranches

std::vector<std::string> ROOT::TTreeProcessorMT::fSuppressErrorsForMissingBranches {}
private

Definition at line 100 of file TTreeProcessorMT.hxx.

◆ fTreeNames

const std::vector<std::string> ROOT::TTreeProcessorMT::fTreeNames
private

TTree names (always same size and ordering as fFileNames)

Definition at line 83 of file TTreeProcessorMT.hxx.

◆ fTreeView

ROOT::TThreadedObject<ROOT::Internal::TTreeView> ROOT::TTreeProcessorMT::fTreeView {TNumSlots{ROOT::GetThreadPoolSize()}}
private

Thread-local TreeViews.

Definition at line 91 of file TTreeProcessorMT.hxx.

Libraries for ROOT::TTreeProcessorMT:

The documentation for this class was generated from the following files: