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> class SurveyPxbImageReader
15 {
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  {
25  read(infile, measurements, reserve);
26  };
27 
29  SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800)
30  {
31  std::ifstream infile(filename.c_str());
32  if (!infile)
33  {
34  std::cerr << "Cannot open file " << filename
35  << " - operation aborted." << std::endl;
36  }
37  read(infile, measurements, reserve);
38  };
39 
46  SurveyPxbImage::count_t read(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 830)
47  {
48 
49  // prepare the measurements vector
50  measurements.clear();
51  measurements.reserve(reserve);
52 
53  // container for the current line
54  std::string aLine;
55 
56  // loop over lines of input file
57  while (std::getline(infile,aLine))
58  {
59  // strip off everything after a hash
60  std::string stripped = "";
61  std::string::iterator iter = std::find(aLine.begin(), aLine.end(), '#');
62  std::copy(aLine.begin(), iter, std::back_inserter(stripped));
63  // read one measurment and add to vector if successfull
64  std::istringstream iss(stripped, std::istringstream::in);
65  T curMeas(iss);
66  if (curMeas.isValid())
67  {
68  measurements.push_back(curMeas);
69  }
70  }
71 
72  return measurements.size();
73  }
74 
75  protected:
76 
77 };
78 
79 #endif
80 
SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve=800)
Constructor with ifstream and destination vector.
def copy(args, dbName)
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