Skip to content

Commit

Permalink
DPL: improve getIndexFromLabel
Browse files Browse the repository at this point in the history
Avoids extra string creation.
  • Loading branch information
ktf committed Jan 22, 2025
1 parent 7b2c021 commit b8be78a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Framework/Core/include/Framework/ASoA.h
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ auto select(T const& t, framework::expressions::Filter const& f)
return Filtered<T>({t.asArrowTable()}, selectionToVector(framework::expressions::createSelection(t.asArrowTable(), f)));
}

arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label);
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label);

template <typename D, typename O, typename IP, typename... C>
consteval auto base_iter(framework::pack<C...>&&) -> TableIterator<D, O, IP, C...>
Expand Down
13 changes: 11 additions & 2 deletions Framework/Core/src/ASoA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
return result;
}

arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label)
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label)
{
auto field = std::find_if(table->schema()->fields().begin(), table->schema()->fields().end(), [&](std::shared_ptr<arrow::Field> const& f) {
return o2::framework::strToUpper(label) == o2::framework::strToUpper(std::string{f->name()});
auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
return std::ranges::equal(
str1, str2,
[](char c1, char c2) {
return std::tolower(static_cast<unsigned char>(c1)) ==
std::tolower(static_cast<unsigned char>(c2));
});
};

return caseInsensitiveCompare(label, f->name());
});
if (field == table->schema()->fields().end()) {
o2::framework::throw_error(o2::framework::runtime_error_f("Unable to find column with label %s", label));
Expand Down

0 comments on commit b8be78a

Please sign in to comment.