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::transform(slicedSelection.begin(), slicedSelection.end(), slicedSelection.begin(),
66 [&
start](int64_t idx) {
67 return idx - static_cast<int64_t>(start);
69 return slicedSelection;
72std::shared_ptr<arrow::Table>
ArrowHelpers::joinTables(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const char* const> labels)
74 if (tables.size() == 1) {
77 for (
auto i = 0U;
i < tables.size() - 1; ++
i) {
78 if (tables[
i]->num_rows() != tables[
i + 1]->num_rows()) {
80 labels[
i], labels[
i + 1], tables[
i]->num_rows(), tables[
i + 1]->num_rows());
83 std::vector<std::shared_ptr<arrow::Field>> fields;
84 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
86 for (
auto& t : tables) {
87 auto tf = t->fields();
88 std::copy(
tf.begin(),
tf.end(), std::back_inserter(fields));
91 auto schema = std::make_shared<arrow::Schema>(fields);
93 if (tables[0]->num_rows() != 0) {
94 for (
auto& t : tables) {
95 auto tc = t->columns();
96 std::copy(tc.begin(), tc.end(), std::back_inserter(columns));
99 return arrow::Table::Make(schema, columns);
104 if (tables.size() == 1) {
107 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
108 assert(tables.size() > 1);
109 std::vector<std::shared_ptr<arrow::Field>> resultFields = tables[0]->schema()->fields();
110 auto compareFields = [](std::shared_ptr<arrow::Field>
const& f1, std::shared_ptr<arrow::Field>
const& f2) {
112 return (!f1->Equals(f2)) && (f1->name() < f2->name());
114 for (
size_t i = 1;
i < tables.size(); ++
i) {
115 auto& fields = tables[
i]->schema()->fields();
116 std::vector<std::shared_ptr<arrow::Field>> intersection;
118 std::set_intersection(resultFields.begin(), resultFields.end(),
119 fields.begin(), fields.end(),
120 std::back_inserter(intersection), compareFields);
121 resultFields.swap(intersection);
124 for (
auto& field : resultFields) {
125 arrow::ArrayVector chunks;
126 for (
auto& table : tables) {
127 auto ci = table->schema()->GetFieldIndex(field->name());
129 throw std::runtime_error(
"Unable to find field " + field->name());
131 auto column = table->column(ci);
132 auto otherChunks = column->chunks();
133 chunks.insert(chunks.end(), otherChunks.begin(), otherChunks.end());
135 columns.push_back(std::make_shared<arrow::ChunkedArray>(chunks));
138 auto result = arrow::Table::Make(std::make_shared<arrow::Schema>(resultFields), columns);
144 auto field = std::find_if(table->schema()->fields().begin(), table->schema()->fields().end(), [&](std::shared_ptr<arrow::Field>
const&
f) {
145 auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
146 return std::ranges::equal(
148 [](char c1, char c2) {
149 return std::tolower(static_cast<unsigned char>(c1)) ==
150 std::tolower(static_cast<unsigned char>(c2));
154 return caseInsensitiveCompare(
label,
f->name());
156 if (field == table->schema()->fields().end()) {
159 auto index = std::distance(table->schema()->fields().begin(), field);
160 return table->column(
index).get();
180 Int_t previousErrorLevel = gErrorIgnoreLevel;
181 gErrorIgnoreLevel = kFatal;
183 TMemFile
file(
"name", (
char*)payload,
size,
"READ");
184 gErrorIgnoreLevel = previousErrorLevel;
185 if (
file.IsZombie()) {
192 auto object =
file.GetObjectChecked(what, cl);
196 std::string objectName(cl->GetName());
197 objectName.erase(std::find_if(objectName.rbegin(), objectName.rend(), [](
unsigned char ch) {
198 return !std::isspace(ch);
201 objectName.erase(objectName.begin(), std::find_if(objectName.begin(), objectName.end(), [](
unsigned char ch) {
202 return !std::isspace(ch);
205 object =
file.GetObjectChecked(objectName.c_str(), cl);
206 LOG(warn) <<
"Did not find object under expected name " << what;
210 LOG(warn) <<
"Found object under deprecated name " << cl->GetName();
215 if (cl->InheritsFrom(
"TObject")) {
218 auto tree =
dynamic_cast<TTree*
>((
TObject*)
object);
220 tree->LoadBaskets(0x1L << 32);
221 tree->SetDirectory(
nullptr);
224 auto h =
dynamic_cast<TH1*
>((
TObject*)
object);
226 h->SetDirectory(
nullptr);
241 if (
pos != std::string::npos) {
249 std::transform(
str.begin(),
str.end(),
str.begin(), [](
unsigned char c) { return std::toupper(c); });
277 offset =
static_cast<int64_t
>(offset_);
Class for time synchronization of RawReader instances.
GLsizei const GLfloat * value
GLuint GLsizei const GLchar * label
std::shared_ptr< gandiva::SelectionVector > Selection
Defining PrimaryVertex 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)
arrow::ChunkedArray * getIndexFromLabel(arrow::Table *table, std::string_view label)
void notFoundColumn(const char *label, const char *key)
std::unique_ptr< GPUReconstructionTimeframe > tf
const std::string binding
Entry const & getBindingKey() const
SliceInfoUnsortedPtr sliceInfo
std::span< const int64_t > getSliceFor(int value) const
void updateSliceInfo(SliceInfoUnsortedPtr &&si)
void updateSliceInfo(SliceInfoPtr &&si)
std::shared_ptr< arrow::Table > getSliceFor(int value, std::shared_ptr< arrow::Table > const &input, uint64_t &offset) const
std::pair< int64_t, int64_t > getSliceFor(int value) const
std::span< int64_t const > getSliceFor(int value) const
static std::shared_ptr< arrow::Table > joinTables(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< const char *const > labels)
static std::shared_ptr< arrow::Table > concatTables(std::vector< std::shared_ptr< arrow::Table > > &&tables)
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