26constexpr char const *kFileName =
"ntpl016_streaming_vector.root";
27constexpr char const *kNTupleName =
"ntpl";
28constexpr char const *kFieldName =
"LargeVector";
29constexpr unsigned int kNEvents = 10;
30constexpr unsigned int kNElementsPerVector = 1000000;
37 auto ptrLargeVector = model->MakeField<std::vector<std::uint32_t>>(kFieldName);
40 auto prng = std::make_unique<TRandom3>();
44 ptrLargeVector->clear();
45 for (std::size_t j = 0; j < kNElementsPerVector; j++)
46 ptrLargeVector->emplace_back(prng->Integer(-1));
49 std::cout <<
"RNTuple written" << std::endl;
57void ReadRNTupleSimple()
61 const auto nEntries = reader->GetNEntries();
62 std::cout <<
"Simple reading, found " << nEntries <<
" entries" << std::endl;
64 auto ptrLargeVector = reader->GetModel().GetDefaultEntry().GetPtr<std::vector<std::uint32_t>>(kFieldName);
68 const auto vectorSize = ptrLargeVector->size();
70 for (
auto val : *ptrLargeVector)
73 std::cout <<
"Size and sum of vector: " << vectorSize <<
" " <<
sum << std::endl;
75 std::cout <<
"RNTuple simple read" << std::endl;
93class StreamingVectorView {
96 ROOT::RNTupleCollectionView fVectorView;
98 ROOT::RNTupleView<T> fItemView;
111 ROOT::RNTupleLocalRange::RIterator fRangeItr;
112 ROOT::RNTupleView<T> &fView;
115 using iterator = Iterator;
116 using iterator_category = std::input_iterator_tag;
117 using value_type =
T;
118 using pointer =
const T *;
119 using reference =
const T &;
121 Iterator(ROOT::RNTupleLocalRange::RIterator rangeItr, ROOT::RNTupleView<T> &view)
122 : fRangeItr(rangeItr), fView(view)
126 iterator operator++(
int)
132 iterator &operator++()
137 reference
operator*() {
return fView.operator()(*fRangeItr); }
138 pointer operator->() {
return &fView.operator()(*fRangeItr); }
139 bool operator==(
const iterator &rh)
const {
return fRangeItr == rh.fRangeItr; }
140 bool operator!=(
const iterator &rh)
const {
return fRangeItr != rh.fRangeItr; }
143 explicit StreamingVectorView(ROOT::RNTupleCollectionView vectorView)
144 : fVectorView(std::move(vectorView)), fItemView(fVectorView.GetView<
T>(
"_0"))
151 Iterator begin() {
return Iterator(fRange.
begin(), fItemView); }
152 Iterator end() {
return Iterator(fRange.
end(), fItemView); }
158 fSize = fVectorView.operator()(fEntry);
165void ReadRNTupleStreamingVector()
172 const auto nEntries = reader->GetNEntries();
173 std::cout <<
"Streamed reading, found " << nEntries <<
" entries" << std::endl;
175 StreamingVectorView<std::uint32_t> streamingVector(reader->GetCollectionView(kFieldName));
179 streamingVector.LoadEntry(i);
182 const auto vectorSize = streamingVector.size();
186 for (
auto val : streamingVector)
189 std::cout <<
"Size and sum of vector: " << vectorSize <<
" " <<
sum << std::endl;
191 std::cout <<
"RNTuple streaming read" << std::endl;
194void ntpl016_streaming_vector()
198 ReadRNTupleStreamingVector();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Bool_t operator!=(const TDatime &d1, const TDatime &d2)
Bool_t operator==(const TDatime &d1, const TDatime &d2)
TTime operator*(const TTime &t1, const TTime &t2)
ROOT::RNTupleLocalRange GetCollectionRange(ROOT::NTupleSize_t globalIndex)
static std::unique_ptr< RNTupleModel > Create()
Common user-tunable settings for reading RNTuples.
void SetClusterCache(EClusterCache val)
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter backed by storage, overwriting it if one with the same URI exists.
constexpr NTupleSize_t kInvalidNTupleIndex
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
constexpr DescriptorId_t kInvalidDescriptorId
static uint64_t sum(uint64_t i)