Logo ROOT   6.16/01
Reference Guide
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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 165 of file TTreeProcessorMT.hxx.

Public Member Functions

 TTreeProcessorMT (const std::vector< std::string_view > &filenames, std::string_view treename="")
 Constructor based on a collection of file names. More...
 
 TTreeProcessorMT (std::string_view filename, std::string_view treename="")
 Constructor based on a file name. More...
 
 TTreeProcessorMT (TTree &tree)
 Constructor based on a TTree. More...
 
 TTreeProcessorMT (TTree &tree, const TEntryList &entries)
 Constructor based on a TTree and a TEntryList. More...
 
void Process (std::function< void(TTreeReader &)> func)
 Process the entries of a TTree in parallel. More...
 

Static Public Member Functions

static unsigned int GetMaxTasksPerFilePerWorker ()
 Sets the maximum number of tasks created per file, per worker. More...
 
static void SetMaxTasksPerFilePerWorker (unsigned int m)
 Sets the maximum number of tasks created per file, per worker. More...
 

Private Member Functions

std::string FindTreeName ()
 Retrieve the name of the first TTree in the first input file, else throw. More...
 
Internal::FriendInfo GetFriendInfo (TTree &tree)
 Get and store the names, aliases and file names of the friends of the tree. More...
 

Private Attributes

const TEntryList fEntryList
 User-defined selection of entry numbers to be processed, empty if none was provided. More...
 
const std::vector< std::string > fFileNames
 Names of the files. More...
 
const Internal::FriendInfo fFriendInfo
 
const std::string fTreeName
 Name of the tree. More...
 
ROOT::TThreadedObject< ROOT::Internal::TTreeViewtreeView
 ! Thread-local TreeViews More...
 

Static Private Attributes

static unsigned int fgMaxTasksPerFilePerWorker = 24U
 

#include <ROOT/TTreeProcessorMT.hxx>

Constructor & Destructor Documentation

◆ TTreeProcessorMT() [1/4]

TTreeProcessorMT::TTreeProcessorMT ( std::string_view  filename,
std::string_view  treename = "" 
)

Constructor based on a file name.

Parameters
[in]filenameName of the file containing the tree to process.
[in]treenameName of the tree to process. If not provided, the implementation will automatically search for a tree in the file.

Definition at line 264 of file TTreeProcessorMT.cxx.

◆ TTreeProcessorMT() [2/4]

TTreeProcessorMT::TTreeProcessorMT ( const std::vector< std::string_view > &  filenames,
std::string_view  treename = "" 
)

Constructor based on a collection of file names.

Parameters
[in]filenamesCollection of the names of the files containing the tree to process.
[in]treenameName of the tree to process. If not provided, the implementation will automatically search for a tree in the collection of files.

Definition at line 285 of file TTreeProcessorMT.cxx.

◆ TTreeProcessorMT() [3/4]

TTreeProcessorMT::TTreeProcessorMT ( TTree tree,
const TEntryList entries 
)

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.

Definition at line 318 of file TTreeProcessorMT.cxx.

◆ TTreeProcessorMT() [4/4]

TTreeProcessorMT::TTreeProcessorMT ( TTree tree)

Constructor based on a TTree.

Parameters
[in]treeTree or chain of files containing the tree to process.

Definition at line 325 of file TTreeProcessorMT.cxx.

Member Function Documentation

◆ FindTreeName()

std::string TTreeProcessorMT::FindTreeName ( )
private

Retrieve the name of the first TTree in the first input file, else throw.

Definition at line 235 of file TTreeProcessorMT.cxx.

◆ GetFriendInfo()

Internal::FriendInfo TTreeProcessorMT::GetFriendInfo ( TTree tree)
private

Get and store the names, aliases and file names of the friends of the tree.

Parameters
[in]treeThe main tree whose friends to

Note that "friends of friends" and circular references in the lists of friends are not supported.

Definition at line 192 of file TTreeProcessorMT.cxx.

◆ GetMaxTasksPerFilePerWorker()

unsigned int TTreeProcessorMT::GetMaxTasksPerFilePerWorker ( )
static

Sets the maximum number of tasks created per file, per worker.

Returns
The maximum number of tasks created per file, per worker

Definition at line 403 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 colmnar datasets such as TTree,...
Definition: TTreeReader.h:44
Bool_t Next()
Move to the next entry (or index of the TEntryList if that is set).
Definition: TTreeReader.h:182

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 344 of file TTreeProcessorMT.cxx.

◆ SetMaxTasksPerFilePerWorker()

void TTreeProcessorMT::SetMaxTasksPerFilePerWorker ( unsigned int  maxTasksPerFile)
static

Sets the maximum number of tasks created per file, per worker.

Parameters
[in]maxTasksPerFileName of the file containing the tree to process.

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.

Definition at line 415 of file TTreeProcessorMT.cxx.

Member Data Documentation

◆ fEntryList

const TEntryList ROOT::TTreeProcessorMT::fEntryList
private

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

Definition at line 170 of file TTreeProcessorMT.hxx.

◆ fFileNames

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

Names of the files.

Definition at line 167 of file TTreeProcessorMT.hxx.

◆ fFriendInfo

const Internal::FriendInfo ROOT::TTreeProcessorMT::fFriendInfo
private

Definition at line 171 of file TTreeProcessorMT.hxx.

◆ fgMaxTasksPerFilePerWorker

unsigned int ROOT::TTreeProcessorMT::fgMaxTasksPerFilePerWorker = 24U
staticprivate

Definition at line 177 of file TTreeProcessorMT.hxx.

◆ fTreeName

const std::string ROOT::TTreeProcessorMT::fTreeName
private

Name of the tree.

Definition at line 168 of file TTreeProcessorMT.hxx.

◆ treeView

ROOT::TThreadedObject<ROOT::Internal::TTreeView> ROOT::TTreeProcessorMT::treeView
private

! Thread-local TreeViews

Definition at line 173 of file TTreeProcessorMT.hxx.

Libraries for ROOT::TTreeProcessorMT:
[legend]

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