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/RField.hxx>
20#include <ROOT/RFieldValue.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 std::vector<Detail::RFieldValue> fValues;
44 /// The objects involed in serialization and deserialization might be used long after the entry is gone:
45 /// hence the shared pointer
46 std::vector<std::shared_ptr<void>> fValuePtrs;
47 /// Points into fValues and indicates the values that are owned by the entry and need to be destructed
48 std::vector<std::size_t> fManagedValues;
49
50public:
51 using Iterator_t = decltype(fValues)::iterator;
52
53 REntry() = default;
54 REntry(const REntry& other) = delete;
55 REntry& operator=(const REntry& other) = delete;
56 ~REntry();
57
58 /// Adds a value whose storage is managed by the entry
59 void AddValue(const Detail::RFieldValue& value);
60
61 /// Adds a value whose storage is _not_ managed by the entry
62 void CaptureValue(const Detail::RFieldValue& value);
63
64 /// While building the entry, adds a new value to the list and return the value's shared pointer
65 template<typename T, typename... ArgsT>
66 std::shared_ptr<T> AddValue(RField<T>* field, ArgsT&&... args) {
67 auto ptr = std::make_shared<T>(std::forward<ArgsT>(args)...);
68 fValues.emplace_back(Detail::RFieldValue(field->CaptureValue(ptr.get())));
69 fValuePtrs.emplace_back(ptr);
70 return ptr;
71 }
72
73 Detail::RFieldValue GetValue(std::string_view fieldName) {
74 for (auto& v : fValues) {
75 if (v.GetField()->GetName() == fieldName)
76 return v;
77 }
78 return Detail::RFieldValue();
79 }
80
81 template<typename T>
82 T* Get(std::string_view fieldName) {
83 for (auto& v : fValues) {
84 if (v.GetField()->GetName() == fieldName) {
85 R__ASSERT(v.GetField()->GetType() == RField<T>::TypeName());
86 return static_cast<T*>(v.GetRawPtr());
87 }
88 }
89 return nullptr;
90 }
91
92 Iterator_t begin() { return fValues.begin(); }
93 Iterator_t end() { return fValues.end(); }
94};
95
96} // namespace Experimental
97} // namespace ROOT
98
99#endif
#define R__ASSERT(e)
Definition TError.h:120
Detail::RFieldValue CaptureValue(void *where) final
Creates a value from a memory location with an already constructed object.
Definition RField.cxx:617
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition REntry.hxx:42
T * Get(std::string_view fieldName)
Definition REntry.hxx:82
REntry & operator=(const REntry &other)=delete
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:46
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:48
void AddValue(const Detail::RFieldValue &value)
Adds a value whose storage is managed by the entry.
Definition REntry.cxx:26
Detail::RFieldValue GetValue(std::string_view fieldName)
Definition REntry.hxx:73
decltype(fValues)::iterator Iterator_t
Definition REntry.hxx:51
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:66
void CaptureValue(const Detail::RFieldValue &value)
Adds a value whose storage is not managed by the entry.
Definition REntry.cxx:32
REntry(const REntry &other)=delete
std::vector< Detail::RFieldValue > fValues
Definition REntry.hxx:43
Classes with dictionaries that can be inspected by TClass.
Definition RField.hxx:412
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...