Logo ROOT  
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/RNTupleUtil.hxx>
22#include <ROOT/RFieldValue.hxx>
23#include <ROOT/RStringView.hxx>
24
25#include <TError.h>
26
27#include <memory>
28#include <utility>
29
30namespace ROOT {
31namespace Experimental {
32
33class RCollectionNTuple;
34
35// clang-format off
36/**
37\class ROOT::Experimental::RNTupleModel
38\ingroup NTuple
39\brief The RNTupleModel encapulates the schema of an ntuple.
40
41The ntuple model comprises a collection of hierarchically organized fields. From a frozen model, "entries"
42can be extracted. For convenience, the model provides a default entry. Models have a unique model identifier
43that faciliates checking whether entries are compatible with it (i.e.: have been extracted from that model).
44A model needs to be frozen before it can be used to create a live ntuple.
45*/
46// clang-format on
48 /// Hierarchy of fields consisting of simple types and collections (sub trees)
49 std::unique_ptr<RFieldRoot> fRootField;
50 /// Contains field values corresponding to the created top-level fields
51 std::unique_ptr<REntry> fDefaultEntry;
52
53public:
55 RNTupleModel(const RNTupleModel&) = delete;
57 ~RNTupleModel() = default;
58
60 static std::unique_ptr<RNTupleModel> Create() { return std::make_unique<RNTupleModel>(); }
61
62 /// Creates a new field and a corresponding tree value that is managed by a shared pointer.
63 template <typename T, typename... ArgsT>
64 std::shared_ptr<T> MakeField(std::string_view fieldName, ArgsT&&... args) {
65 auto field = std::make_unique<RField<T>>(fieldName);
66 auto ptr = fDefaultEntry->AddValue<T>(field.get(), std::forward<ArgsT>(args)...);
67 fRootField->Attach(std::move(field));
68 return ptr;
69 }
70
71 /// Adds a field whose type is not known at compile time. Thus there is no shared pointer returned.
72 void AddField(std::unique_ptr<Detail::RFieldBase> field);
73
74 template <typename T>
75 void AddField(std::string_view fieldName, T* fromWhere) {
76 auto field = std::make_unique<RField<T>>(fieldName);
77 fDefaultEntry->CaptureValue(field->CaptureValue(fromWhere));
78 fRootField->Attach(std::move(field));
79 }
80
81 template <typename T>
82 T* Get(std::string_view fieldName) {
83 return fDefaultEntry->Get<T>(fieldName);
84 }
85
86 /// Ingests a model for a sub collection and attaches it to the current model
87 std::shared_ptr<RCollectionNTuple> MakeCollection(
88 std::string_view fieldName,
89 std::unique_ptr<RNTupleModel> collectionModel);
90
91 RFieldRoot *GetRootField() const { return fRootField.get(); }
93 std::unique_ptr<REntry> CreateEntry();
95 std::string GetDescription() const { return ""; /* TODO */ }
96 RNTupleUuid GetUuid() const { return RNTupleUuid(); /* TODO */ }
97};
98
99} // namespace Experimental
100} // namespace ROOT
101
102#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 an ntuple model, which itself has no physical representation.
Definition: RField.hxx:290
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::string GetDescription() const
std::unique_ptr< RFieldRoot > fRootField
Hierarchy of fields consisting of simple types and collections (sub trees)
RFieldRoot * GetRootField() const
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.
RNTupleVersion GetVersion() const
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.
For forward and backward compatibility, attach version information to the consitituents of the file f...
basic_string_view< char > string_view
std::string RNTupleUuid
Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
double T(double x)
Definition: ChebyshevPol.h:34
VSD Structures.
Definition: StringConv.hxx:21