Skip to content

Commit 9e9f870

Browse files
committed
[main] RootObjTree: add NodeFullPath
1 parent d4c65c5 commit 9e9f870

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

main/src/RootObjTree.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,17 @@ ROOT::CmdLine::ParseRootSources(const std::vector<std::string> &sourcesRaw, std:
155155

156156
return sources;
157157
}
158+
159+
std::string ROOT::CmdLine::NodeFullPath(const ROOT::CmdLine::RootObjTree &tree, ROOT::CmdLine::NodeIdx_t nodeIdx,
160+
ROOT::CmdLine::ENodeFullPathOpt opt)
161+
{
162+
const RootObjNode *node = &tree.fNodes[nodeIdx];
163+
std::string fullPath = node->fName;
164+
while (node->fParent != 0) {
165+
node = &tree.fNodes[node->fParent];
166+
fullPath = node->fName + (fullPath.empty() ? "" : "/") + fullPath;
167+
}
168+
if (opt == ENodeFullPathOpt::kIncludeFilename && nodeIdx > 0)
169+
fullPath = tree.fNodes[0].fName + ":" + fullPath;
170+
return fullPath;
171+
}

main/src/RootObjTree.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ struct RootObjTree {
5656
std::unique_ptr<TFile> fFile;
5757
};
5858

59+
enum class ENodeFullPathOpt {
60+
kExcludeFilename,
61+
kIncludeFilename,
62+
};
63+
/// Given a node, returns its full path. If `opt == kIncludeFilename`, the path is prepended by "filename.root:"
64+
std::string
65+
NodeFullPath(const RootObjTree &tree, NodeIdx_t nodeIdx, ENodeFullPathOpt opt = ENodeFullPathOpt::kExcludeFilename);
66+
5967
struct RootSource {
6068
std::string fFileName;
6169
RootObjTree fObjectTree;

0 commit comments

Comments
 (0)