Skip to content

Commit

Permalink
[ntuple] prevent writable access to RValues in REntry
Browse files Browse the repository at this point in the history
  • Loading branch information
jblomer committed Jan 16, 2024
1 parent 2e97fb5 commit bd36801
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
25 changes: 22 additions & 3 deletions tree/ntuple/v7/inc/ROOT/REntry.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ that are associated to values are managed.
*/
// clang-format on
class REntry {
friend class RCollectionNTupleWriter;
friend class RNTupleModel;
friend class RNTupleReader;
friend class RNTupleWriter;

/// The entry must be linked to a specific model (or one if its clones), identified by a model ID
std::uint64_t fModelId = 0;
Expand All @@ -66,8 +69,24 @@ class REntry {
return ptr;
}

void Read(NTupleSize_t index)
{
for (auto &v : fValues) {
v.Read(index);
}
}

std::size_t Append()
{
std::size_t bytesWritten = 0;
for (auto &v : fValues) {
bytesWritten += v.Append();
}
return bytesWritten;
}

public:
using Iterator_t = decltype(fValues)::iterator;
using ConstIterator_t = decltype(fValues)::const_iterator;

REntry(const REntry &other) = delete;
REntry &operator=(const REntry &other) = delete;
Expand Down Expand Up @@ -101,8 +120,8 @@ public:

std::uint64_t GetModelId() const { return fModelId; }

Iterator_t begin() { return fValues.begin(); }
Iterator_t end() { return fValues.end(); }
ConstIterator_t begin() const { return fValues.cbegin(); }
ConstIterator_t end() const { return fValues.cend(); }
};

} // namespace Experimental
Expand Down
15 changes: 3 additions & 12 deletions tree/ntuple/v7/inc/ROOT/RNTuple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,7 @@ public:
LoadEntry(index, *fModel->GetDefaultEntry());
}
/// Fills a user provided entry after checking that the entry has been instantiated from the ntuple model
void LoadEntry(NTupleSize_t index, REntry &entry) {
for (auto& value : entry) {
value.Read(index);
}
}
void LoadEntry(NTupleSize_t index, REntry &entry) { entry.Read(index); }

/// Returns an iterator over the entry indices of the RNTuple.
///
Expand Down Expand Up @@ -412,10 +408,7 @@ public:
if (R__unlikely(entry.GetModelId() != fModel->GetModelId()))
throw RException(R__FAIL("mismatch between entry and model"));

std::size_t bytesWritten = 0;
for (auto& value : entry) {
bytesWritten += value.Append();
}
const std::size_t bytesWritten = entry.Append();
fUnzippedClusterSize += bytesWritten;
fNEntries++;
if ((fUnzippedClusterSize >= fMaxUnzippedClusterSize) || (fUnzippedClusterSize >= fUnzippedClusterSizeEst))
Expand Down Expand Up @@ -487,9 +480,7 @@ public:

void Fill() { Fill(fDefaultEntry.get()); }
void Fill(REntry *entry) {
for (auto &value : *entry) {
value.Append();
}
entry->Append();
fOffset++;
}

Expand Down

0 comments on commit bd36801

Please # to comment.