File indexing completed on 2026-09-15 09:18:32
0001 #ifndef PODIO_ARROWWRITER_H
0002 #define PODIO_ARROWWRITER_H
0003
0004 #include "podio/utilities/DatamodelRegistryIOHelpers.h"
0005
0006 #include <parquet/arrow/writer.h>
0007
0008 #include <cstddef>
0009 #include <cstdint>
0010 #include <filesystem>
0011 #include <map>
0012 #include <memory>
0013 #include <string>
0014 #include <vector>
0015
0016
0017 namespace arrow {
0018 class Schema;
0019 class Table;
0020 }
0021
0022 namespace podio {
0023
0024 class Frame;
0025
0026
0027
0028
0029
0030 class ArrowWriter {
0031 public:
0032
0033 struct Options {
0034 size_t maxBufferedRows = 1000;
0035 std::string compression = "";
0036 };
0037
0038
0039
0040
0041
0042
0043
0044
0045 ArrowWriter(const std::string& directory, const Options& options);
0046 explicit ArrowWriter(const std::string& directory);
0047
0048
0049 ~ArrowWriter();
0050
0051 ArrowWriter(const ArrowWriter&) = delete;
0052 ArrowWriter& operator=(const ArrowWriter&) = delete;
0053 ArrowWriter(ArrowWriter&&) = delete;
0054 ArrowWriter& operator=(ArrowWriter&&) = delete;
0055
0056
0057
0058
0059
0060
0061 void writeFrame(const podio::Frame& frame, std::string_view category);
0062
0063
0064
0065
0066
0067
0068 void writeFrame(const podio::Frame& frame, std::string_view category, const std::vector<std::string>& collsToWrite);
0069
0070
0071 void finish();
0072
0073 private:
0074
0075 struct CategoryInfo {
0076 std::string filePath{};
0077 std::shared_ptr<arrow::Schema> schema{nullptr};
0078 std::vector<std::string> collsToWrite{};
0079 std::vector<std::string> collTypes{};
0080 std::vector<bool> collIsSubset{};
0081 std::vector<uint32_t> collSchemaVersions{};
0082 std::vector<uint32_t> collIDs{};
0083 std::vector<std::shared_ptr<arrow::Table>> buffer{};
0084 std::unique_ptr<parquet::arrow::FileWriter> writer{nullptr};
0085 size_t entries = 0;
0086
0087 CategoryInfo() = default;
0088 ~CategoryInfo() = default;
0089 CategoryInfo(CategoryInfo&&) = default;
0090 CategoryInfo& operator=(CategoryInfo&&) = default;
0091 };
0092
0093 void flushCategory(CategoryInfo& catInfo);
0094 void writeMetadata();
0095 void validateSchema(const CategoryInfo& catInfo, const podio::Frame& frame,
0096 const std::vector<std::string>& collsToWrite);
0097
0098 std::string m_directory{};
0099 Options m_options{};
0100 std::map<std::string, CategoryInfo> m_categories{};
0101 DatamodelDefinitionCollector m_datamodelCollector{};
0102 bool m_finished = false;
0103 };
0104
0105 }
0106
0107 #endif