File indexing completed on 2026-06-20 07:36:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/Parquet/ArrowInputConverter.hpp"
0010
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "ActsExamples/Framework/DataHandle.hpp"
0013 #include "ActsPlugins/Arrow/ArrowUtil.hpp"
0014
0015 #include <sstream>
0016 #include <stdexcept>
0017
0018 #include <arrow/api.h>
0019
0020 namespace ActsExamples {
0021
0022 class ArrowInputConverter::Impl {
0023 public:
0024 Impl(ArrowInputConverter& parent, const std::string& inputTable)
0025 : m_inputTable(&parent, "InputTable") {
0026 m_inputTable.initialize(inputTable);
0027 }
0028
0029 ReadDataHandle<ActsPlugins::ArrowUtil::ArrowTable> m_inputTable;
0030 };
0031
0032 ArrowInputConverter::ArrowInputConverter(
0033 const std::string& name, const std::string& inputTable,
0034 std::unique_ptr<const Acts::Logger> logger)
0035 : IAlgorithm(name, std::move(logger)),
0036 m_impl(std::make_unique<Impl>(*this, inputTable)) {}
0037
0038 ArrowInputConverter::~ArrowInputConverter() = default;
0039
0040 ProcessCode ArrowInputConverter::execute(const AlgorithmContext& ctx) const {
0041 const auto& handle = m_impl->m_inputTable(ctx);
0042 if (!handle) {
0043 ACTS_ERROR("ArrowInputConverter '" << name() << "' received null table");
0044 return ProcessCode::ABORT;
0045 }
0046 const auto& table = handle.table();
0047
0048
0049
0050
0051
0052 if (auto expected = expectedSchema(); expected != nullptr) {
0053 const auto& actual = *table->schema();
0054 std::ostringstream missing;
0055 bool ok = true;
0056 for (const auto& field : expected->fields()) {
0057 auto actualField = actual.GetFieldByName(field->name());
0058 if (actualField == nullptr) {
0059 if (!ok) {
0060 missing << ", ";
0061 }
0062 missing << field->name() << " (missing)";
0063 ok = false;
0064 } else if (!actualField->type()->Equals(*field->type())) {
0065 if (!ok) {
0066 missing << ", ";
0067 }
0068 missing << field->name() << " (type " << actualField->type()->ToString()
0069 << " != " << field->type()->ToString() << ")";
0070 ok = false;
0071 }
0072 }
0073 if (!ok) {
0074 ACTS_ERROR("ArrowInputConverter '"
0075 << name() << "' schema mismatch: " << missing.str() << "\n"
0076 << " expected fields: " << expected->ToString() << "\n"
0077 << " actual schema: " << actual.ToString());
0078 return ProcessCode::ABORT;
0079 }
0080 }
0081
0082 return convert(ctx, *table);
0083 }
0084
0085 }