OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
PeakReader.cpp
Go to the documentation of this file.
1 //
2 // Class PeakReader
3 // Implements a parser and value extractor for peak files (*.peaks)
4 //
5 // Copyright (c) 2017 - 2018, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // Implemented as part of the PhD thesis
9 // "Precise Simulations of Multibunches in High Intensity Cyclotrons"
10 // and the paper
11 // "Matching of turn pattern measurements for cyclotrons using multiobjective optimization"
12 // (https://doi.org/10.1103/PhysRevAccelBeams.22.064602)
13 //
14 // This file is part of OPAL.
15 //
16 // OPAL is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
23 //
24 #include <fstream>
25 #include <iterator>
26 
27 #include "Util/PeakReader.h"
28 #include "Util/OptPilotException.h"
29 
30 PeakReader::PeakReader(std::string filename)
31  : filename_m(filename)
32 { }
33 
34 
36 
37 
39 
40  std::ifstream peak_file;
41 
42  peak_file.open(filename_m.c_str(), std::ios::in);
43 
44  if ( !peak_file ) {
45  throw OptPilotException("PeakReader::parseFile()",
46  "Error opening file " + filename_m);
47  }
48 
49  // skip header
50  std::string header;
51  std::getline(peak_file, header);
52 
53  if ( header.find("# Peak") == std::string::npos ) {
54  throw OptPilotException("PeakReader::parseFile()",
55  "Error reading file " + filename_m);
56  }
57 
58 
59  int nPeaks = 0;
60  peaks_m.clear();
61  std::istream_iterator<double> it(peak_file);
62  while ( it != std::istream_iterator<double>() ) {
63  peaks_m[++nPeaks] = *it;
64  ++it;
65  }
66 
67  peak_file.close();
68 }
69 
70 
71 void PeakReader::getPeak(int nPeak, double& radius) {
72 
73  if ( peaks_m.count(nPeak) > 0 ) {
74  radius = peaks_m[nPeak];
75  } else {
76  throw OptPilotException("PeakReader::getPeak",
77  "peak not found!");
78  }
79 }
80 
81 
83  return peaks_m.size();
84 }
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
Definition: LICENSE:43
void getPeak(int nPeak, double &radius)
Definition: PeakReader.cpp:71
std::size_t getNumberOfPeaks()
Definition: PeakReader.cpp:82
std::map< int, double > peaks_m
all found peaks &lt; peak number, radius &gt;
Definition: PeakReader.h:57
std::string filename_m
Peak filename.
Definition: PeakReader.h:54
PeakReader(std::string filename)
Definition: PeakReader.cpp:30
void parseFile()
Definition: PeakReader.cpp:38