File indexing completed on 2025-01-18 09:13:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "ReadSeedFile.hpp"
0011
0012
0013 #include <cmath>
0014 #include <fstream>
0015 #include <iostream>
0016 #include <limits>
0017 #include <sstream>
0018 #include <stdexcept>
0019
0020 std::vector<std::unique_ptr<TestSpacePoint> > readSeedFile(
0021 const std::string& fileName, bool filterDuplicates) {
0022
0023 std::vector<std::unique_ptr<TestSpacePoint> > result;
0024
0025
0026 std::ifstream spFile(fileName);
0027 if (!spFile.is_open()) {
0028 throw std::runtime_error("Could not open file: " + fileName);
0029 }
0030
0031
0032
0033 std::size_t duplicatesFound = 0;
0034 while (!spFile.eof()) {
0035 std::string line;
0036 std::getline(spFile, line);
0037 std::stringstream ss(line);
0038 std::string linetype;
0039
0040 ss >> linetype;
0041 if (linetype != "lxyz") {
0042 continue;
0043 }
0044
0045 int layer;
0046 float x, y, z, varianceR, varianceZ;
0047 ss >> layer >> x >> y >> z >> varianceR >> varianceZ;
0048 const float r = std::hypot(x, y);
0049 const float f22 = varianceR;
0050 const float wid = varianceZ;
0051 float cov = wid * wid * .08333;
0052
0053 if (cov < f22) {
0054 cov = f22;
0055 }
0056 if (std::abs(z) > 450.) {
0057 varianceZ = 9. * cov;
0058 varianceR = .06;
0059 } else {
0060 varianceR = 9. * cov;
0061 varianceZ = .06;
0062 }
0063
0064
0065 std::unique_ptr<TestSpacePoint> sp(
0066 new TestSpacePoint{x, y, z, r, layer, varianceR, varianceZ});
0067
0068
0069 if (filterDuplicates) {
0070 bool discardSP = false;
0071 for (const auto& otherSP : result) {
0072 if (*sp == *otherSP) {
0073 ++duplicatesFound;
0074 discardSP = true;
0075 break;
0076 }
0077 }
0078 if (discardSP) {
0079 continue;
0080 }
0081 }
0082
0083
0084 result.push_back(std::move(sp));
0085 }
0086
0087 if (duplicatesFound) {
0088 std::cerr << duplicatesFound << " duplicates found in: " << fileName
0089 << std::endl;
0090 }
0091
0092 return result;
0093 }