Skip to content

Commit 025a2fe

Browse files
committed
[main] RootObjTree: extract NodeFullPath from rootls
1 parent d4c65c5 commit 025a2fe

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
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;

main/src/rootls.cxx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -509,26 +509,6 @@ static void PrintChildrenInColumns(std::ostream &stream, const RootObjTree &tree
509509
PrintNodesInColumns(stream, tree, children.begin(), children.end(), flags, indent);
510510
}
511511

512-
static std::string NodeFullPath(const RootObjTree &tree, NodeIdx_t nodeIdx)
513-
{
514-
std::vector<const std::string *> fragments;
515-
const RootObjNode *node = &tree.fNodes[nodeIdx];
516-
NodeIdx_t prevParent;
517-
do {
518-
prevParent = node->fParent;
519-
fragments.push_back(&node->fName);
520-
node = &tree.fNodes[node->fParent];
521-
} while (node->fParent != prevParent);
522-
523-
assert(!fragments.empty());
524-
525-
std::string fullPath = **fragments.rbegin();
526-
for (auto it = std::next(fragments.rbegin()), end = fragments.rend(); it != end; ++it) {
527-
fullPath += '/' + **it;
528-
}
529-
return fullPath;
530-
}
531-
532512
// Main entrypoint of the program
533513
static void RootLs(const RootLsArgs &args, std::ostream &stream = std::cout)
534514
{

0 commit comments

Comments
 (0)