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 84 of file TTreeProcessorMT.hxx.
Public Member Functions | |
TTreeProcessorMT (const std::vector< std::string_view > &filenames, std::string_view treename="", UInt_t nThreads=0u) | |
Constructor based on a collection of file names. | |
TTreeProcessorMT (std::string_view filename, std::string_view treename="", UInt_t nThreads=0u) | |
Constructor based on a file name. | |
TTreeProcessorMT (TTree &tree, const TEntryList &entries, UInt_t nThreads=0u) | |
Constructor based on a TTree and a TEntryList. | |
TTreeProcessorMT (TTree &tree, UInt_t nThreads=0u) | |
Constructor based on a TTree. | |
void | Process (std::function< void(TTreeReader &)> func) |
Process the entries of a TTree in parallel. | |
Static Public Member Functions | |
static unsigned int | GetMaxTasksPerFilePerWorker () |
This function is deprecated in favor of GetTasksPerWorkerHint(). | |
static unsigned int | GetTasksPerWorkerHint () |
Retrieve the current value for the desired number of tasks per worker. | |
static void | SetMaxTasksPerFilePerWorker (unsigned int m) |
This function is deprecated in favor of SetTasksPerWorkerHint(). | |
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. | |
Internal::FriendInfo | GetFriendInfo (TTree &tree) |
Get and store the names, aliases and file names of the friends of the tree. | |
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. | |
const Internal::FriendInfo | fFriendInfo |
ROOT::TThreadExecutor | fPool |
! Thread pool for processing. | |
const std::vector< std::string > | fTreeNames |
TTree names (always same size and ordering as fFileNames) | |
ROOT::TThreadedObject< ROOT::Internal::TTreeView > | fTreeView {TNumSlots{ROOT::GetThreadPoolSize()}} |
Thread-local TreeViews. | |
Static Private Attributes | |
static unsigned int | fgMaxTasksPerFilePerWorker = 24U |
static unsigned int | fgTasksPerWorkerHint = 24U |
#include <ROOT/TTreeProcessorMT.hxx>
TTreeProcessorMT::TTreeProcessorMT | ( | std::string_view | filename, |
std::string_view | treename = "" , |
||
UInt_t | nThreads = 0u |
||
) |
Constructor based on a file name.
[in] | filename | Name of the file containing the tree to process. |
[in] | treename | Name of the tree to process. If not provided, the implementation will search for a TTree key in the file and will use the first one it finds. |
[in] | nThreads | Number of threads to create in the underlying thread-pool. The semantics of this argument are the same as for TThreadExecutor. |
Definition at line 468 of file TTreeProcessorMT.cxx.
TTreeProcessorMT::TTreeProcessorMT | ( | const std::vector< std::string_view > & | filenames, |
std::string_view | treename = "" , |
||
UInt_t | nThreads = 0u |
||
) |
Constructor based on a collection of file names.
[in] | filenames | Collection of the names of the files containing the tree to process. |
[in] | treename | Name of the tree to process. If not provided, the implementation will search filenames for a TTree key and will use the first one it finds in each file. |
[in] | nThreads | Number of threads to create in the underlying thread-pool. The semantics of this argument are the same as for TThreadExecutor. |
If different files contain TTrees with different names and automatic TTree name detection is not an option (for example, because some of the files contain multiple TTrees) please manually create a TChain and pass it to the appropriate TTreeProcessorMT constructor.
Definition at line 499 of file TTreeProcessorMT.cxx.
TTreeProcessorMT::TTreeProcessorMT | ( | TTree & | tree, |
const TEntryList & | entries, | ||
UInt_t | nThreads = 0u |
||
) |
Constructor based on a TTree and a TEntryList.
[in] | tree | Tree or chain of files containing the tree to process. |
[in] | entries | List of entry numbers to process. |
[in] | nThreads | Number of threads to create in the underlying thread-pool. The semantics of this argument are the same as for TThreadExecutor. |
Definition at line 541 of file TTreeProcessorMT.cxx.
Constructor based on a TTree.
[in] | tree | Tree or chain of files containing the tree to process. |
[in] | nThreads | Number of threads to create in the underlying thread-pool. The semantics of this argument are the same as for TThreadExecutor. |
Definition at line 553 of file TTreeProcessorMT.cxx.
|
private |
Retrieve the names of the TTrees in each of the input files, throw if a TTree cannot be found.
Definition at line 434 of file TTreeProcessorMT.cxx.
|
private |
Get and store the names, aliases and file names of the friends of the tree.
[in] | tree | The main tree whose friends to |
Note that "friends of friends" and circular references in the lists of friends are not supported.
Definition at line 374 of file TTreeProcessorMT.cxx.
|
static |
This function is deprecated in favor of GetTasksPerWorkerHint().
Definition at line 641 of file TTreeProcessorMT.cxx.
|
static |
Retrieve the current value for the desired number of tasks per worker.
Definition at line 649 of file TTreeProcessorMT.cxx.
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
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.
[in] | func | User-defined function that processes a subrange of entries |
Definition at line 574 of file TTreeProcessorMT.cxx.
This function is deprecated in favor of SetTasksPerWorkerHint().
Definition at line 656 of file TTreeProcessorMT.cxx.
Set the hint for the desired number of tasks created per worker.
[in] | tasksPerWorkerHint | Desired 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 669 of file TTreeProcessorMT.cxx.
|
private |
User-defined selection of entry numbers to be processed, empty if none was provided.
Definition at line 89 of file TTreeProcessorMT.hxx.
|
private |
Names of the files.
Definition at line 86 of file TTreeProcessorMT.hxx.
|
private |
Definition at line 90 of file TTreeProcessorMT.hxx.
|
staticprivate |
Definition at line 99 of file TTreeProcessorMT.hxx.
|
staticprivate |
Definition at line 100 of file TTreeProcessorMT.hxx.
|
private |
! Thread pool for processing.
Definition at line 91 of file TTreeProcessorMT.hxx.
|
private |
TTree names (always same size and ordering as fFileNames)
Definition at line 87 of file TTreeProcessorMT.hxx.
|
private |
Thread-local TreeViews.
Definition at line 95 of file TTreeProcessorMT.hxx.