38 MakeClusters(
const std::string &treeName,
const std::vector<std::string> &fileNames)
43 std::vector<EntryCluster> clusters;
44 std::vector<Long64_t> nEntries;
45 const auto nFileNames = fileNames.size();
47 for (
auto i = 0u; i < nFileNames; ++i) {
48 std::unique_ptr<TFile>
f(
TFile::Open(fileNames[i].c_str()));
50 f->GetObject(treeName.c_str(), t);
51 auto clusterIter = t->GetClusterIterator(0);
53 const Long64_t entries = t->GetEntries();
54 nEntries.emplace_back(entries);
56 while ((start = clusterIter()) < entries) {
57 end = clusterIter.GetNextEntry();
59 clusters.emplace_back(
EntryCluster{start + offset, end + offset});
64 return std::make_pair(std::move(clusters), std::move(nEntries));
69 std::vector<std::vector<Long64_t>>
GetFriendEntries(
const std::vector<std::pair<std::string, std::string>> &friendNames,
70 const std::vector<std::vector<std::string>> &friendFileNames)
72 std::vector<std::vector<Long64_t>> friendEntries;
73 const auto nFriends = friendNames.size();
74 for (
auto i = 0u; i < nFriends; ++i) {
75 std::vector<Long64_t> nEntries;
76 const auto &thisFriendName = friendNames[i].first;
77 const auto &thisFriendFiles = friendFileNames[i];
78 for (
const auto &fname : thisFriendFiles) {
81 f->GetObject(thisFriendName.c_str(), t);
82 nEntries.emplace_back(t->GetEntries());
84 friendEntries.emplace_back(std::move(nEntries));
95 if (0 == strcmp(
"TChain", tree.ClassName())) {
96 auto &chain =
dynamic_cast<const TChain&
>(
tree);
98 if (files && 0 != files->GetEntries()) {
104 if (
auto motherDir = tree.GetDirectory()) {
105 std::string fullPath(motherDir->GetPath());
107 fullPath += tree.GetName();
112 return tree.GetName();
117 static const TClassRef clRefTChain(
"TChain");
118 if (clRefTChain == tree.IsA()) {
121 for (
auto f : *filelist)
126 auto msg =
"The provided chain of files is empty, cannot process tree " +
fTreeName;
127 throw std::runtime_error(msg);
131 TFile *
f = tree.GetCurrentFile();
137 auto msg =
"The specified TTree is not linked to any file, in-memory-only trees are not supported. Cannot process tree " +
fTreeName;
138 throw std::runtime_error(msg);
196 const auto &clusters = clustersAndEntries.first;
197 const auto &entries = clustersAndEntries.second;
199 const auto friendEntries =
206 std::unique_ptr<TTreeReader>
reader;
207 std::unique_ptr<TEntryList> elist;
217 pool.
Foreach(mapFunction, clusters);
void Foreach(F func, unsigned nTimes)
Execute func (with no arguments) nTimes in parallel.
const std::vector< std::string > & GetFileNames() const
Get the filenames for this view.
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Namespace for new ROOT classes and functions.
TObject * At(Int_t idx) const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
TObjArray * GetListOfFiles() const
std::string GetTreeName() const
Get the name of the tree of this view.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
const std::vector< NameAlias > & GetFriendNames() const
std::string fTreeName
Name of the tree.
std::vector< std::string > fFileNames
Names of the files.
void StoreFriends(const TTree &tree, bool isTree)
Get and store the names, aliases and file names of the friends of the tree.
This class provides a simple interface to execute the same task multiple times in parallel...
void PopTaskFirstEntry()
Restore the tree of the previous loaded entry, if any.
std::vector< std::vector< Long64_t > > GetFriendEntries(const std::vector< std::pair< std::string, std::string >> &friendNames, const std::vector< std::vector< std::string >> &friendFileNames)
Return a vector containing the number of entries of each file of each friend TChain.
TreeReaderEntryListPair GetTreeReader(Long64_t start, Long64_t end, const std::vector< Long64_t > &nEntries, const std::vector< std::vector< Long64_t >> &friendEntries)
Get a TTreeReader for the current tree of this view.
const std::vector< std::vector< std::string > > & GetFriendFileNames() const
void PushTaskFirstEntry(Long64_t entry)
Push a new loaded entry to the stack.
void Process(std::function< void(TTreeReader &)> func)
Process the entries of a TTree in parallel.
ClustersAndEntries MakeClusters(const std::string &treename, const std::vector< std::string > &filenames)
Return a vector of cluster boundaries for the given tree and files.
basic_string_view< char > string_view
ROOT::TThreadedObject< ROOT::Internal::TTreeView > treeView
! Thread-local TreeViews
std::pair< std::vector< EntryCluster >, std::vector< Long64_t > > ClustersAndEntries
TClassRef is used to implement a permanent reference to a TClass object.
A chain is a collection of files containing TTree objects.
Int_t GetEntries() const
Return the number of objects in array (i.e.
TTreeProcessorMT(std::string_view filename, std::string_view treename="")
Constructor based on a file name.
virtual const char * GetName() const
Returns name of object.
A List of entry numbers in a TTree or TChain.
TTreeView(std::string_view fn, std::string_view tn)
Constructor based on a file name.
static std::string GetTreeFullPath(const TTree &tree)
Return the full path of the tree.