OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
NumberOfPeaks.h
Go to the documentation of this file.
1//
2// Struct NumberOfPeaks
3// A simple expression to check the number of turns in a circular machine. It checks
4// probe files (*.peaks) and counts the number of turns.
5//
6// Copyright (c) 2018, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// Implemented as part of the PhD thesis
10// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
11// and the paper
12// "Matching of turn pattern measurements for cyclotrons using multiobjective optimization"
13// (https://doi.org/10.1103/PhysRevAccelBeams.22.064602)
14//
15// This file is part of OPAL.
16//
17// OPAL is free software: you can redistribute it and/or modify
18// it under the terms of the GNU General Public License as published by
19// the Free Software Foundation, either version 3 of the License, or
20// (at your option) any later version.
21//
22// You should have received a copy of the GNU General Public License
23// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
24//
25#ifndef __NUMBER_OF_PEAKS_H__
26#define __NUMBER_OF_PEAKS_H__
27
28#include <string>
29
30#include <cmath>
31
32#include "boost/type_traits/remove_cv.hpp"
33#include "boost/variant/get.hpp"
34#include "boost/variant/variant.hpp"
35#include "boost/smart_ptr.hpp"
36
37#include "Util/Types.h"
38#include "Util/PeakReader.h"
40
42
43 static const std::string name;
44
46 if (args.size() != 1) {
47 throw OptPilotException("NumberOfPeaks::operator()",
48 "numberOfPeaks expects 1 arguments, " + std::to_string(args.size()) + " given");
49 }
50
51 sim_filename_ = boost::get<std::string>(args[0]);
52
53 bool is_valid = true;
54
55 boost::scoped_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_));
56 std::size_t nPeaks = 0;
57
58 try {
59 sim_peaks->parseFile();
60 nPeaks = sim_peaks->getNumberOfPeaks();
61 } catch (OptPilotException &ex) {
62 std::cout << "Caught exception: " << ex.what() << std::endl;
63 is_valid = false;
64 }
65
66
67 return boost::make_tuple(nPeaks, is_valid);
68 }
69
70private:
71 std::string sim_filename_;
72
73 // define a mapping to arguments in argument vector
74 boost::tuple<std::string> argument_types;
75};
76
77#endif
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
boost::tuple< double, bool > Result_t
Definition: Expression.h:66
std::vector< argument_t > arguments_t
Definition: function.hpp:19
static const std::string name
Definition: NumberOfPeaks.h:43
Expressions::Result_t operator()(client::function::arguments_t args)
Definition: NumberOfPeaks.h:45
boost::tuple< std::string > argument_types
Definition: NumberOfPeaks.h:74
std::string sim_filename_
Definition: NumberOfPeaks.h:71
virtual const char * what() const