Skip to content

Commit 5ba79a9

Browse files
magnustymoteussilverweed
authored andcommitted
[ntuplebrowse] Add treemap to classic ntuplebrowser
1 parent d8748af commit 5ba79a9

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

config/mimes.unix.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ pattern = RNTuple-leaf
255255
icon = leaf_s.xpm leaf_t.xpm
256256
action = ->Browse()
257257

258+
[root/rntuple-visualization]
259+
pattern = RNTuple-visualization
260+
icon = bld_listtree.xpm
261+
action = ->Browse()
262+
258263
# actions used by GuiBuilder
259264
[root/textbutton]
260265
pattern = TGTextButton

config/mimes.win32.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ pattern = RNTuple-leaf
255255
icon = leaf_s.xpm leaf_t.xpm
256256
action = ->Browse()
257257

258+
[root/rntuple-visualization]
259+
pattern = RNTuple-visualization
260+
icon = bld_listtree.xpm
261+
action = ->Browse()
262+
258263
# actions used by GuiBuilder
259264
[root/textbutton]
260265
pattern = TGTextButton

tree/ntuplebrowse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DEPENDENCIES
2626
Graf
2727
Hist
2828
ROOTNTuple
29+
ROOTTreeMap
2930
)
3031

3132
ROOT_ADD_TEST_SUBDIRECTORY(test)

tree/ntuplebrowse/src/RNTupleClassicBrowse.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <ROOT/RNTupleDrawVisitor.hxx>
1818
#include <ROOT/RNTupleDescriptor.hxx>
1919
#include <ROOT/RNTupleReader.hxx>
20+
#include <ROOT/RTreeMapPainter.hxx>
21+
#include <ROOT/RNTupleInspector.hxx>
2022

2123
#include <TBrowser.h>
2224
#include <TObject.h>
@@ -91,6 +93,32 @@ class RFieldBrowsable final : public TObject {
9193
const char *GetTitle() const final { return fTypeName.c_str(); }
9294
};
9395

96+
class RVisualizationBrowsable : public TObject {
97+
private:
98+
std::unique_ptr<ROOT::Experimental::RNTupleInspector> fInspector;
99+
std::unique_ptr<ROOT::Experimental::RTreeMapPainter> fTreeMap;
100+
101+
public:
102+
RVisualizationBrowsable(const ROOT::RNTuple &ntuple)
103+
: fInspector(ROOT::Experimental::RNTupleInspector::Create(ntuple))
104+
{
105+
}
106+
void Browse(TBrowser *b) final
107+
{
108+
if (!b || !gPad)
109+
return;
110+
gPad->GetListOfPrimitives()->Clear();
111+
fTreeMap = ROOT::Experimental::RTreeMapPainter::ImportRNTuple(*fInspector);
112+
fTreeMap->Paint("");
113+
gPad->Update();
114+
}
115+
116+
const char *GetIconName() const final { return "RNTuple-visualization"; }
117+
bool IsFolder() const final { return false; }
118+
const char *GetName() const final { return "Visualization"; }
119+
const char *GetTitle() const final { return "TreeMap visualization of RNTuple structure and disk usage"; }
120+
};
121+
94122
} // anonymous namespace
95123

96124
void ROOT::Internal::BrowseRNTuple(const void *ntuple, TBrowser *b)
@@ -100,6 +128,7 @@ void ROOT::Internal::BrowseRNTuple(const void *ntuple, TBrowser *b)
100128

101129
std::shared_ptr<ROOT::RNTupleReader> reader = RNTupleReader::Open(*static_cast<const ROOT::RNTuple *>(ntuple));
102130
const auto &desc = reader->GetDescriptor();
131+
b->Add(new RVisualizationBrowsable(*static_cast<const ROOT::RNTuple *>(ntuple)), "Visualization");
103132
for (const auto &f : desc.GetTopLevelFields()) {
104133
b->Add(new RFieldBrowsable(reader, f.GetId()), f.GetFieldName().c_str());
105134
}

tree/ntuplebrowse/test/ntuple_browse.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ TEST(RNTupleBrowse, Simple)
7272

7373
ROOT::Internal::BrowseRNTuple(ntpl.get(), b);
7474

75-
ASSERT_EQ(1u, imp->fAdded.size());
76-
EXPECT_EQ("f", imp->fAdded[0]);
75+
ASSERT_EQ(2u, imp->fAdded.size());
76+
EXPECT_EQ("f", imp->fAdded[1]);
7777
}

0 commit comments

Comments
 (0)