OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 <cmath>
29#include <string>
30#include <tuple>
31#include <variant>
32
33#include "Util/Types.h"
34#include "Util/PeakReader.h"
36
38
39 static const std::string name;
40
42 if (args.size() != 1) {
43 throw OptPilotException("NumberOfPeaks::operator()",
44 "numberOfPeaks expects 1 arguments, " + std::to_string(args.size()) + " given");
45 }
46
47 sim_filename_ = std::get<std::string>(args[0]);
48
49 bool is_valid = true;
50
51 const std::unique_ptr<PeakReader> sim_peaks(new PeakReader(sim_filename_));
52 std::size_t nPeaks = 0;
53
54 try {
55 sim_peaks->parseFile();
56 nPeaks = sim_peaks->getNumberOfPeaks();
57 } catch (OptPilotException &ex) {
58 std::cout << "Caught exception: " << ex.what() << std::endl;
59 is_valid = false;
60 }
61
62
63 return std::make_tuple(nPeaks, is_valid);
64 }
65
66private:
67 std::string sim_filename_;
68
69 // define a mapping to arguments in argument vector
70 std::tuple<std::string> argument_types;
71};
72
73#endif
std::tuple< double, bool > Result_t
Definition Expression.h:65
std::vector< argument_t > arguments_t
Definition function.hpp:14
static const std::string name
Expressions::Result_t operator()(client::function::arguments_t args)
std::string sim_filename_
std::tuple< std::string > argument_types
virtual const char * what() const