15#include <arrow/util/key_value_metadata.h>
16#include <arrow/util/config.h>
31 throw o2::framework::runtime_error_f(
"Trying to dereference index with a wrong type in %s_as<T> for base target \"%s\". Note that if you have several compatible index targets in your process() signature, the last one will be the one actually bound.", getter,
target);
51 rows.resize(sel->GetNumSlots());
52 for (
auto i = 0;
i < sel->GetNumSlots(); ++
i) {
53 rows[
i] = sel->GetIndex(
i);
62 auto start_iterator = std::lower_bound(mSelectedRows.begin(), mSelectedRows.end(),
start);
63 auto stop_iterator = std::lower_bound(start_iterator, mSelectedRows.end(),
end);
65 std::ranges::transform(slicedSelection.begin(), slicedSelection.end(), slicedSelection.begin(),
67 return idx - static_cast<int64_t>(start);
69 return slicedSelection;
75 requires(std::same_as<T, std::string>)
76auto makeString(T
const&
str)
81 requires(std::same_as<T, const char*>)
82auto makeString(T
const&
str)
88void canNotJoin(std::vector<std::shared_ptr<arrow::Table>>
const& tables, std::span<T>
labels)
90 for (
auto i = 0U;
i < tables.size() - 1; ++
i) {
91 if (tables[
i]->num_rows() != tables[
i + 1]->num_rows()) {
93 makeString(
labels[
i]), makeString(
labels[
i + 1]), tables[
i]->num_rows(), tables[
i + 1]->num_rows());
99void IncompatibleRanges(std::vector<ArrowTableRef>
const& tables, std::span<T>
labels)
101 auto loc = std::ranges::adjacent_find(tables, [](
auto const& l,
auto const&
r) {
return l.range !=
r.range; });
102 if (loc != std::ranges::cend(tables)) {
103 auto pos = std::distance(tables.begin(), loc);
106 throw o2::framework::runtime_error_f(
"Incompatible ranges at %d: (%zu, %z) vs. (%zu, %z)",
pos, loc->range.offset, loc->range.size, next->range.offset, next->range.size);
113std::shared_ptr<arrow::Table> joinTablesImpl(std::ranges::input_range
auto tables)
115 std::vector<std::shared_ptr<arrow::Field>>
fields;
116 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
117 bool notEmpty = (tables.front()->num_rows() != 0);
118 std::ranges::for_each(tables, [&
fields, &columns, notEmpty](
auto const& t) {
119 std::ranges::copy(t->fields(), std::back_inserter(
fields));
121 std::ranges::copy(t->columns(), std::back_inserter(columns));
125 return arrow::Table::Make(
schema, columns);
129ArrowTableRef joinTablesImpl(std::ranges::input_range
auto tables, std::span<T>
labels)
131 if (tables.size() == 1) {
132 return tables.front();
134 IncompatibleRanges(tables,
labels);
135 ArrowRange commonRange{tables.front().range};
136 return {joinTablesImpl(tables), commonRange};
142 std::vector<ArrowTableRef> refs;
143 std::ranges::transform(tables, std::back_inserter(refs), [](
auto const& table) {
return ArrowTableRef{table}; });
144 return joinTablesImpl(refs, std::span<const char* const>());
149 return joinTablesImpl(tables, std::span<const char* const>());
154 return joinTablesImpl(tables,
labels);
159 return joinTablesImpl(tables,
labels);
164 canNotJoin(tables,
labels);
170 canNotJoin(tables,
labels);
176 if (tables.size() == 1) {
177 return tables.front();
179 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
180 std::vector<std::shared_ptr<arrow::Field>> resultFields = tables.front()->schema()->fields();
181 auto compareFields = [](std::shared_ptr<arrow::Field>
const& f1, std::shared_ptr<arrow::Field>
const& f2) {
183 return (!f1->Equals(f2)) && (f1->name() < f2->name());
186 for (
auto i = 1;
i < tables.size(); ++
i) {
187 auto const&
fields = tables[
i]->fields();
188 std::vector<std::shared_ptr<arrow::Field>> intersection;
189 std::ranges::set_intersection(resultFields,
fields, std::back_inserter(intersection), compareFields);
190 resultFields.swap(intersection);
193 for (
auto const& field : resultFields) {
194 arrow::ArrayVector chunks;
195 for (
auto const& table : tables) {
196 auto ci = table->schema()->GetFieldIndex(field->name());
200 auto column = table->column(ci);
201 auto otherChunks = column->chunks();
202 chunks.insert(chunks.end(), otherChunks.begin(), otherChunks.end());
204 columns.push_back(std::make_shared<arrow::ChunkedArray>(chunks));
207 return {arrow::Table::Make(std::make_shared<arrow::Schema>(resultFields), columns)};
215 auto field = std::ranges::find_if(table->schema()->fields(), [
label](std::shared_ptr<arrow::Field>
const&
f) {
216 std::string_view name = f->name();
217 return label == name ||
218 std::ranges::equal(label, name, [](char c1, char c2) {
219 return asciiToLower(c1) == asciiToLower(c2);
222 if (field == table->schema()->fields().end()) {
225 return table->column(std::distance(table->schema()->fields().begin(), field)).get();
245 Int_t previousErrorLevel = gErrorIgnoreLevel;
246 gErrorIgnoreLevel = kFatal;
248 TMemFile file(
"name", (
char*)payload,
size,
"READ");
249 gErrorIgnoreLevel = previousErrorLevel;
250 if (file.IsZombie()) {
257 auto object = file.GetObjectChecked(what, cl);
261 std::string objectName(cl->GetName());
262 objectName.erase(std::find_if(objectName.rbegin(), objectName.rend(), [](
unsigned char ch) {
263 return !std::isspace(ch);
266 objectName.erase(objectName.begin(), std::find_if(objectName.begin(), objectName.end(), [](
unsigned char ch) {
267 return !std::isspace(ch);
270 object = file.GetObjectChecked(objectName.c_str(), cl);
271 LOG(warn) <<
"Did not find object under expected name " << what;
275 LOG(warn) <<
"Found object under deprecated name " << cl->GetName();
280 if (cl->InheritsFrom(
"TObject")) {
283 auto tree =
dynamic_cast<TTree*
>((
TObject*)
object);
285 tree->LoadBaskets(0x1L << 32);
286 tree->SetDirectory(
nullptr);
289 auto h =
dynamic_cast<TH1*
>((
TObject*)
object);
291 h->SetDirectory(
nullptr);
303 m.origin = newOrigin;
316 if (
pos != std::string::npos) {
324 std::transform(
str.begin(),
str.end(),
str.begin(), [](
unsigned char c) { return std::toupper(c); });
351 return input.
slice({
static_cast<uint64_t
>(offset_),
count});
std::vector< std::string > labels
std::shared_ptr< arrow::Schema > schema
std::vector< std::shared_ptr< arrow::Field > > fields
Class for time synchronization of RawReader instances.
GLsizei const GLfloat * value
GLuint GLsizei const GLchar * label
std::shared_ptr< gandiva::SelectionVector > Selection
Defining ITS Vertex explicitly as messageable.
RuntimeErrorRef runtime_error(const char *)
void throw_error(RuntimeErrorRef)
std::string strToUpper(std::string &&str)
RuntimeErrorRef runtime_error_f(const char *,...)
std::string cutString(std::string &&str)
void * extractCCDBPayload(char *payload, size_t size, TClass const *cl, const char *what)
SelectionVector selectionToVector(gandiva::Selection const &sel)
void notBoundTable(const char *tableName)
SelectionVector sliceSelection(std::span< int64_t const > const &mSelectedRows, int64_t nrows, uint64_t offset)
std::vector< int64_t > SelectionVector
void missingFilterDeclaration(int hash, int ai)
void accessingInvalidIndexFor(const char *getter)
void dereferenceWithWrongType(const char *getter, const char *target)
void getterNotFound(const char *targetColumnLabel)
void missingOptionalPreslice(const char *label, const char *key)
std::function< framework::ConcreteDataMatcher(framework::ConcreteDataMatcher &&)> originReplacement(header::DataOrigin newOrigin)
arrow::ChunkedArray * getIndexFromLabel(arrow::Table *table, std::string_view label)
void notFoundColumn(const char *label, const char *key)
const std::string binding
Entry const & getBindingKey() const
SliceInfoUnsortedPtr sliceInfo
std::span< const int64_t > getSliceFor(int value) const
void updateSliceInfo(SliceInfoUnsortedPtr &&si)
o2::soa::ArrowTableRef getSliceFor(int value, o2::soa::ArrowTableRef const &input) const
void updateSliceInfo(SliceInfoPtr &&si)
std::pair< int64_t, int64_t > getSliceFor(int value) const
std::span< int64_t const > getSliceFor(int value) const
static o2::soa::ArrowTableRef joinTables(std::vector< std::shared_ptr< arrow::Table > > &&tables)
static o2::soa::ArrowTableRef concatTables(std::vector< o2::soa::ArrowTableRef > &&tables)
ArrowTableRef slice(ArrowRange newRange) const
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))
std::vector< ReadoutWindowData > rows