|
| 1 | +// Copyright 2019-2025 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 | +#ifndef O2_FRAMEWORK_FRAGMENT_TO_BATCH_H_ |
| 12 | +#define O2_FRAMEWORK_FRAGMENT_TO_BATCH_H_ |
| 13 | + |
| 14 | +#include <arrow/buffer.h> |
| 15 | +#include <arrow/io/interfaces.h> |
| 16 | +#include <arrow/record_batch.h> |
| 17 | +#include <arrow/dataset/file_base.h> |
| 18 | +#include <memory> |
| 19 | + |
| 20 | +// ============================================================================= |
| 21 | +namespace o2::framework |
| 22 | +{ |
| 23 | +class FragmentToBatch |
| 24 | +{ |
| 25 | + public: |
| 26 | + // The function to be used to create the required stream. |
| 27 | + using StreamerCreator = std::function<std::shared_ptr<arrow::io::OutputStream>(std::shared_ptr<arrow::dataset::FileFragment>, const std::shared_ptr<arrow::ResizableBuffer>& buffer)>; |
| 28 | + |
| 29 | + FragmentToBatch(StreamerCreator, std::shared_ptr<arrow::dataset::FileFragment>, arrow::MemoryPool* pool = arrow::default_memory_pool()); |
| 30 | + void setLabel(const char* label); |
| 31 | + void fill(std::shared_ptr<arrow::Schema> dataSetSchema, std::shared_ptr<arrow::dataset::FileFormat>); |
| 32 | + std::shared_ptr<arrow::RecordBatch> finalize(); |
| 33 | + |
| 34 | + std::shared_ptr<arrow::io::OutputStream> streamer(std::shared_ptr<arrow::ResizableBuffer> buffer) |
| 35 | + { |
| 36 | + return mCreator(mFragment, buffer); |
| 37 | + } |
| 38 | + |
| 39 | + private: |
| 40 | + std::shared_ptr<arrow::dataset::FileFragment> mFragment; |
| 41 | + arrow::MemoryPool* mArrowMemoryPool = nullptr; |
| 42 | + std::string mTableLabel; |
| 43 | + std::shared_ptr<arrow::RecordBatch> mRecordBatch; |
| 44 | + StreamerCreator mCreator; |
| 45 | +}; |
| 46 | + |
| 47 | +// ----------------------------------------------------------------------------- |
| 48 | +} // namespace o2::framework |
| 49 | + |
| 50 | +// ============================================================================= |
| 51 | +#endif // O2_FRAMEWORK_FRAGMENT_TO_BATCH_H_ |
0 commit comments