File indexing completed on 2024-09-07 04:34:42
0001 #ifndef GUARD_surveypxbimagereader_h
0002 #define GUARD_surveypxbimagereader_h
0003
0004 #include "Alignment/SurveyAnalysis/interface/SurveyPxbImage.h"
0005
0006 #include <algorithm>
0007 #include <iostream>
0008 #include <sstream>
0009 #include <vector>
0010 #include <fstream>
0011 #include <string>
0012
0013
0014 template <class T>
0015 class SurveyPxbImageReader {
0016 public:
0017 typedef std::vector<T> measurements_t;
0018
0019
0020
0021 SurveyPxbImageReader() {}
0022
0023 SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800) {
0024 read(infile, measurements, reserve);
0025 };
0026
0027
0028 SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800) {
0029 std::ifstream infile(filename.c_str());
0030 if (!infile) {
0031 std::cerr << "Cannot open file " << filename << " - operation aborted." << std::endl;
0032 }
0033 read(infile, measurements, reserve);
0034 };
0035
0036
0037
0038
0039
0040
0041
0042 SurveyPxbImage::count_t read(std::ifstream &infile,
0043 measurements_t &measurements,
0044 SurveyPxbImage::count_t reserve = 830) {
0045
0046 measurements.clear();
0047 measurements.reserve(reserve);
0048
0049
0050 std::string aLine;
0051
0052
0053 while (std::getline(infile, aLine)) {
0054
0055 std::string stripped = "";
0056 std::string::iterator iter = std::find(aLine.begin(), aLine.end(), '#');
0057 std::copy(aLine.begin(), iter, std::back_inserter(stripped));
0058
0059 std::istringstream iss(stripped, std::istringstream::in);
0060 T curMeas(iss);
0061 if (curMeas.isValid()) {
0062 measurements.push_back(curMeas);
0063 }
0064 }
0065
0066 return measurements.size();
0067 }
0068
0069 protected:
0070 };
0071
0072 #endif