Skip to content

Commit 704b34e

Browse files
committed
[ntuple] Add initial RNTupleBrowse library
Implementation of the browsing logic with the classic T(Root)Browser.
1 parent 7fa6143 commit 704b34e

11 files changed

Lines changed: 229 additions & 0 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interpreter/cling/tools/packaging @vgvassilev
4141
/tree/dataframe/ @martamaja10 @vepadulano
4242
/tree/readspeed/ @martamaja10
4343
/tree/ntuple/ @jblomer
44+
/tree/ntuplebrowse/ @jblomer
4445
/tree/ntupleutil/v7/ @jblomer
4546
/tutorials/sql/ @linev
4647

gui/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Gui
204204
Gpad
205205
Graf
206206
MathCore
207+
ROOTNTupleBrowse
207208
)
208209

209210
target_include_directories(Gui PRIVATE ${CMAKE_SOURCE_DIR}/gui/ged/inc)

gui/gui/src/TRootBrowser.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Here is the list of available options:
6060
6161
*/
6262

63+
#include <ROOT/RNTupleClassicBrowse.hxx>
64+
6365
#include "TROOT.h"
6466
#include "TSystem.h"
6567
#include "TApplication.h"
@@ -163,6 +165,11 @@ TRootBrowser::TRootBrowser(TBrowser *b, const char *name, Int_t x, Int_t y,
163165

164166
void TRootBrowser::CreateBrowser(const char *name)
165167
{
168+
static bool hasRNTupleBrowsing __attribute__((unused)) = [](){
169+
TClass::GetClass("ROOT::RNTuple")->SetBrowse(ROOT::Internal::BrowseRNTuple);
170+
return true;
171+
}();
172+
166173
// Create the actual interface.
167174

168175
fVf = new TGVerticalFrame(this, 100, 100);

tree/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ if(webgui)
1212
endif()
1313
add_subdirectory(dataframe)
1414
add_subdirectory(ntuple)
15+
add_subdirectory(ntuplebrowse)
1516
add_subdirectory(ntupleutil)
1617
add_subdirectory(readspeed)

tree/ntuplebrowse/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (C) 1995-2025, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
############################################################################
8+
# CMakeLists.txt file for building ROOT ntuplebrowse package
9+
# @author Jakob Blomer CERN
10+
############################################################################
11+
12+
ROOT_STANDARD_LIBRARY_PACKAGE(ROOTNTupleBrowse
13+
HEADERS
14+
ROOT/RNTupleClassicBrowse.hxx
15+
SOURCES
16+
src/RNTupleClassicBrowse.cxx
17+
LINKDEF
18+
LinkDef.h
19+
DEPENDENCIES
20+
Core
21+
ROOTNTuple
22+
)
23+
24+
ROOT_ADD_TEST_SUBDIRECTORY(test)

tree/ntuplebrowse/doc/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Implements the browsing logic for RNTuple with the TBrowser.
2+
The `TRootBrowser` sets the `BrowseRNTuple` as `ROOT::RNTuple`'s browsing function through `TClass`.

tree/ntuplebrowse/inc/LinkDef.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Author: Jakob Blomer CERN 06/2025
2+
3+
/*************************************************************************
4+
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
5+
* All rights reserved. *
6+
* *
7+
* For the licensing terms see $ROOTSYS/LICENSE. *
8+
* For the list of contributors see $ROOTSYS/README/CREDITS. *
9+
*************************************************************************/
10+
11+
#ifdef __CLING__
12+
13+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// \file ROOT/RNTupleClassicBrowse.hxx
2+
/// \ingroup NTuple
3+
/// \author Jakob Blomer <jblomer@cern.ch>
4+
/// \date 2025-06-60
5+
/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6+
/// is welcome!
7+
8+
/*************************************************************************
9+
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
10+
* All rights reserved. *
11+
* *
12+
* For the licensing terms see $ROOTSYS/LICENSE. *
13+
* For the list of contributors see $ROOTSYS/README/CREDITS. *
14+
*************************************************************************/
15+
16+
#ifndef ROOT_RNTupleClassicBrowse
17+
#define ROOT_RNTupleClassicBrowse
18+
19+
class TBrowser;
20+
21+
namespace ROOT {
22+
namespace Internal {
23+
24+
void BrowseRNTuple(const void *ntuple, TBrowser *b);
25+
26+
} // namespace Internal
27+
} // namespace ROOT
28+
29+
#endif
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/// \file RNTupleClassicBrowse.cxx
2+
/// \ingroup NTuple
3+
/// \author Jakob Blomer <jblomer@cern.ch>
4+
/// \date 2025-06-30
5+
6+
/*************************************************************************
7+
* Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
8+
* All rights reserved. *
9+
* *
10+
* For the licensing terms see $ROOTSYS/LICENSE. *
11+
* For the list of contributors see $ROOTSYS/README/CREDITS. *
12+
*************************************************************************/
13+
14+
#include <ROOT/RNTuple.hxx>
15+
#include <ROOT/RNTupleClassicBrowse.hxx>
16+
#include <ROOT/RNTupleDescriptor.hxx>
17+
#include <ROOT/RNTupleReader.hxx>
18+
19+
#include <TBrowser.h>
20+
#include <TObject.h>
21+
22+
#include <memory>
23+
#include <string>
24+
25+
namespace {
26+
27+
class RFieldBrowsable final : public TObject {
28+
private:
29+
std::shared_ptr<ROOT::RNTupleReader> fReader;
30+
ROOT::DescriptorId_t fFieldId = ROOT::kInvalidDescriptorId;
31+
32+
public:
33+
RFieldBrowsable(std::shared_ptr<ROOT::RNTupleReader> reader, ROOT::DescriptorId_t fieldId)
34+
: fReader(reader), fFieldId(fieldId)
35+
{
36+
}
37+
38+
void Browse(TBrowser *b) final
39+
{
40+
if (!b)
41+
return;
42+
43+
const auto &desc = fReader->GetDescriptor();
44+
for (const auto &f : desc.GetFieldIterable(fFieldId)) {
45+
b->Add(new RFieldBrowsable(fReader, f.GetId()), f.GetFieldName().c_str());
46+
}
47+
}
48+
};
49+
50+
} // anonymous namespace
51+
52+
void ROOT::Internal::BrowseRNTuple(const void *ntuple, TBrowser *b)
53+
{
54+
if (!b)
55+
return;
56+
57+
std::shared_ptr<ROOT::RNTupleReader> reader = RNTupleReader::Open(*static_cast<const ROOT::RNTuple *>(ntuple));
58+
const auto &desc = reader->GetDescriptor();
59+
for (const auto &f : desc.GetTopLevelFields()) {
60+
b->Add(new RFieldBrowsable(reader, f.GetId()), f.GetFieldName().c_str());
61+
}
62+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (C) 1995-2025, Rene Brun and Fons Rademakers.
2+
# All rights reserved.
3+
#
4+
# For the licensing terms see $ROOTSYS/LICENSE.
5+
# For the list of contributors see $ROOTSYS/README/CREDITS.
6+
7+
# @author Jakob Blomer CERN
8+
9+
ROOT_ADD_GTEST(ntuple_browse ntuple_browse.cxx LIBRARIES Core Gui ROOTNTuple ROOTNTupleBrowse)

0 commit comments

Comments
 (0)