File indexing completed on 2026-10-09 08:30:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Mille/MillePedeResultReader.hpp"
0010
0011 #include "Acts/Utilities/Logger.hpp"
0012 #include "Acts/Utilities/Result.hpp"
0013 #include "ActsPlugins/Mille/MillePedeError.hpp"
0014
0015 #include <fstream>
0016 #include <optional>
0017 #include <system_error>
0018
0019 using namespace ActsPlugins;
0020
0021 namespace {
0022
0023 std::optional<ActsPlugins::MillePedeParameterResult> parseMpLine(
0024 const std::string& resLine, const Acts::Logger& logger) {
0025
0026 if (resLine.empty()) {
0027 return std::nullopt;
0028 }
0029 ActsPlugins::MillePedeParameterResult par;
0030 par.sigma = -1;
0031 par.nRecords = -1;
0032 std::stringstream sstr(resLine);
0033
0034 std::string firstWord = "";
0035 sstr >> firstWord;
0036 if (!firstWord.empty() && firstWord.starts_with("#")) {
0037 ACTS_DEBUG(" Skipping a commented line in the MP results file ");
0038 return std::nullopt;
0039 }
0040 if (!firstWord.empty() && firstWord == "Parameter") {
0041 ACTS_DEBUG(" Skipping the header line of the MP results file ");
0042 return std::nullopt;
0043 }
0044 sstr.seekg(0);
0045 sstr >> par.label >> par.val >> par.start;
0046 if (sstr.fail()) {
0047 ACTS_WARNING(" Failed to read a line of the MP results file ");
0048 return std::nullopt;
0049 }
0050
0051
0052 if (!sstr.eof()) {
0053 sstr >> par.delta;
0054 }
0055 if (!sstr.eof()) {
0056 sstr >> par.sigma;
0057 }
0058 if (!sstr.eof()) {
0059 sstr >> par.nRecords;
0060 }
0061 return par;
0062 }
0063 }
0064
0065 Acts::Result<std::vector<MillePedeParameterResult>>
0066 ActsPlugins::readMillePedeResult(const std::filesystem::path& mpFile,
0067 const Acts::Logger& logger) {
0068 std::vector<MillePedeParameterResult> res;
0069 std::ifstream resFile(mpFile);
0070 if (!resFile.is_open()) {
0071 ACTS_ERROR(" Failed to read the MP results file '" << mpFile << "'");
0072 return Acts::Result<std::vector<MillePedeParameterResult>>::failure(
0073 MillePedeError::SolutionNotReadable);
0074 }
0075 while (!resFile.eof()) {
0076 std::string resLine;
0077 std::getline(resFile, resLine);
0078 auto parseOut = parseMpLine(resLine, logger());
0079 if (parseOut.has_value()) {
0080 res.push_back(*parseOut);
0081 }
0082 }
0083 resFile.close();
0084 return res;
0085 }