Skip to content

Commit 665114d

Browse files
committed
Make column lookup case-insensitive
1 parent 8c75154 commit 665114d

File tree

2 files changed

+31
-46
lines changed

2 files changed

+31
-46
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
#include <gsl/span>
3232
#include <limits>
3333

34+
namespace o2::framework
35+
{
36+
using ListVector = std::vector<std::vector<int64_t>>;
37+
38+
std::string cutString(std::string&& str);
39+
std::string strToUpper(std::string&& str);
40+
} // namespace o2::framework
41+
3442
#define DECLARE_SOA_METADATA() \
3543
template <typename T> \
3644
struct MetadataTrait { \
@@ -5655,19 +5663,19 @@ template <typename T>
56555663
constexpr bool is_smallgroups_v = is_smallgroups_t<T>::value;
56565664
} // namespace o2::soa
56575665

5658-
namespace o2::framework
5659-
{
5660-
using ListVector = std::vector<std::vector<int64_t>>;
5661-
5662-
std::string cutString(std::string&& str);
5663-
5664-
void sliceByColumnGeneric(
5665-
char const* key,
5666-
char const* target,
5667-
std::shared_ptr<arrow::Table> const& input,
5668-
int32_t fullSize,
5669-
ListVector* groups,
5670-
ListVector* unassigned = nullptr);
5671-
} // namespace o2::framework
5666+
// namespace o2::framework
5667+
// {
5668+
// using ListVector = std::vector<std::vector<int64_t>>;
5669+
5670+
// std::string cutString(std::string&& str);
5671+
5672+
// void sliceByColumnGeneric(
5673+
// char const* key,
5674+
// char const* target,
5675+
// std::shared_ptr<arrow::Table> const& input,
5676+
// int32_t fullSize,
5677+
// ListVector* groups,
5678+
// ListVector* unassigned = nullptr);
5679+
// } // namespace o2::framework
56725680

56735681
#endif // O2_FRAMEWORK_ASOA_H_

Framework/Core/src/ASoA.cxx

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,14 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
115115

116116
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label)
117117
{
118-
auto index = table->schema()->GetAllFieldIndices(label);
119-
if (index.empty()) {
118+
auto field = std::find_if(table->schema()->fields().begin(), table->schema()->fields().end(), [&](std::shared_ptr<arrow::Field> const& f){
119+
return o2::framework::strToUpper(label) == o2::framework::strToUpper(std::string{f->name()});
120+
});
121+
if (field == table->schema()->fields().end()) {
120122
o2::framework::throw_error(o2::framework::runtime_error_f("Unable to find column with label %s", label));
121123
}
122-
return table->column(index[0]).get();
124+
auto index = std::distance(table->schema()->fields().begin(), field);
125+
return table->column(index).get();
123126
}
124127

125128
void notBoundTable(const char* tableName)
@@ -150,35 +153,9 @@ std::string cutString(std::string&& str)
150153
return str;
151154
}
152155

153-
void sliceByColumnGeneric(
154-
char const* key,
155-
char const* target,
156-
std::shared_ptr<arrow::Table> const& input,
157-
int32_t fullSize,
158-
ListVector* groups,
159-
ListVector* unassigned)
156+
std::string strToUpper(std::string&& str)
160157
{
161-
groups->resize(fullSize);
162-
auto column = input->GetColumnByName(key);
163-
int32_t row = 0;
164-
for (auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
165-
auto chunk = static_cast<arrow::NumericArray<arrow::Int32Type>>(column->chunk(iChunk)->data());
166-
for (auto iElement = 0; iElement < chunk.length(); ++iElement) {
167-
auto v = chunk.Value(iElement);
168-
if (v >= 0) {
169-
if (v >= groups->size()) {
170-
throw runtime_error_f("Table %s has an entry with index (%d) that is larger than the grouping table size (%d)", target, v, fullSize);
171-
}
172-
(*groups)[v].push_back(row);
173-
} else if (unassigned != nullptr) {
174-
auto av = std::abs(v);
175-
if (unassigned->size() < av + 1) {
176-
unassigned->resize(av + 1);
177-
}
178-
(*unassigned)[av].push_back(row);
179-
}
180-
++row;
181-
}
182-
}
158+
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){ return std::toupper(c); });
159+
return str;
183160
}
184161
} // namespace o2::framework

0 commit comments

Comments
 (0)