Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TTreeProcessorMT.hxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Authors: Enric Tejedor, Enrico Guiraud CERN 05/06/2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TTreeProcessorMT
13#define ROOT_TTreeProcessorMT
14
15#include "TKey.h"
16#include "TTree.h"
17#include "TFile.h"
18#include "TChain.h"
19#include "TEntryList.h"
20#include "TTreeReader.h"
21#include "TError.h"
22#include "TEntryList.h"
25#include "ROOT/InternalTreeUtils.hxx" // RNoCleanupNotifier
26#include "ROOT/RFriendInfo.hxx"
27
28#include <functional>
29#include <memory>
30#include <vector>
31#include <limits>
32#include <RtypesCore.h> // Long64_t
33
34/** \class TTreeView
35 \brief A helper class that encapsulates a file and a tree.
36
37A helper class that encapsulates a TFile and a TTree, along with their names.
38It is used together with TTProcessor and ROOT::TThreadedObject, so that
39in the TTProcessor::Process method each thread can work on its own
40<TFile,TTree> pair.
41
42This class can also be used with a collection of file names or a TChain, in case
43the tree is stored in more than one file. A view will always contain only the
44current (active) tree and file objects.
45
46A copy constructor is defined for TTreeView to work with ROOT::TThreadedObject.
47The latter makes a copy of a model object every time a new thread accesses
48the threaded object.
49*/
50
51namespace ROOT {
52
53namespace Internal {
54
55class TTreeView {
57
58 std::vector<std::unique_ptr<TChain>> fFriends; ///< Friends of the tree/chain, if present
59 std::unique_ptr<TEntryList> fEntryList; ///< TEntryList for fChain, if present
60 // NOTE: fFriends and fEntryList MUST come before fChain to be deleted after it, because neither friend trees nor
61 // entrylists are deregistered from the main tree at destruction (ROOT-9283 tracks the issue for friends).
62 std::unique_ptr<TChain> fChain; ///< Chain on which to operate
63
64 void MakeChain(const std::vector<std::string> &treeName, const std::vector<std::string> &fileNames,
65 const ROOT::TreeUtils::RFriendInfo &friendInfo, const std::vector<Long64_t> &nEntries);
66
67public:
68 TTreeView() = default;
69 // no-op, we don't want to copy the local TChains
70 TTreeView(const TTreeView &) {}
71 std::unique_ptr<TTreeReader> GetTreeReader(Long64_t start, Long64_t end, const std::vector<std::string> &treeName,
72 const std::vector<std::string> &fileNames,
73 const ROOT::TreeUtils::RFriendInfo &friendInfo,
74 const TEntryList &entryList, const std::vector<Long64_t> &nEntries);
75 void Reset();
76};
77} // End of namespace Internal
78
80private:
81 const std::vector<std::string> fFileNames; ///< Names of the files
82 const std::vector<std::string> fTreeNames; ///< TTree names (always same size and ordering as fFileNames)
83 /// User-defined selection of entry numbers to be processed, empty if none was provided
86 ROOT::TThreadExecutor fPool; ///<! Thread pool for processing.
87
88 /// Thread-local TreeViews
89 // Must be declared after fPool, for IMT to be initialized first!
91
92 std::vector<std::string> FindTreeNames();
93 static unsigned int fgTasksPerWorkerHint;
94
95 std::pair<Long64_t, Long64_t> fGlobalRange{0, std::numeric_limits<Long64_t>::max()};
96
97public:
98 TTreeProcessorMT(std::string_view filename, std::string_view treename = "", UInt_t nThreads = 0u,
99 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
100 TTreeProcessorMT(const std::vector<std::string_view> &filenames, std::string_view treename = "",
101 UInt_t nThreads = 0u,
102 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
103 TTreeProcessorMT(std::initializer_list<std::string_view> filenames, std::string_view treename = "", UInt_t nThreads = 0u,
104 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()}):
105 TTreeProcessorMT(std::vector<std::string_view>(filenames), treename, nThreads, globalRange) {}
106 TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads = 0u);
107 TTreeProcessorMT(TTree &tree, UInt_t nThreads = 0u,
108 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
109
110 void Process(std::function<void(TTreeReader &)> func);
111
112 static void SetTasksPerWorkerHint(unsigned int m);
113 static unsigned int GetTasksPerWorkerHint();
114};
115
116} // End of namespace ROOT
117
118#endif // defined TTreeProcessorMT
unsigned int UInt_t
Definition RtypesCore.h:46
long long Long64_t
Definition RtypesCore.h:80
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
std::unique_ptr< TChain > fChain
Chain on which to operate.
std::vector< std::unique_ptr< TChain > > fFriends
Friends of the tree/chain, if present.
std::unique_ptr< TEntryList > fEntryList
TEntryList for fChain, if present.
void Reset()
Clear the resources.
std::unique_ptr< TTreeReader > GetTreeReader(Long64_t start, Long64_t end, const std::vector< std::string > &treeName, const std::vector< std::string > &fileNames, const ROOT::TreeUtils::RFriendInfo &friendInfo, const TEntryList &entryList, const std::vector< Long64_t > &nEntries)
Get a TTreeReader for the current tree of this view.
void MakeChain(const std::vector< std::string > &treeName, const std::vector< std::string > &fileNames, const ROOT::TreeUtils::RFriendInfo &friendInfo, const std::vector< Long64_t > &nEntries)
Construct fChain, also adding friends if needed and injecting knowledge of offsets if available.
ROOT::Internal::TreeUtils::RNoCleanupNotifier fNoCleanupNotifier
This class provides a simple interface to execute the same task multiple times in parallel threads,...
A wrapper to make object instances thread private, lazily.
A class to process the entries of a TTree in parallel.
ROOT::TreeUtils::RFriendInfo fFriendInfo
const std::vector< std::string > fTreeNames
TTree names (always same size and ordering as fFileNames)
std::vector< std::string > FindTreeNames()
Retrieve the names of the TTrees in each of the input files, throw if a TTree cannot be found.
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()})
const std::vector< std::string > fFileNames
Names of the files.
static unsigned int fgTasksPerWorkerHint
TTreeProcessorMT(TTree &tree, UInt_t nThreads=0u, const std::pair< Long64_t, Long64_t > &globalRange={0, std::numeric_limits< Long64_t >::max()})
ROOT::TThreadExecutor fPool
! Thread pool for processing.
TEntryList fEntryList
User-defined selection of entry numbers to be processed, empty if none was provided.
static void SetTasksPerWorkerHint(unsigned int m)
Set the hint for the desired number of tasks created per worker.
ROOT::TThreadedObject< ROOT::Internal::TTreeView > fTreeView
Thread-local TreeViews.
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()})
void Process(std::function< void(TTreeReader &)> func)
Process the entries of a TTree in parallel.
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()})
static unsigned int GetTasksPerWorkerHint()
Retrieve the current value for the desired number of tasks per worker.
std::pair< Long64_t, Long64_t > fGlobalRange
A List of entry numbers in a TTree or TChain.
Definition TEntryList.h:26
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:44
A TTree represents a columnar dataset.
Definition TTree.h:79
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
Definition TROOT.cxx:577
Defines the number of threads in some of ROOT's interfaces.
Information about friend trees of a certain TTree or TChain object.
TMarker m
Definition textangle.C:8