Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Framework/Core/include/Framework/AnalysisHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,12 @@ struct WritingCursor {

/// reserve @a size rows when filling, so that we do not
/// spend time reallocating the buffers.
/// Switches the internal cursor to UnsafeAppend (no capacity check),
/// which is safe because we just reserved enough space.
void reserve(int64_t size)
{
mBuilder->reserve(typename persistent_table_t::column_types{}, size);
cursor = std::move(FFL(mBuilder->template unsafeCursor<persistent_table_t>()));
}

void release()
Expand Down
21 changes: 21 additions & 0 deletions Framework/Core/include/Framework/TableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,18 @@ class TableBuilder
};
}

/// Same as persist, but uses UnsafeAppend (no capacity check).
/// Only safe after reserve() has been called with the correct size.
template <typename ARG0, typename... ARGS>
requires(sizeof...(ARGS) > 0) || ShouldNotDeconstruct<ARG0>
auto unsafePersist()
{
using FillTuple = std::tuple<typename BuilderMaker<ARG0>::FillType, typename BuilderMaker<ARGS>::FillType...>;
return [holders = mHolders](unsigned int /*slot*/, typename BuilderMaker<ARG0>::FillType arg, typename BuilderMaker<ARGS>::FillType... args) -> void {
TableBuilderHelpers::unsafeAppend(*(HoldersTupleIndexed<ARG0, ARGS...>*)holders, std::forward_as_tuple(arg, args...));
};
}

// Same as above, but starting from a o2::soa::Table, which has all the
// information already available.
template <typename T>
Expand All @@ -725,6 +737,15 @@ class TableBuilder
}(typename T::table_t::persistent_columns_t{});
}

/// Same as cursor(), but uses UnsafeAppend. Only safe after reserve().
template <typename T>
auto unsafeCursor()
{
return [this]<typename... Cs>(pack<Cs...>) {
return this->template unsafePersist<typename Cs::type...>();
}(typename T::table_t::persistent_columns_t{});
}

template <typename... Cs>
auto cursor(framework::pack<Cs...>)
{
Expand Down