Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-20 08:42:21

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 <boost/test/tools/old/interface.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 
0012 #include "Acts/Utilities/Logger.hpp"
0013 #include "ActsPlugins/Mille/MillePedeError.hpp"
0014 #include "ActsPlugins/Mille/MillePedeResultReader.hpp"
0015 
0016 #include <format>
0017 #include <fstream>
0018 
0019 using namespace ActsPlugins;
0020 
0021 BOOST_AUTO_TEST_SUITE(MillePedeResultReaderSimpleFile)
0022 
0023 bool operator==(const MillePedeParameterResult &r1,
0024                 const MillePedeParameterResult &r2) {
0025   return (r1.label == r2.label && r1.val == r2.val && r1.start == r2.start &&
0026           r1.delta == r2.delta && r1.sigma == r2.sigma &&
0027           r1.nRecords == r2.nRecords);
0028 }
0029 
0030 std::ostream &operator<<(std::ostream &str, const MillePedeParameterResult &p) {
0031   str << std::format(
0032       " [ Label {}, Val {}, Start {}, Delta {}, Sigma {}, NRecords {} ]",
0033       p.label, p.val, p.start, p.delta, p.sigma, p.nRecords);
0034   return str;
0035 }
0036 
0037 /// catch a missing steering file
0038 BOOST_AUTO_TEST_CASE(ReadSimpleFile) {
0039   auto logger = Acts::getDefaultLogger("ReadSimpleFile", Acts::Logging::INFO);
0040   std::filesystem::path dummyFileName("testResult.txt");
0041   std::ofstream dummyResultFile(dummyFileName);
0042   dummyResultFile << " # this is a comment line and will be ignored."
0043                   << std::endl;
0044 
0045   std::vector<MillePedeParameterResult> dummyResults{
0046       {1, 0.01, 0.00, 0.01, 0.001, 144},
0047       {41, -0.07, 0.00, -0.07, 0.001, 86},
0048       {99, -0.015, 10.00, -0.0, 0.0031, 1446},
0049   };
0050   for (const auto &[label, val, start, delta, sigma, nRec] : dummyResults) {
0051     dummyResultFile << label << " " << val << " " << start << " " << delta
0052                     << " " << sigma << " " << nRec << std::endl;
0053   }
0054   dummyResultFile.close();
0055   auto res = ActsPlugins::readMillePedeResult(dummyFileName, *logger);
0056   BOOST_CHECK(res.ok());
0057   BOOST_CHECK_EQUAL(res->size(), dummyResults.size());
0058   for (std::size_t i = 0; i < res->size(); ++i) {
0059     BOOST_CHECK(res->at(i) == dummyResults[i]);
0060   }
0061 }
0062 /// catch a missing steering file
0063 BOOST_AUTO_TEST_CASE(ReadInvalidFile) {
0064   // This test deliberately emits an error
0065   // message. To prevent the ACTS CI from
0066   // interpreting this as a failure,
0067   // we temporarily disable the failure threshold
0068   Acts::Logging::ScopedFailureThreshold threshold{Acts::Logging::Level::MAX};
0069   auto logger = Acts::getDefaultLogger("ReadSimpleFile", Acts::Logging::INFO);
0070 
0071   auto res = readMillePedeResult("/this/does/hopefully/not/exist?", *logger);
0072   BOOST_CHECK(!res.ok());
0073   BOOST_CHECK_EQUAL(res.error(), MillePedeError::SolutionNotReadable);
0074 }
0075 
0076 BOOST_AUTO_TEST_SUITE_END()