12#ifndef ROOT_TTreeProcessorMT
13#define ROOT_TTreeProcessorMT
58 using NameAlias = std::pair<std::string, std::string>;
77 void MakeChain(
const std::string &treeName,
const std::vector<std::string> &fileNames,
78 const FriendInfo &friendInfo,
const std::vector<Long64_t> &nEntries,
79 const std::vector<std::vector<Long64_t>> &friendEntries)
81 const std::vector<NameAlias> &friendNames = friendInfo.
fFriendNames;
82 const std::vector<std::vector<std::string>> &friendFileNames = friendInfo.
fFriendFileNames;
85 const auto nFiles = fileNames.size();
86 for (
auto i = 0u; i < nFiles; ++i) {
87 fChain->Add(fileNames[i].c_str(), nEntries[i]);
92 const auto nFriends = friendNames.size();
93 for (
auto i = 0u; i < nFriends; ++i) {
94 const auto &friendName = friendNames[i];
95 const auto &
name = friendName.first;
96 const auto &alias = friendName.second;
99 auto frChain = std::make_unique<TChain>(
name.c_str());
100 const auto nFileNames = friendFileNames[i].size();
101 for (
auto j = 0u; j < nFileNames; ++j)
102 frChain->Add(friendFileNames[i][j].c_str(), friendEntries[i][j]);
105 fChain->AddFriend(frChain.get(), alias.c_str());
106 fFriends.emplace_back(std::move(frChain));
114 auto localList = std::make_unique<TEntryList>();
119 else if (entry >= start)
120 localList->Enter(entry);
121 }
while ((entry = globalList.
Next()) >= 0);
123 auto reader = std::make_unique<TTreeReader>(
fChain.get(), localList.get());
124 return std::make_pair(std::move(
reader), std::move(localList));
129 auto reader = std::make_unique<TTreeReader>(
fChain.get());
130 reader->SetEntriesRange(start, end);
143 const std::vector<std::string> &fileNames,
const FriendInfo &friendInfo,
144 TEntryList entryList,
const std::vector<Long64_t> &nEntries,
145 const std::vector<std::vector<Long64_t>> &friendEntries)
147 const bool usingLocalEntries = friendInfo.
fFriendNames.empty() && entryList.
GetN() == 0;
148 if (
fChain ==
nullptr || (usingLocalEntries && fileNames[0] !=
fChain->GetListOfFiles()->At(0)->GetTitle()))
149 MakeChain(treeName, fileNames, friendInfo, nEntries, friendEntries);
151 std::unique_ptr<TTreeReader>
reader;
152 std::unique_ptr<TEntryList> localList;
153 if (entryList.
GetN() > 0) {
160 return std::make_pair(std::move(
reader), std::move(localList));
std::pair< std::unique_ptr< TTreeReader >, std::unique_ptr< TEntryList > > TreeReaderEntryListPair
TTreeView(const TTreeView &)
std::unique_ptr< TChain > fChain
Chain on which to operate.
std::vector< std::unique_ptr< TChain > > fFriends
Friends of the tree/chain.
void MakeChain(const std::string &treeName, const std::vector< std::string > &fileNames, const FriendInfo &friendInfo, const std::vector< Long64_t > &nEntries, const std::vector< std::vector< Long64_t > > &friendEntries)
Construct fChain, also adding friends if needed and injecting knowledge of offsets if available.
TreeReaderEntryListPair MakeReaderWithEntryList(TEntryList &globalList, Long64_t start, Long64_t end)
TreeReaderEntryListPair GetTreeReader(Long64_t start, Long64_t end, const std::string &treeName, const std::vector< std::string > &fileNames, const FriendInfo &friendInfo, TEntryList entryList, const std::vector< Long64_t > &nEntries, const std::vector< std::vector< Long64_t > > &friendEntries)
Get a TTreeReader for the current tree of this view.
std::unique_ptr< TTreeReader > MakeReader(Long64_t start, Long64_t end)
A wrapper to make object instances thread private, lazily.
A class to process the entries of a TTree in parallel.
static unsigned int GetMaxTasksPerFilePerWorker()
Sets the maximum number of tasks created per file, per worker.
const std::string fTreeName
Name of the tree.
const std::vector< std::string > fFileNames
Names of the files.
static void SetMaxTasksPerFilePerWorker(unsigned int m)
Sets the maximum number of tasks created per file, per worker.
Internal::FriendInfo GetFriendInfo(TTree &tree)
Get and store the names, aliases and file names of the friends of the tree.
static unsigned int fgMaxTasksPerFilePerWorker
TTreeProcessorMT(std::string_view filename, std::string_view treename="")
Constructor based on a file name.
const TEntryList fEntryList
User-defined selection of entry numbers to be processed, empty if none was provided.
void Process(std::function< void(TTreeReader &)> func)
Process the entries of a TTree in parallel.
ROOT::TThreadedObject< ROOT::Internal::TTreeView > treeView
! Thread-local TreeViews
const Internal::FriendInfo fFriendInfo
std::string FindTreeName()
Retrieve the name of the first TTree in the first input file, else throw.
A chain is a collection of files containing TTree objects.
A List of entry numbers in a TTree or TChain.
virtual Long64_t Next()
Return the next non-zero entry index (next after fLastIndexQueried) this function is faster than GetE...
virtual Long64_t GetEntry(Int_t index)
Return the number of the entry #index of this TEntryList in the TTree or TChain See also Next().
virtual Long64_t GetN() const
@ kMustCleanup
if object destructor must call RecursiveRemove()
A simple, robust and fast interface to read values from ROOT colmnar datasets such as TTree,...
A TTree object has a header with a name and a title.
std::pair< std::string, std::string > NameAlias
Names, aliases, and file names of a TTree's or TChain's friends.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Namespace for new ROOT classes and functions.
basic_string_view< char > string_view
std::vector< std::vector< std::string > > fFriendFileNames
Names of the files where each friend is stored.
std::vector< Internal::NameAlias > fFriendNames
Pairs of names and aliases of friend trees/chains.