Skip to content
Snippets Groups Projects
Commit 6ed691c8 authored by Enrico Guiraud's avatar Enrico Guiraud
Browse files

[TREEPROCMT] Add routine to get number of entries in friend trees

parent 157d83e7
No related branches found
No related tags found
No related merge requests found
......@@ -60,8 +60,7 @@ namespace ROOT {
class TTreeView {
private:
using TreeReaderEntryListPair = std::pair<std::unique_ptr<TTreeReader>, std::unique_ptr<TEntryList>>;
typedef std::pair<std::string, std::string> NameAlias;
using NameAlias = std::pair<std::string, std::string>;
// NOTE: fFriends must come before fChain to be deleted after it, see ROOT-9281 for more details
std::vector<std::unique_ptr<TChain>> fFriends; ///< Friends of the tree/chain
......@@ -317,6 +316,16 @@ namespace ROOT {
fChain->LoadTree(fLoadedEntries.back());
}
}
const std::vector<NameAlias> &GetFriendNames() const
{
return fFriendNames;
}
const std::vector<std::vector<std::string>> &GetFriendFileNames() const
{
return fFriendFileNames;
}
};
} // End of namespace Internal
......
......@@ -63,6 +63,29 @@ MakeClusters(const std::string &treeName, const std::vector<std::string> &fileNa
return std::make_pair(std::move(clusters), std::move(nEntries));
}
////////////////////////////////////////////////////////////////////////
/// Return a vector containing the number of entries of each file of each friend TChain
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)
{
std::vector<std::vector<Long64_t>> friendEntries;
const auto nFriends = friendNames.size();
for (auto i = 0u; i < nFriends; ++i) {
std::vector<Long64_t> nEntries;
const auto &thisFriendName = friendNames[i].first;
const auto &thisFriendFiles = friendFileNames[i];
for (const auto &fname : thisFriendFiles) {
std::unique_ptr<TFile> f(TFile::Open(fname.c_str()));
TTree *t = nullptr; // owned by TFile
f->GetObject(thisFriendName.c_str(), t);
nEntries.emplace_back(t->GetEntries());
}
friendEntries.emplace_back(std::move(nEntries));
}
return friendEntries;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment