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 const std::vector<std::string> &suppressErrorsForMissingBranches);
76 void Reset();
77};
78} // End of namespace Internal
79
81private:
82 const std::vector<std::string> fFileNames; ///< Names of the files
83 const std::vector<std::string> fTreeNames; ///< TTree names (always same size and ordering as fFileNames)
84 /// User-defined selection of entry numbers to be processed, empty if none was provided
87 ROOT::TThreadExecutor fPool; ///<! Thread pool for processing.
88
89 /// Thread-local TreeViews
90 // Must be declared after fPool, for IMT to be initialized first!
92
93 std::vector<std::string> FindTreeNames();
94 static unsigned int fgTasksPerWorkerHint;
95
96 std::pair<Long64_t, Long64_t> fGlobalRange{0, std::numeric_limits<Long64_t>::max()};
97
98 // List of branches for which we want to suppress the printed error about
99 // missing branch when switching to a new tree
100 std::vector<std::string> fSuppressErrorsForMissingBranches{};
101
102public:
103 TTreeProcessorMT(std::string_view filename, 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(const std::vector<std::string_view> &filenames, std::string_view treename = "",
106 UInt_t nThreads = 0u,
107 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
108 TTreeProcessorMT(std::initializer_list<std::string_view> filenames, std::string_view treename = "", UInt_t nThreads = 0u,
109 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()}):
110 TTreeProcessorMT(std::vector<std::string_view>(filenames), treename, nThreads, globalRange) {}
111 TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads = 0u,
112 const std::vector<std::string> &suppressErrorsForMissingBranches = {});
113 TTreeProcessorMT(TTree &tree, UInt_t nThreads = 0u,
114 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()},
115 const std::vector<std::string> &suppressErrorsForMissingBranches = {});
116
117 void Process(std::function<void(TTreeReader &)> func);
118
119 static void SetTasksPerWorkerHint(unsigned int m);
120 static unsigned int GetTasksPerWorkerHint();
121};
122
123} // End of namespace ROOT
124
125#endif // defined TTreeProcessorMT
unsigned int UInt_t
Definition RtypesCore.h:46
long long Long64_t
Definition RtypesCore.h:69
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< 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, const std::vector< std::string > &suppressErrorsForMissingBranches)
Get a TTreeReader for the current tree of this view.
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.
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(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={})
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
ROOT::TThreadExecutor fPool
! Thread pool for processing.
TEntryList fEntryList
User-defined selection of entry numbers to be processed, empty if none was provided.
std::vector< std::string > fSuppressErrorsForMissingBranches
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:46
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