CMS 3D CMS Logo

SurveyPxbImageReader.h
Go to the documentation of this file.
1 #ifndef GUARD_surveypxbimagereader_h
2 #define GUARD_surveypxbimagereader_h
3 
5 
6 #include <algorithm>
7 #include <iostream>
8 #include <sstream>
9 #include <vector>
10 #include <fstream>
11 #include <string>
12 
14 template <class T>
16 public:
17  typedef std::vector<T> measurements_t;
18 
19  // Constructors
23  SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800) {
24  read(infile, measurements, reserve);
25  };
26 
28  SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800) {
29  std::ifstream infile(filename.c_str());
30  if (!infile) {
31  std::cerr << "Cannot open file " << filename << " - operation aborted." << std::endl;
32  }
33  read(infile, measurements, reserve);
34  };
35 
43  measurements_t &measurements,
44  SurveyPxbImage::count_t reserve = 830) {
45  // prepare the measurements vector
46  measurements.clear();
47  measurements.reserve(reserve);
48 
49  // container for the current line
50  std::string aLine;
51 
52  // loop over lines of input file
53  while (std::getline(infile, aLine)) {
54  // strip off everything after a hash
55  std::string stripped = "";
56  std::string::iterator iter = std::find(aLine.begin(), aLine.end(), '#');
57  std::copy(aLine.begin(), iter, std::back_inserter(stripped));
58  // read one measurment and add to vector if successfull
59  std::istringstream iss(stripped, std::istringstream::in);
60  T curMeas(iss);
61  if (curMeas.isValid()) {
62  measurements.push_back(curMeas);
63  }
64  }
65 
66  return measurements.size();
67  }
68 
69 protected:
70 };
71 
72 #endif
SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve=800)
Constructor with ifstream and destination vector.
unsigned int count_t
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve=800)
Constructor with filename and destination vector.
Class to hold one picture of the BPix survey.
SurveyPxbImageReader()
Empty default constructor.
SurveyPxbImage::count_t read(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve=830)
long double T
std::vector< T > measurements_t