OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
PeakReader.cpp
Go to the documentation of this file.
1 #include <fstream>
2 #include <iterator>
3 
4 #include "Util/PeakReader.h"
6 
7 PeakReader::PeakReader(std::string filename)
8  : filename_m(filename)
9 { }
10 
11 
13 
14 
16 
17  std::ifstream peak_file;
18 
19  peak_file.open(filename_m.c_str(), std::ios::in);
20 
21  if ( !peak_file ) {
22  throw OptPilotException("PeakReader::parseFile()",
23  "Error opening file " + filename_m);
24  }
25 
26  // skip header
27  std::string header;
28  std::getline(peak_file, header);
29 
30  if ( header.find("# Peak") == std::string::npos ) {
31  throw OptPilotException("PeakReader::parseFile()",
32  "Error reading file " + filename_m);
33  }
34 
35 
36  int nPeaks = 0;
37  peaks_m.clear();
38  std::istream_iterator<double> it(peak_file);
39  while ( it != std::istream_iterator<double>() ) {
40  peaks_m[++nPeaks] = *it;
41  ++it;
42  }
43 
44  peak_file.close();
45 }
46 
47 
48 void PeakReader::getPeak(int nPeak, double& radius) {
49 
50  if ( peaks_m.count(nPeak) > 0 ) {
51  radius = peaks_m[nPeak];
52  } else {
53  throw OptPilotException("PeakReader::getPeak",
54  "peak not found!");
55  }
56 }
57 
58 
60  return peaks_m.size();
61 }
void getPeak(int nPeak, double &radius)
Definition: PeakReader.cpp:48
std::string filename_m
Peak filename.
Definition: PeakReader.h:35
PeakReader(std::string filename)
Definition: PeakReader.cpp:7
std::map< int, double > peaks_m
all found peaks &lt; peak number, radius &gt;
Definition: PeakReader.h:38
void parseFile()
Definition: PeakReader.cpp:15
std::size_t getNumberOfPeaks()
Definition: PeakReader.cpp:59