32 fFriendNames.emplace_back(std::make_pair(treeName, alias));
44 const std::string &alias)
46 fFriendNames.emplace_back(std::make_pair(treeName, alias));
57 const std::string &alias)
66 auto nPairs = treeAndFileNameGlobs.size();
67 theseFileNames.reserve(nPairs);
68 theseChainSubNames.reserve(nPairs);
70 auto fSubNamesIt = std::back_inserter(theseChainSubNames);
71 auto fNamesIt = std::back_inserter(theseFileNames);
73 for (
const auto &names : treeAndFileNameGlobs) {
74 *fSubNamesIt = names.first;
75 *fNamesIt = names.second;
87 std::vector<std::string> filenames;
90 if (
auto chain =
dynamic_cast<const TChain *
>(&
tree)) {
91 const auto *chainFiles = chain->GetListOfFiles();
93 throw std::runtime_error(
"Could not retrieve a list of files from the input TChain.");
97 const auto nfiles = chainFiles->GetEntries();
99 throw std::runtime_error(
"The list of files associated with the input TChain is empty.");
101 filenames.reserve(nfiles);
102 for (
const auto *
f : *chainFiles)
103 filenames.emplace_back(
f->GetTitle());
107 throw std::runtime_error(
"The input TTree is not linked to any file, "
108 "in-memory-only trees are not supported.");
111 filenames.emplace_back(
f->GetName());
154 std::vector<NameAlias> friendNames;
155 std::vector<std::vector<std::string>> friendFileNames;
156 std::vector<std::vector<std::string>> friendChainSubNames;
164 const auto *friends =
tree.GetListOfFriends();
168 for (
auto fr : *friends) {
174 friendFileNames.emplace_back();
175 auto &fileNames = friendFileNames.back();
179 friendChainSubNames.emplace_back();
180 auto &chainSubNames = friendChainSubNames.back();
183 const auto *alias_c =
tree.GetFriendAlias(frTree);
184 const std::string alias = alias_c !=
nullptr ? alias_c :
"";
187 if (
auto frChain =
dynamic_cast<const TChain *
>(frTree)) {
198 const auto *chainFiles = frChain->GetListOfFiles();
199 if (!chainFiles || chainFiles->GetEntries() == 0) {
200 throw std::runtime_error(
"A TChain in the list of friends does not contain any file. "
201 "Friends with no associated files are not supported.");
205 friendNames.emplace_back(std::make_pair(frChain->GetName(), alias));
209 for (
const auto *
f : *chainFiles) {
210 chainSubNames.emplace_back(
f->GetName());
211 fileNames.emplace_back(
f->GetTitle());
216 friendNames.emplace_back(std::make_pair(realName, alias));
219 const auto *
f = frTree->GetCurrentFile();
221 throw std::runtime_error(
"A TTree in the list of friends is not linked to any file. "
222 "Friends with no associated files are not supported.");
223 fileNames.emplace_back(
f->GetName());
227 return RFriendInfo{std::move(friendNames), std::move(friendFileNames), std::move(friendChainSubNames)};
247 if (
auto chain =
dynamic_cast<const TChain *
>(&
tree)) {
248 const auto *chainFiles = chain->GetListOfFiles();
249 if (!chainFiles || chainFiles->GetEntries() == 0) {
250 throw std::runtime_error(
"The input TChain does not contain any file.");
252 std::vector<std::string> treeNames;
253 for (
const auto *
f : *chainFiles)
254 treeNames.emplace_back(
f->GetName());
260 if (
const auto *treeDir =
tree.GetDirectory()) {
265 if (
dynamic_cast<const TFile *
>(treeDir)) {
266 return {
tree.GetName()};
268 std::string fullPath = treeDir->GetPath();
269 fullPath = fullPath.substr(fullPath.rfind(
":/") + 1);
271 fullPath +=
tree.GetName();
276 return {
tree.GetName()};
A chain is a collection of files containing TTree objects.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
A TFriendElement TF describes a TTree object TF in a file.
A TTree represents a columnar dataset.
Different standalone functions to work with trees and tuples, not reqiuired to be a member of any cla...
std::vector< std::string > GetTreeFullPaths(const TTree &tree)
RFriendInfo GetFriendInfo(const TTree &tree)
std::vector< std::string > GetFileNamesFromTree(const TTree &tree)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Information about friend trees of a certain TTree or TChain object.
std::vector< NameAlias > fFriendNames
Pairs of names and aliases of friend trees/chains.
std::vector< std::vector< std::string > > fFriendFileNames
Names of the files where each friend is stored.
void AddFriend(const std::string &treeName, const std::string &fileNameGlob, const std::string &alias="")
Add information of a single friend.
std::vector< std::vector< std::string > > fFriendChainSubNames
Names of the subtrees of a friend TChain.