Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-09 08:30:26

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 "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   // skip blank lines
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   // skip comment lines
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   // the following three elements are not guaranteed
0051   // to exist, depending on the Pede configuration.
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 }  // namespace
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 }