Skip to content

Commit 09f8bad

Browse files
committed
[ntuple] add basic TBrowser support
1 parent 8c63c1d commit 09f8bad

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

tree/ntuple/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ SOURCES
6464
src/RFieldVisitor.cxx
6565
src/RMiniFile.cxx
6666
src/RNTuple.cxx
67+
src/RNTupleClassicBrowse.cxx
6768
src/RNTupleDescriptor.cxx
6869
src/RNTupleDescriptorFmt.cxx
6970
src/RNTupleFillContext.cxx

tree/ntuple/inc/ROOT/RNTuple.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <cstdint>
2020

21+
class TBrowser;
2122
class TCollection;
2223
class TFile;
2324
class TFileMergeInfo;
@@ -129,6 +130,9 @@ public:
129130
/// Merge this NTuple with the input list entries
130131
Long64_t Merge(TCollection *input, TFileMergeInfo *mergeInfo);
131132

133+
/// Custom callback for the classic TBrowser
134+
void Browse(TBrowser *) const;
135+
132136
/// NOTE: if you change this version you also need to update RTFNTuple::fClassVersion in RMiniFile.cxx
133137
ClassDefNV(RNTuple, 2);
134138
}; // class RNTuple
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/// \file RNTupleClassicBrowse.cxx
2+
/// \ingroup NTuple
3+
/// \author Jakob Blomer <[email protected]>
4+
/// \date 2025-05-26
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/RNTupleReader.hxx>
16+
#include <ROOT/RNTupleUtil.hxx>
17+
18+
#include <TBrowser.h>
19+
#include <TObject.h>
20+
21+
#include <memory>
22+
23+
namespace {
24+
25+
class RFieldBrowsable final : public TObject {
26+
private:
27+
std::shared_ptr<ROOT::RNTupleReader> fReader;
28+
ROOT::DescriptorId_t fFieldId = ROOT::kInvalidDescriptorId;
29+
30+
public:
31+
RFieldBrowsable(std::shared_ptr<ROOT::RNTupleReader> reader, ROOT::DescriptorId_t fieldId)
32+
: fReader(reader), fFieldId(fieldId)
33+
{
34+
}
35+
36+
void Browse(TBrowser *b) final
37+
{
38+
if (!b)
39+
return;
40+
41+
const auto &desc = fReader->GetDescriptor();
42+
for (const auto &f : desc.GetFieldIterable(fFieldId)) {
43+
b->Add(new RFieldBrowsable(fReader, f.GetId()), f.GetFieldName().c_str());
44+
}
45+
}
46+
};
47+
48+
} // anonymous namespace
49+
50+
void ROOT::RNTuple::Browse(TBrowser *b) const
51+
{
52+
if (!b)
53+
return;
54+
55+
std::shared_ptr<ROOT::RNTupleReader> reader = RNTupleReader::Open(*this);
56+
const auto &desc = reader->GetDescriptor();
57+
for (const auto &f : desc.GetTopLevelFields()) {
58+
b->Add(new RFieldBrowsable(reader, f.GetId()), f.GetFieldName().c_str());
59+
}
60+
}

0 commit comments

Comments
 (0)