File indexing completed on 2025-09-15 09:11:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TTreeProcessorMT
0013 #define ROOT_TTreeProcessorMT
0014
0015 #include "TKey.h"
0016 #include "TTree.h"
0017 #include "TFile.h"
0018 #include "TChain.h"
0019 #include "TEntryList.h"
0020 #include "TTreeReader.h"
0021 #include "TError.h"
0022 #include "TEntryList.h"
0023 #include "ROOT/TThreadedObject.hxx"
0024 #include "ROOT/TThreadExecutor.hxx"
0025 #include "ROOT/InternalTreeUtils.hxx" // RNoCleanupNotifier
0026 #include "ROOT/RFriendInfo.hxx"
0027
0028 #include <functional>
0029 #include <memory>
0030 #include <vector>
0031 #include <limits>
0032 #include <RtypesCore.h> // Long64_t
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 namespace ROOT {
0052
0053 namespace Internal {
0054
0055 class TTreeView {
0056 ROOT::Internal::TreeUtils::RNoCleanupNotifier fNoCleanupNotifier;
0057
0058 std::vector<std::unique_ptr<TChain>> fFriends;
0059 std::unique_ptr<TEntryList> fEntryList;
0060
0061
0062 std::unique_ptr<TChain> fChain;
0063
0064 void MakeChain(const std::vector<std::string> &treeName, const std::vector<std::string> &fileNames,
0065 const ROOT::TreeUtils::RFriendInfo &friendInfo, const std::vector<Long64_t> &nEntries);
0066
0067 public:
0068 TTreeView() = default;
0069
0070 TTreeView(const TTreeView &) {}
0071 std::unique_ptr<TTreeReader> GetTreeReader(Long64_t start, Long64_t end, const std::vector<std::string> &treeName,
0072 const std::vector<std::string> &fileNames,
0073 const ROOT::TreeUtils::RFriendInfo &friendInfo,
0074 const TEntryList &entryList, const std::vector<Long64_t> &nEntries,
0075 const std::set<std::string> &suppressErrorsForMissingBranches);
0076 void Reset();
0077 };
0078 }
0079
0080 class TTreeProcessorMT {
0081 private:
0082 const std::vector<std::string> fFileNames;
0083 const std::vector<std::string> fTreeNames;
0084
0085 TEntryList fEntryList;
0086 ROOT::TreeUtils::RFriendInfo fFriendInfo;
0087 ROOT::TThreadExecutor fPool;
0088
0089
0090
0091 ROOT::TThreadedObject<ROOT::Internal::TTreeView> fTreeView{TNumSlots{ROOT::GetThreadPoolSize()}};
0092
0093 std::vector<std::string> FindTreeNames();
0094 static unsigned int fgTasksPerWorkerHint;
0095
0096 std::pair<Long64_t, Long64_t> fGlobalRange{0, std::numeric_limits<Long64_t>::max()};
0097
0098
0099
0100 std::set<std::string> fSuppressErrorsForMissingBranches{};
0101
0102 public:
0103 TTreeProcessorMT(std::string_view filename, std::string_view treename = "", UInt_t nThreads = 0u,
0104 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
0105 TTreeProcessorMT(const std::vector<std::string_view> &filenames, std::string_view treename = "",
0106 UInt_t nThreads = 0u,
0107 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
0108 TTreeProcessorMT(std::initializer_list<std::string_view> filenames, std::string_view treename = "", UInt_t nThreads = 0u,
0109 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()}):
0110 TTreeProcessorMT(std::vector<std::string_view>(filenames), treename, nThreads, globalRange) {}
0111 TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads = 0u,
0112 const std::set<std::string> &suppressErrorsForMissingBranches = {});
0113 TTreeProcessorMT(TTree &tree, UInt_t nThreads = 0u,
0114 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()},
0115 const std::set<std::string> &suppressErrorsForMissingBranches = {});
0116
0117 void Process(std::function<void(TTreeReader &)> func);
0118
0119 static void SetTasksPerWorkerHint(unsigned int m);
0120 static unsigned int GetTasksPerWorkerHint();
0121 };
0122
0123 }
0124
0125 #endif