34 fFriendNames.emplace_back(std::make_pair(treeName, alias));
46 const std::string &alias)
48 fFriendNames.emplace_back(std::make_pair(treeName, alias));
59 const std::string &alias)
68 auto nPairs = treeAndFileNameGlobs.size();
69 theseFileNames.reserve(nPairs);
70 theseChainSubNames.reserve(nPairs);
72 auto fSubNamesIt = std::back_inserter(theseFileNames);
73 auto fNamesIt = std::back_inserter(theseChainSubNames);
75 for (
const auto &names : treeAndFileNameGlobs) {
76 *fSubNamesIt = names.first;
77 *fNamesIt = names.second;
89 std::vector<std::string> filenames;
92 if (
auto chain =
dynamic_cast<const TChain *
>(&
tree)) {
93 const auto *chainFiles = chain->GetListOfFiles();
95 throw std::runtime_error(
"Could not retrieve a list of files from the input TChain.");
99 const auto nfiles = chainFiles->GetEntries();
101 throw std::runtime_error(
"The list of files associated with the input TChain is empty.");
103 filenames.reserve(nfiles);
104 for (
const auto *
f : *chainFiles)
105 filenames.emplace_back(
f->GetTitle());
109 throw std::runtime_error(
"The input TTree is not linked to any file, "
110 "in-memory-only trees are not supported.");
113 filenames.emplace_back(
f->GetName());
157 std::vector<NameAlias> friendNames;
158 std::vector<std::vector<std::string>> friendFileNames;
159 std::vector<std::vector<std::string>> friendChainSubNames;
167 const auto *friends =
tree.GetListOfFriends();
171 for (
auto fr : *friends) {
177 friendFileNames.emplace_back();
178 auto &fileNames = friendFileNames.back();
182 friendChainSubNames.emplace_back();
183 auto &chainSubNames = friendChainSubNames.back();
186 const auto *alias_c =
tree.GetFriendAlias(frTree);
187 const std::string alias = alias_c !=
nullptr ? alias_c :
"";
190 if (
auto frChain =
dynamic_cast<const TChain *
>(frTree)) {
201 const auto *chainFiles = frChain->GetListOfFiles();
202 if (!chainFiles || chainFiles->GetEntries() == 0) {
203 throw std::runtime_error(
"A TChain in the list of friends does not contain any file. "
204 "Friends with no associated files are not supported.");
208 friendNames.emplace_back(std::make_pair(frChain->GetName(), alias));
212 for (
const auto *
f : *chainFiles) {
213 chainSubNames.emplace_back(
f->GetName());
214 fileNames.emplace_back(
f->GetTitle());
219 friendNames.emplace_back(std::make_pair(realName, alias));
222 const auto *
f = frTree->GetCurrentFile();
224 throw std::runtime_error(
"A TTree in the list of friends is not linked to any file. "
225 "Friends with no associated files are not supported.");
226 fileNames.emplace_back(
f->GetName());
230 return RFriendInfo{std::move(friendNames), std::move(friendFileNames), std::move(friendChainSubNames)};
250 if (
auto chain =
dynamic_cast<const TChain *
>(&
tree)) {
251 const auto *chainFiles = chain->GetListOfFiles();
252 if (!chainFiles || chainFiles->GetEntries() == 0) {
253 throw std::runtime_error(
"The input TChain does not contain any file.");
255 std::vector<std::string> treeNames;
256 for (
const auto *
f : *chainFiles)
257 treeNames.emplace_back(
f->GetName());
263 if (
const auto *treeDir =
tree.GetDirectory()) {
268 if (
dynamic_cast<const TFile *
>(treeDir)) {
269 return {
tree.GetName()};
271 std::string fullPath = treeDir->GetPath();
272 fullPath = fullPath.substr(fullPath.rfind(
":/") + 1);
274 fullPath +=
tree.GetName();
279 return {
tree.GetName()};
295 TObjArray *subBranches = branch->GetListOfBranches();
297 TObjArray *leaves = branch->GetListOfLeaves();
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.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Mother of all ROOT objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
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)
Retrieve the full path(s) to a TTree or the trees in a TChain.
RFriendInfo GetFriendInfo(const TTree &tree)
Get and store the names, aliases and file names of the direct friends of the tree.
std::vector< std::string > GetFileNamesFromTree(const TTree &tree)
Get and store the file names associated with the input tree.
void ClearMustCleanupBits(TObjArray &arr)
Reset the kMustCleanup bit of a TObjArray of TBranch objects (e.g.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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.