Skip to content

Commit 9810263

Browse files
committed
[skip-ci][ntuple] Add doc comment to RNTupleReader::GetNEntries()
1 parent 8551484 commit 9810263

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tree/ntuple/inc/ROOT/RNTupleReader.hxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ public:
171171
}
172172
~RNTupleReader();
173173

174+
/// Returns the number of entries in this RNTuple.
175+
/// \attention This method requires locking a mutex, therefore it can become relatively expensive to call repeatedly
176+
/// (even in the absence of contention). Unless necessary, you should not call this method in the condition of a
177+
/// `for` loop. Instead, either call it once and cache the result, use the faster `GetEntryRange()` or, equivalently,
178+
/// use the RNTupleReader directly as an iterator.
179+
///
180+
/// ~~~ {.cpp}
181+
/// // BAD for performance:
182+
/// for (auto i = 0u; i < reader->GetNEntries(); ++i) { ... }
183+
///
184+
/// // GOOD for performance (all equivalent):
185+
/// for (auto i = 0u, n = reader->GetNEntries(); i < n; ++i) { ... }
186+
/// for (auto i : reader->GetEntryRange()) { ... }
187+
/// for (auto i : *reader) { ... }
188+
/// ~~~
174189
ROOT::NTupleSize_t GetNEntries() const { return fSource->GetNEntries(); }
175190
const ROOT::RNTupleModel &GetModel();
176191
std::unique_ptr<ROOT::REntry> CreateEntry();

0 commit comments

Comments
 (0)