11#ifndef o2_framework_AnalysisHelpers_H_DEFINED
12#define o2_framework_AnalysisHelpers_H_DEFINED
37 o2::aod::description(o2::aod::signature<R>()),
47 o2::aod::description(o2::aod::signature<R>()),
56 o2::aod::description(o2::aod::signature<R>()),
72 std::string{
"input:"} + o2::aod::label<R>(),
89template <is_producable T>
95 template <
typename...
Ts>
98 static_assert(
sizeof...(Ts) ==
framework::pack_size(
typename persistent_table_t::persistent_columns_t{}),
"Argument number mismatch");
100 cursor(0, extract(args)...);
111 mBuilder = std::move(builder);
119 mBuilder->setLabel(
label);
126 mBuilder->reserve(
typename persistent_table_t::column_types{},
size);
137 template <
typename A>
138 requires requires { &A::globalIndex; }
139 static decltype(
auto) extract(
A const& arg)
141 return arg.globalIndex();
144 template <
typename A>
145 static decltype(
auto) extract(
A const& arg)
153 LifetimeHolder<TableBuilder> mBuilder =
nullptr;
158template <soa::is_table T>
163template <soa::is_iterator T>
164consteval auto typeWithRef() ->
typename T::parent_t
169 requires soa::is_table<T> || soa::is_iterator<T>
176 return OutputSpec{
OutputLabel{aod::label<table_t::ref>()}, o2::aod::origin<table_t::ref>(), o2::aod::description(o2::aod::signature<table_t::ref>()), table_t::ref.version};
181 return OutputRef{aod::label<table_t::ref>(), table_t::ref.version};
189template <is_producable T>
194concept is_produces =
requires(T t) {
typename T::cursor_t;
typename T::persistent_table_t; &T::cursor; };
211template <soa::is_metadata M, soa::TableRef Ref>
216 template <soa::TableRef R>
219 return soa::tableRef2InputSpec<R>();
224 return []<
size_t... Is>(std::index_sequence<Is...>) -> std::vector<InputSpec> {
225 return {base_spec<sources[Is]>()...};
226 }(std::make_index_sequence<
sources.size()>{});
231 return soa::tableRef2OutputSpec<Ref>();
236 return soa::tableRef2Output<Ref>();
239 constexpr auto ref()
const
241 return soa::tableRef2OutputRef<Ref>();
250template <is_spawnable T>
257template <is_spawnable T>
258struct Spawns : decltype(transformBase<T>()) {
283 std::shared_ptr<typename T::table_t>
table =
nullptr;
289 typename T::metadata;
290 requires std::same_as<
decltype(t.pack()),
typename T::expression_pack_t>;
304template <
typename T,
typename Key>
305inline std::shared_ptr<arrow::ChunkedArray> getIndexToKey(arrow::Table* table)
308 return table->column(framework::has_type_at_v<IC>(
typename T::persistent_columns_t{}));
311template <soa::is_column C>
315 static consteval auto listSize()
317 if constexpr (std::same_as<typename C::type, std::vector<int>>) {
319 }
else if constexpr (std::same_as<int[2], typename C::type>) {
326 template <
typename T,
typename Key>
327 static std::shared_ptr<SelfIndexColumnBuilder> makeColumnBuilder(arrow::Table* table, arrow::MemoryPool* pool)
329 if constexpr (!std::same_as<T, Key>) {
330 return std::make_shared<IndexColumnBuilder>(getIndexToKey<T, Key>(table), C::columnLabel(), listSize(), pool);
332 return std::make_shared<SelfIndexColumnBuilder>(C::columnLabel(), pool);
337template <
typename Key,
typename C>
339 using type =
typename std::conditional<soa::is_binding_compatible_v<Key, typename C::binding_t>(), SelfIndexColumnBuilder, IndexColumnBuilder>
::type;
342template <
typename Key,
typename C>
343using reduced_t = Reduction<Key, C>::type;
346template <
typename Kind>
348 template <
typename Key,
size_t N, std::array<soa::TableRef, N> refs,
typename C1,
typename... Cs>
351 auto pool = arrow::default_memory_pool();
353 std::unique_ptr<ChunkedArrayIterator> keyIndex =
nullptr;
354 if constexpr (!Key::template hasOriginal<refs[0]>()) {
355 keyIndex = std::make_unique<ChunkedArrayIterator>(tables[0]->column(
o2::aod::MetadataTrait<
o2::aod::Hash<refs[0].desc_hash>>::metadata::template getIndexPosToKey<Key>()));
358 auto sq = std::make_index_sequence<
sizeof...(Cs)>();
360 auto columnBuilders = [&tables, &pool ]<
size_t... Is>(std::index_sequence<Is...>) -> std::array<std::shared_ptr<framework::SelfIndexColumnBuilder>,
sizeof...(Cs)>
362 return {[](arrow::Table* table, arrow::MemoryPool* pool) {
364 if constexpr (!Key::template hasOriginal<refs[Is + 1]>()) {
366 return std::make_shared<IndexColumnBuilder>(table->column(
pos), T::columnLabel(), ColumnTrait<T>::listSize(), pool);
368 return std::make_shared<SelfIndexColumnBuilder>(T::columnLabel(), pool);
370 }(tables[Is + 1].get(), pool)...};
374 std::array<bool,
sizeof...(Cs)> finds;
378 if constexpr (Key::template hasOriginal<refs[0]>()) {
381 idx = keyIndex->valueAt(
counter);
383 finds = [&idx, &columnBuilders]<
size_t... Is>(std::index_sequence<Is...>) {
385 [&idx, &columnBuilders]() {
387 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->
template find<T>(idx);
390 if constexpr (std::same_as<Kind, Sparse>) {
391 [&idx, &columnBuilders]<
size_t... Is>(std::index_sequence<Is...>) {
392 ([&idx, &columnBuilders]() {
394 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->
template fill<T>(idx); }(), ...);
397 }
else if constexpr (std::same_as<Kind, Exclusive>) {
398 if (std::none_of(finds.begin(), finds.end(), [](
bool const x) {
return x ==
false; })) {
399 [&idx, &columnBuilders]<
size_t... Is>(std::index_sequence<Is...>) {
400 ([&idx, &columnBuilders]() {
402 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->
template fill<T>(idx);
411 return [&
label, &columnBuilders, &self]<
size_t... Is>(std::index_sequence<Is...>) {
413 {self.template
result<C1>(), [&columnBuilders]() {
415 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->
template result<T>();
417 {self.field(), [&columnBuilders]() {
419 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->field();
427template <soa::is_index_table T>
434template <soa::is_index_table T>
435struct Builds : decltype(transformBase<T>()) {
439 using Key = metadata::Key;
440 using H =
typename T::first_t;
441 using Ts =
typename T::rest_t;
455 return table->asArrowTable();
464 template <
typename Key,
typename... Cs>
467 this->table = std::make_shared<T>(IP::template indexBuilder<
Key, metadata::sources.
size(), metadata::sources>(o2::aod::label<T::ref>(), std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables),
framework::pack<Cs...>{}));
468 return (this->table !=
nullptr);
474 typename T::metadata;
476 requires std::same_as<
decltype(t.pack()),
typename T::index_pack_t>;
510 object = std::make_shared<T>(t);
511 object->SetName(
label.c_str());
516 object = std::make_shared<T>(t);
517 object->SetName(
label.c_str());
523 object->SetName(
label.c_str());
529 object->SetName(
label.c_str());
542 std::memset(desc.str,
'_', 16);
544 s << std::hex << lhash;
546 s << std::hex << reinterpret_cast<uint64_t>(
this);
547 std::memcpy(desc.str, s.str().c_str(), 12);
558 return *
object.get();
579 requires std::same_as<
decltype(t.operator->()),
typename T::obj_t*>;
580 requires std::same_as<
decltype(t.object), std::shared_ptr<typename T::obj_t>>;
591 decltype(
auto) operator->()
const
603 requires std::same_as<
decltype(t.service),
typename T::service_t*>;
609 return std::make_unique<
o2::soa::Filtered<std::decay_t<
decltype(table)>>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
614 return std::make_unique<
o2::soa::Filtered<std::decay_t<
decltype(table)>>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
632 void intializeCaches(std::set<uint32_t>
const& hashes, std::shared_ptr<arrow::Schema>
const& schema)
646 template <
typename...
Ts>
650 mFiltered->bindExternalIndices(tables...);
654 template <
typename E>
677 template <
typename T1>
693 template <
typename T1,
typename Policy,
bool OPT>
700 std::unique_ptr<o2::soa::Filtered<T>>
mFiltered =
nullptr;
701 gandiva::NodePtr
tree =
nullptr;
734 &T::updatePlaceholders;
735 requires std::same_as<
decltype(t.filter), expressions::Filter>;
756 return output_t{{table.asArrowTable()}, table.offset()};
constexpr uint32_t runtime_hash(char const *str)
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Helper to check if a type T is an iterator.
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
GLuint GLsizei const GLchar * label
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
std::shared_ptr< gandiva::Filter > FilterPtr
std::variant< OriginValueMatcher, DescriptionValueMatcher, SubSpecificationTypeValueMatcher, std::unique_ptr< DataDescriptorMatcher >, ConstantValueMatcher, StartTimeValueMatcher > Node
gandiva::Selection createSelection(std::shared_ptr< arrow::Table > const &table, Filter const &expression)
Function for creating gandiva selection from our internal filter tree.
void updatePlaceholders(Filter &filter, InitContext &context)
Update placeholder nodes from context.
Defining PrimaryVertex explicitly as messageable.
auto spawner(std::vector< std::shared_ptr< arrow::Table > > &&tables, const char *name)
Expression-based column generator to materialize columns.
typename pack_element< I, T >::type pack_element_t
constexpr std::size_t pack_size(pack< Ts... > const &)
template function to determine number of types in a pack
constexpr auto transformBase()
This helper struct allows you to declare index tables to be created in a task.
memfun_type< decltype(&F::operator())>::type FFL(F const &func)
auto getTableFromFilter(soa::is_filtered_table auto const &table, soa::SelectionVector &&selection)
consteval auto typeWithRef() -> T
Helper to define output for a Table.
OutputObjHandlingPolicy
Policy enum to determine OutputObj handling when writing.
void initializePartitionCaches(std::set< uint32_t > const &hashes, std::shared_ptr< arrow::Schema > const &schema, expressions::Filter const &filter, gandiva::NodePtr &tree, gandiva::FilterPtr &gfilter)
std::shared_ptr< arrow::Table > makeArrowTable(const char *label, std::vector< std::shared_ptr< arrow::ChunkedArray > > &&columns, std::vector< std::shared_ptr< arrow::Field > > &&fields)
SelectionVector selectionToVector(gandiva::Selection const &sel)
constexpr auto tableRef2InputSpec()
constexpr auto tableRef2Output()
std::vector< int64_t > SelectionVector
auto Attach(T const &table)
constexpr auto tableRef2ConfigParamSpec()
auto Extend(T const &table)
On-the-fly adding of expression columns.
constexpr auto tableRef2OutputSpec()
constexpr auto tableRef2OutputRef()
Defining DataPointCompositeObject explicitly as copiable.
std::shared_ptr< T > table
T const & operator*() const
auto build(framework::pack< Cs... >, std::vector< std::shared_ptr< arrow::Table > > &&tables)
metadata::index_pack_t index_pack_t
decltype(transformBase< T >())::metadata metadata
static auto indexBuilder(const char *label, std::vector< std::shared_ptr< arrow::Table > > &&tables, framework::pack< C1, Cs... >)
static OutputSpec const spec()
aod::MetadataTrait< o2::aod::Hash< table_t::ref.desc_hash > >::metadata metadata
decltype(typeWithRef< T >()) table_t
OutputObj(T &&t, OutputObjHandlingPolicy policy_=OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType sourceType_=OutputObjSourceType::OutputObjSource)
void setObject(std::shared_ptr< T > t)
OutputObjSourceType sourceType
OutputRef ref(uint16_t index, uint16_t max)
std::shared_ptr< T > object
void setObject(T const &t)
OutputObj(std::string const &label_, OutputObjHandlingPolicy policy_=OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType sourceType_=OutputObjSourceType::OutputObjSource)
OutputObjHandlingPolicy policy
void setHash(uint32_t hash)
Partition(expressions::Node &&filter_, T const &table)
typename o2::soa::Filtered< T >::const_iterator filtered_const_iterator
void bindTable(T const &table)
filtered_const_iterator begin() const
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
void intializeCaches(std::set< uint32_t > const &hashes, std::shared_ptr< arrow::Schema > const &schema)
Partition(expressions::Node &&filter_)
typename o2::soa::Filtered< T >::iterator filtered_iterator
o2::soa::Filtered< T > * operator->()
typename o2::soa::Filtered< T >::iterator iterator
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
std::shared_ptr< arrow::Table > asArrowTable() const
o2::soa::RowViewSentinel end() const
void updatePlaceholders(InitContext &context)
std::unique_ptr< o2::soa::Filtered< T > > mFiltered
void bindInternalIndicesTo(E *ptr)
expressions::Filter filter
o2::soa::RowViewSentinel end()
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
typename o2::soa::Filtered< T >::const_iterator const_iterator
gandiva::FilterPtr gfilter
void bindExternalIndices(Ts *... tables)
filtered_iterator begin()
T::table_t * operator->()
std::shared_ptr< extension_t > extension
T::table_t const & operator*() const
typename metadata::base_table_t base_table_t
typename metadata::expression_pack_t expression_pack_t
decltype(transformBase< T >())::metadata metadata
std::shared_ptr< typename T::table_t > table
typename metadata::extension_table_t extension_t
int64_t lastIndex()
Last index inserted in the table.
decltype(FFL(std::declval< cursor_t >())) cursor
bool resetCursor(LifetimeHolder< TableBuilder > builder)
void operator()(Ts... args)
void setLabel(const char *label)
void reserve(int64_t size)
decltype([]() { if constexpr(soa::is_iterator< T >) { return typename T::parent_t{nullptr} persistent_table_t
decltype(std::declval< TableBuilder >().cursor< persistent_table_t >()) cursor_t
An expression tree node corresponding to a column binding.
A struct, containing the root of the expression tree.
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))