Logo ROOT   6.18/05
Reference Guide
RNTupleModel.hxx
Go to the documentation of this file.
1/// \file ROOT/RNTupleModel.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-10-04
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-2019, 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 ROOT7_RNTupleModel
17#define ROOT7_RNTupleModel
18
19#include <ROOT/REntry.hxx>
20#include <ROOT/RField.hxx>
21#include <ROOT/RFieldValue.hxx>
22#include <ROOT/RStringView.hxx>
23
24#include <TError.h>
25
26#include <memory>
27#include <utility>
28
29namespace ROOT {
30namespace Experimental {
31
32class RCollectionNTuple;
33
34// clang-format off
35/**
36\class ROOT::Experimental::RNTupleModel
37\ingroup NTuple
38\brief The RNTupleModel encapulates the schema of an ntuple.
39
40The ntuple model comprises a collection of hierarchically organized fields. From a frozen model, "entries"
41can be extracted. For convenience, the model provides a default entry. Models have a unique model identifier
42that faciliates checking whether entries are compatible with it (i.e.: have been extracted from that model).
43A model needs to be frozen before it can be used to create a live ntuple.
44*/
45// clang-format on
47 /// Hierarchy of fields consisting of simple types and collections (sub trees)
48 std::unique_ptr<RFieldRoot> fRootField;
49 /// Contains field values corresponding to the created top-level fields
50 std::unique_ptr<REntry> fDefaultEntry;
51
52public:
54 RNTupleModel(const RNTupleModel&) = delete;
56 ~RNTupleModel() = default;
57
59 static std::unique_ptr<RNTupleModel> Create() { return std::make_unique<RNTupleModel>(); }
60
61 /// Creates a new field and a corresponding tree value that is managed by a shared pointer.
62 template <typename T, typename... ArgsT>
63 std::shared_ptr<T> MakeField(std::string_view fieldName, ArgsT&&... args) {
64 auto field = std::make_unique<RField<T>>(fieldName);
65 auto ptr = fDefaultEntry->AddValue<T>(field.get(), std::forward<ArgsT>(args)...);
66 fRootField->Attach(std::move(field));
67 return ptr;
68 }
69
70 /// Adds a field whose type is not known at compile time. Thus there is no shared pointer returned.
71 void AddField(std::unique_ptr<Detail::RFieldBase> field);
72
73 template <typename T>
74 void AddField(std::string_view fieldName, T* fromWhere) {
75 auto field = std::make_unique<RField<T>>(fieldName);
76 fDefaultEntry->CaptureValue(field->CaptureValue(fromWhere));
77 fRootField->Attach(std::move(field));
78 }
79
80 template <typename T>
81 T* Get(std::string_view fieldName) {
82 return fDefaultEntry->Get<T>(fieldName);
83 }
84
85 /// Ingests a model for a sub collection and attaches it to the current model
86 std::shared_ptr<RCollectionNTuple> MakeCollection(
87 std::string_view fieldName,
88 std::unique_ptr<RNTupleModel> collectionModel);
89
90 RFieldRoot* GetRootField() { return fRootField.get(); }
92 std::unique_ptr<REntry> CreateEntry();
93};
94
95} // namespace Exerimental
96} // namespace ROOT
97
98#endif
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition: REntry.hxx:42
The container field for a tree model, which itself has no physical representation.
Definition: RField.hxx:225
The RNTupleModel encapulates the schema of an ntuple.
std::shared_ptr< RCollectionNTuple > MakeCollection(std::string_view fieldName, std::unique_ptr< RNTupleModel > collectionModel)
Ingests a model for a sub collection and attaches it to the current model.
T * Get(std::string_view fieldName)
RNTupleModel(const RNTupleModel &)=delete
std::unique_ptr< RFieldRoot > fRootField
Hierarchy of fields consisting of simple types and collections (sub trees)
void AddField(std::string_view fieldName, T *fromWhere)
std::unique_ptr< REntry > CreateEntry()
std::unique_ptr< REntry > fDefaultEntry
Contains field values corresponding to the created top-level fields.
std::shared_ptr< T > MakeField(std::string_view fieldName, ArgsT &&... args)
Creates a new field and a corresponding tree value that is managed by a shared pointer.
static std::unique_ptr< RNTupleModel > Create()
RNTupleModel & operator=(const RNTupleModel &)=delete
void AddField(std::unique_ptr< Detail::RFieldBase > field)
Adds a field whose type is not known at compile time. Thus there is no shared pointer returned.
basic_string_view< char > string_view
double T(double x)
Definition: ChebyshevPol.h:34
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21