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/RStringView.hxx>
22
23#include <TError.h>
24
25#include <memory>
26#include <utility>
27#include <vector>
28
29namespace ROOT {
30namespace Experimental {
31
32// clang-format off
33/**
34\class ROOT::Experimental::REntry
35\ingroup NTuple
36\brief The REntry is a collection of values in an ntuple corresponding to a complete row in the data set
37
38The entry provides a memory-managed binder for a set of values. Through shared pointers, the memory locations
39that are associated to values are managed.
40*/
41// clang-format on
42class REntry {
43 friend class RNTupleModel;
44
45 /// The entry must be linked to a specific model (or one if its clones), identified by a model ID
46 std::uint64_t fModelId = 0;
47 /// Corresponds to the top-level fields of the linked model
48 std::vector<Detail::RFieldBase::RValue> fValues;
49 /// The objects involed in serialization and deserialization might be used long after the entry is gone:
50 /// hence the shared pointer
51 std::vector<std::shared_ptr<void>> fValuePtrs;
52
53 // Creation of entries is done by the RNTupleModel class
54
55 REntry() = default;
56 explicit REntry(std::uint64_t modelId) : fModelId(modelId) {}
57
59
60 /// While building the entry, adds a new value to the list and return the value's shared pointer
61 template<typename T, typename... ArgsT>
62 std::shared_ptr<T> AddValue(RField<T>* field, ArgsT&&... args) {
63 auto ptr = std::make_shared<T>(std::forward<ArgsT>(args)...);
64 fValues.emplace_back(field->BindValue(ptr.get()));
65 fValuePtrs.emplace_back(ptr);
66 return ptr;
67 }
68
69public:
70 using Iterator_t = decltype(fValues)::iterator;
71
72 REntry(const REntry &other) = delete;
73 REntry &operator=(const REntry &other) = delete;
74 REntry(REntry &&other) = default;
75 REntry &operator=(REntry &&other) = default;
76 ~REntry() = default;
77
78 void CaptureValueUnsafe(std::string_view fieldName, void *where);
79
80 template <typename T>
81 T *Get(std::string_view fieldName) const
82 {
83 for (auto& v : fValues) {
84 if (v.GetField()->GetName() == fieldName) {
85 R__ASSERT(v.GetField()->GetType() == RField<T>::TypeName());
86 return v.Get<T>();
87 }
88 }
89 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
90 }
91
92 void *GetRawPtr(std::string_view fieldName) const
93 {
94 for (auto& v : fValues) {
95 if (v.GetField()->GetName() == fieldName) {
96 return v.GetRawPtr();
97 }
98 }
99 throw RException(R__FAIL("invalid field name: " + std::string(fieldName)));
100 }
101
102 std::uint64_t GetModelId() const { return fModelId; }
103
104 Iterator_t begin() { return fValues.begin(); }
105 Iterator_t end() { return fValues.end(); }
106};
107
108} // namespace Experimental
109} // namespace ROOT
110
111#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:118
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Points to an object with RNTuple I/O support and keeps a pointer to the corresponding field.
Definition RField.hxx:140
RValue BindValue(void *where)
Creates a value from a memory location with an already constructed object.
Definition RField.hxx:569
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition REntry.hxx:42
void AddValue(Detail::RFieldBase::RValue &&value)
Definition REntry.cxx:21
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:46
REntry & operator=(REntry &&other)=default
REntry & operator=(const REntry &other)=delete
T * Get(std::string_view fieldName) const
Definition REntry.hxx:81
REntry(std::uint64_t modelId)
Definition REntry.hxx:56
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:51
std::uint64_t GetModelId() const
Definition REntry.hxx:102
std::vector< Detail::RFieldBase::RValue > fValues
Corresponds to the top-level fields of the linked model.
Definition REntry.hxx:48
void CaptureValueUnsafe(std::string_view fieldName, void *where)
Definition REntry.cxx:26
void * GetRawPtr(std::string_view fieldName) const
Definition REntry.hxx:92
decltype(fValues)::iterator Iterator_t
Definition REntry.hxx:70
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:62
REntry(const REntry &other)=delete
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:1215
The RNTupleModel encapulates the schema of an ntuple.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.