Project
Loading...
Searching...
No Matches
TableConsumer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#if defined(__GNUC__)
15#pragma GCC diagnostic push
16#pragma GCC diagnostic ignored "-Wshadow"
17#endif
18#include <arrow/builder.h>
19#include <arrow/memory_pool.h>
20#include <arrow/record_batch.h>
21#include <arrow/table.h>
22#include <arrow/type_traits.h>
23#include <arrow/status.h>
24#include <arrow/io/memory.h>
25#include <arrow/ipc/reader.h>
26#if defined(__GNUC__)
27#pragma GCC diagnostic pop
28#endif
29
30using namespace arrow;
31
32namespace o2::framework
33{
34
35TableConsumer::TableConsumer(const uint8_t* data, int64_t size)
36 : mBuffer{std::make_shared<Buffer>(data, size)}
37{
38}
39
40std::shared_ptr<arrow::Table>
42{
43 std::shared_ptr<Table> inTable;
44 // In case the buffer is empty, we cannot determine the schema
45 // and therefore return an empty table;
46 using BackendColumnType = typename decltype(inTable->column(0))::element_type;
47 if (mBuffer->size() == 0) {
48 std::vector<std::shared_ptr<arrow::Field>> dummyFields{};
49 std::vector<std::shared_ptr<BackendColumnType>> dummyColumns{};
50 auto dummySchema = std::make_shared<arrow::Schema>(dummyFields);
51 return arrow::Table::Make(dummySchema, dummyColumns);
52 }
53
55 std::shared_ptr<io::InputStream> bufferReader = std::make_shared<io::BufferReader>(mBuffer);
56
57 auto readerResult = ipc::RecordBatchStreamReader::Open(bufferReader);
58 std::vector<std::shared_ptr<RecordBatch>> batches;
59 auto batchReader = readerResult.ValueOrDie();
60 while (true) {
61 std::shared_ptr<RecordBatch> batch;
62 auto next = batchReader->ReadNext(&batch);
63 if (batch.get() == nullptr) {
64 break;
65 }
66 batches.push_back(batch);
67 }
68
69 auto tableResult = Table::FromRecordBatches(batches);
70
71 return tableResult.ValueOrDie();
72}
73
74} // namespace o2::framework
TableConsumer(const uint8_t *data, int64_t size)
std::shared_ptr< arrow::Table > asArrowTable()
Return the table in the message as a arrow::Table instance.
GLsizeiptr size
Definition glcorearb.h:659
GLboolean * data
Definition glcorearb.h:298
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
Defining DataPointCompositeObject explicitly as copiable.