CMS 3D CMS Logo

SurveyPxbImageReader.h
Go to the documentation of this file.
1 #ifndef GUARD_surveypxbimagereader_h
2 #define GUARD_surveypxbimagereader_h
3 
4 #include <sstream>
5 #include <vector>
6 #include <fstream>
7 #include <string>
8 
10 template <class T> class SurveyPxbImageReader
11 {
12  public:
13  typedef std::vector<T> measurements_t;
14 
15  // Constructors
19  SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800)
20  {
21  read(infile, measurements, reserve);
22  };
23 
25  SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800)
26  {
27  std::ifstream infile(filename.c_str());
28  if (!infile)
29  {
30  std::cerr << "Cannot open file " << filename
31  << " - operation aborted." << std::endl;
32  }
33  read(infile, measurements, reserve);
34  };
35 
42  SurveyPxbImage::count_t read(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 830)
43  {
44 
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  {
55  // strip off everything after a hash
56  std::string stripped = "";
57  std::string::iterator iter = std::find(aLine.begin(), aLine.end(), '#');
58  std::copy(aLine.begin(), iter, std::back_inserter(stripped));
59  // read one measurment and add to vector if successfull
60  std::istringstream iss(stripped, std::istringstream::in);
61  T curMeas(iss);
62  if (curMeas.isValid())
63  {
64  measurements.push_back(curMeas);
65  }
66  }
67 
68  return measurements.size();
69  }
70 
71  protected:
72 
73 };
74 
75 #endif
76 
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:20
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