Logo ROOT  
Reference Guide
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 
29 namespace ROOT {
30 namespace 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 
38 The entry provides a memory-managed binder for a set of values. Through shared pointers, the memory locations
39 that are associated to values are managed.
40 */
41 // clang-format on
42 class 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 
50 public:
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 
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
ROOT::Experimental::REntry::end
Iterator_t end()
Definition: REntry.hxx:93
ROOT::Experimental::RClassField::CaptureValue
Detail::RFieldValue CaptureValue(void *where) final
Creates a value from a memory location with an already constructed object.
Definition: RField.cxx:617
ROOT::Experimental::REntry::AddValue
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
RField.hxx
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
ROOT::Experimental::REntry::Get
T * Get(std::string_view fieldName)
Definition: REntry.hxx:82
ROOT::Experimental::REntry::~REntry
~REntry()
Definition: REntry.cxx:19
ROOT::Experimental::Detail::RFieldValue
Definition: RFieldValue.hxx:41
ROOT::Experimental::REntry
The REntry is a collection of values in an ntuple corresponding to a complete row in the data set.
Definition: REntry.hxx:42
ROOT::Experimental::REntry::begin
Iterator_t begin()
Definition: REntry.hxx:92
v
@ v
Definition: rootcling_impl.cxx:3643
ROOT::Experimental::REntry::CaptureValue
void CaptureValue(const Detail::RFieldValue &value)
Adds a value whose storage is not managed by the entry.
Definition: REntry.cxx:32
ROOT::Experimental::REntry::REntry
REntry(const REntry &other)=delete
RStringView.hxx
ROOT::Experimental::REntry::operator=
REntry & operator=(const REntry &other)=delete
ROOT::Experimental::REntry::REntry
REntry()=default
ROOT::Experimental::REntry::GetValue
Detail::RFieldValue GetValue(std::string_view fieldName)
Definition: REntry.hxx:73
R__ASSERT
#define R__ASSERT(e)
Definition: TError.h:120
ROOT::Experimental::REntry::fValues
std::vector< Detail::RFieldValue > fValues
Definition: REntry.hxx:43
ROOT::Experimental::REntry::fManagedValues
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
ROOT::Experimental::REntry::fValuePtrs
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
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
ROOT::Experimental::REntry::AddValue
void AddValue(const Detail::RFieldValue &value)
Adds a value whose storage is managed by the entry.
Definition: REntry.cxx:26
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Experimental::REntry::Iterator_t
decltype(fValues)::iterator Iterator_t
Definition: REntry.hxx:51
RFieldValue.hxx
ROOT::Experimental::RField< T >
TError.h