|
| 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 | +} |
0 commit comments