Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REntry.hxx
Go to the documentation of this file.
1/// \file ROOT/REntry.hxx
2/// \ingroup NTuple ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2018-07-19
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_REntry
17#define ROOT7_REntry
18
19#include <ROOT/RError.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#include <vector>
29
30namespace ROOT {
31namespace Experimental {
32
33// clang-format off
34/**
35\class ROOT::Experimental::REntry
36\ingroup NTuple
37\brief The REntry is a collection of values in an ntuple corresponding to a complete row in the data set
38
39The entry provides a memory-managed binder for a set of values. Through shared pointers, the memory locations
40that are associated to values are managed.
41*/
42// clang-format on
43class REntry {
44 friend class RNTupleModel;
45
46 /// The entry must be linked to a specific model (or one if its clones), identified by a model ID
47 std::uint64_t fModelId = 0;
48 /// Corresponds to the top-level fields of the linked model
49 std::vector<Detail::RFieldValue> fValues;
50 /// The objects involed in serialization and deserialization might be used long after the entry is gone:
51 /// hence the shared pointer
52 std::vector<std::shared_ptr<void>> fValuePtrs;
53 /// Points into fValues and indicates the values that are owned by the entry and need to be destructed
54 std::vector<std::size_t> fManagedValues;
55
56 // Creation of entries is done by the RNTupleModel class
57
58 REntry() = default;
59 explicit REntry(std::uint64_t modelId) : fModelId(modelId) {}
60
61 /// Adds a value whose storage is managed by the entry
63
64 /// Adds a value whose storage is _not_ managed by the entry
66
67 /// While building the entry, adds a new value to the list and return the value's shared pointer
68 template<typename T, typename... ArgsT>
69 std::shared_ptr<T> AddValue(RField<T>* field, ArgsT&&... args) {
70 auto ptr = std::make_shared<T>(std::forward<ArgsT>(args)...);
71 fValues.emplace_back(Detail::RFieldValue(field->CaptureValue(ptr.get())));
72 fValuePtrs.emplace_back(ptr);
73 return ptr;
74 }
75
76public:
77 using Iterator_t = decltype(fValues)::iterator;
78
79 REntry(const REntry &other) = delete;
80 REntry &operator=(const REntry &other) = delete;
81 REntry(REntry &&other) = default;
82 REntry &operator=(REntry &&other) = default;
83 ~REntry();
84
85 void CaptureValueUnsafe(std::string_view fieldName, void *where);
86
87 Detail::RFieldValue GetValue(std::string_view fieldName) const
88 {
89 for (auto& v : fValues) {
90 if (v.GetField()->GetName() == fieldName)
91 return v;
92 }
93 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
94 }
95
96 template <typename T>
97 T *Get(std::string_view fieldName) const
98 {
99 for (auto& v : fValues) {
100 if (v.GetField()->GetName() == fieldName) {
101 R__ASSERT(v.GetField()->GetType() == RField<T>::TypeName());
102 return v.Get<T>();
103 }
104 }
105 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
106 }
107
108 std::uint64_t GetModelId() const { return fModelId; }
109
110 Iterator_t begin() { return fValues.begin(); }
111 Iterator_t end() { return fValues.end(); }
112};
113
114} // namespace Experimental
115} // namespace ROOT
116
117#endif
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:303
#define R__ASSERT(e)
Definition TError.h:117
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Detail::RFieldValue CaptureValue(void *where) final
Creates a value from a memory location with an already constructed object.
Definition RField.cxx:958
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition REntry.hxx:43
std::uint64_t fModelId
The entry must be linked to a specific model (or one if its clones), identified by a model ID.
Definition REntry.hxx:47
REntry & operator=(REntry &&other)=default
REntry & operator=(const REntry &other)=delete
T * Get(std::string_view fieldName) const
Definition REntry.hxx:97
Detail::RFieldValue GetValue(std::string_view fieldName) const
Definition REntry.hxx:87
REntry(std::uint64_t modelId)
Definition REntry.hxx:59
REntry(REntry &&other)=default
std::vector< std::shared_ptr< void > > fValuePtrs
The objects involed in serialization and deserialization might be used long after the entry is gone: ...
Definition REntry.hxx:52
std::vector< std::size_t > fManagedValues
Points into fValues and indicates the values that are owned by the entry and need to be destructed.
Definition REntry.hxx:54
std::uint64_t GetModelId() const
Definition REntry.hxx:108
void AddValue(const Detail::RFieldValue &value)
Adds a value whose storage is managed by the entry.
Definition REntry.cxx:29
void CaptureValueUnsafe(std::string_view fieldName, void *where)
Definition REntry.cxx:40
decltype(fValues)::iterator Iterator_t
Definition REntry.hxx:77
std::shared_ptr< T > AddValue(RField< T > *field, ArgsT &&... args)
While building the entry, adds a new value to the list and return the value's shared pointer.
Definition REntry.hxx:69
void CaptureValue(const Detail::RFieldValue &value)
Adds a value whose storage is not managed by the entry.
Definition REntry.cxx:35
REntry(const REntry &other)=delete
std::vector< Detail::RFieldValue > fValues
Corresponds to the top-level fields of the linked model.
Definition REntry.hxx:49
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:640
The RNTupleModel encapulates the schema of an ntuple.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.