Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-20 07:36:36

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // Subset check, not equality: dataset reads may surface a unified schema
0049   // that includes fields from newer fragments which older converters don't
0050   // care about. We require every field the converter declares to be present
0051   // and to have a matching type, but allow extra fields.
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 }  // namespace ActsExamples