Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <memory>
26#include <unordered_set>
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<RFieldZero> fFieldZero;
49 /// Contains field values corresponding to the created top-level fields
50 std::unique_ptr<REntry> fDefaultEntry;
51 /// Keeps track of which field names are taken.
52 std::unordered_set<std::string> fFieldNames;
53
54 /// Checks that user-provided field names are valid in the context
55 /// of this NTuple model. Throws an RException for invalid names.
56 void EnsureValidFieldName(std::string_view fieldName);
57
58public:
60 RNTupleModel(const RNTupleModel&) = delete;
62 ~RNTupleModel() = default;
63
64 std::unique_ptr<RNTupleModel> Clone() const;
65 static std::unique_ptr<RNTupleModel> Create() { return std::make_unique<RNTupleModel>(); }
66
67 /// Creates a new field and a corresponding tree value that is managed by a shared pointer.
68 template <typename T, typename... ArgsT>
69 std::shared_ptr<T> MakeField(std::string_view fieldName, ArgsT&&... args) {
70 EnsureValidFieldName(fieldName);
71 auto field = std::make_unique<RField<T>>(fieldName);
72 auto ptr = fDefaultEntry->AddValue<T>(field.get(), std::forward<ArgsT>(args)...);
73 fFieldZero->Attach(std::move(field));
74 return ptr;
75 }
76
77 /// Adds a field whose type is not known at compile time. Thus there is no shared pointer returned.
78 void AddField(std::unique_ptr<Detail::RFieldBase> field);
79
80 template <typename T>
81 void AddField(std::string_view fieldName, T* fromWhere) {
82 EnsureValidFieldName(fieldName);
83 auto field = std::make_unique<RField<T>>(fieldName);
84 fDefaultEntry->CaptureValue(field->CaptureValue(fromWhere));
85 fFieldZero->Attach(std::move(field));
86 }
87
88 template <typename T>
89 T* Get(std::string_view fieldName) {
90 return fDefaultEntry->Get<T>(fieldName);
91 }
92
93 /// Ingests a model for a sub collection and attaches it to the current model
94 std::shared_ptr<RCollectionNTuple> MakeCollection(
95 std::string_view fieldName,
96 std::unique_ptr<RNTupleModel> collectionModel);
97
98 RFieldZero *GetFieldZero() const { return fFieldZero.get(); }
100 std::unique_ptr<REntry> CreateEntry();
102 std::string GetDescription() const { return ""; /* TODO */ }
103 RNTupleUuid GetUuid() const { return RNTupleUuid(); /* TODO */ }
104};
105
106} // namespace Experimental
107} // namespace ROOT
108
109#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:260
The RNTupleModel encapulates the schema of an ntuple.
std::unordered_set< std::string > fFieldNames
Keeps track of which field names are taken.
void EnsureValidFieldName(std::string_view fieldName)
Checks that user-provided field names are valid in the context of this NTuple model.
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< RNTupleModel > Clone() 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
RFieldZero * GetFieldZero() 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.
std::unique_ptr< RFieldZero > fFieldZero
Hierarchy of fields consisting of simple types and collections (sub trees)
For forward and backward compatibility, attach version information to the consitituents of the file f...
std::string RNTupleUuid
Every NTuple is identified by a UUID. TODO(jblomer): should this be a TUUID?
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...