File indexing completed on 2025-01-18 10:10:51
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 void Reset();
0076 };
0077 }
0078
0079 class TTreeProcessorMT {
0080 private:
0081 const std::vector<std::string> fFileNames;
0082 const std::vector<std::string> fTreeNames;
0083
0084 TEntryList fEntryList;
0085 ROOT::TreeUtils::RFriendInfo fFriendInfo;
0086 ROOT::TThreadExecutor fPool;
0087
0088
0089
0090 ROOT::TThreadedObject<ROOT::Internal::TTreeView> fTreeView{TNumSlots{ROOT::GetThreadPoolSize()}};
0091
0092 std::vector<std::string> FindTreeNames();
0093 static unsigned int fgTasksPerWorkerHint;
0094
0095 std::pair<Long64_t, Long64_t> fGlobalRange{0, std::numeric_limits<Long64_t>::max()};
0096
0097 public:
0098 TTreeProcessorMT(std::string_view filename, std::string_view treename = "", UInt_t nThreads = 0u,
0099 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
0100 TTreeProcessorMT(const std::vector<std::string_view> &filenames, std::string_view treename = "",
0101 UInt_t nThreads = 0u,
0102 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
0103 TTreeProcessorMT(std::initializer_list<std::string_view> filenames, 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(std::vector<std::string_view>(filenames), treename, nThreads, globalRange) {}
0106 TTreeProcessorMT(TTree &tree, const TEntryList &entries, UInt_t nThreads = 0u);
0107 TTreeProcessorMT(TTree &tree, UInt_t nThreads = 0u,
0108 const std::pair<Long64_t, Long64_t> &globalRange = {0, std::numeric_limits<Long64_t>::max()});
0109
0110 void Process(std::function<void(TTreeReader &)> func);
0111
0112 static void SetTasksPerWorkerHint(unsigned int m);
0113 static unsigned int GetTasksPerWorkerHint();
0114 };
0115
0116 }
0117
0118 #endif