BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
parameters.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef PARAMETERS_H
20#define PARAMETERS_H
21
22#include <string>
23#include <iostream>
24#include <iomanip>
25#include <map>
26#include "element.h"
27
28namespace GMAD
29{
30 extern bool willExit;
31
32 class Array;
33
44 struct Parameters : public Element {
45
47 std::map<std::string,bool> setMap;
48
50 void flush();
51
54 void inherit_properties(const Element& e);
55
57 template <typename T>
58 void set_value(std::string property, T value);
59
61 Parameters();
62 };
63
64 template <typename T>
65 void Parameters::set_value(std::string property, T value)
66 {
67#ifdef BDSDEBUG
68 std::cout << "element> Setting value " << std::setw(25) << std::left << property << value << std::endl;
69#endif
70 // member method can throw runtime_error, catch and exit gracefully
71 try {
72 Published<Element>::set(this,property,value);
73 }
74 catch(const std::runtime_error&) {
75 // not implemented mad parameters will be ignored
76 if (property == "harmon" || property == "lag" || property == "volt")
77 {return;}
78
79 std::cerr << "Error: element> unknown parameter \"" << property << "\" with value " << value << std::endl;
80 // don't exit here, but flag willExit instead
81 //exit(1);
82 willExit = true;
83 return;
84 }
85 // record property set
86 // property name can be different, so look up in alternate names
87 std::string publishedName = getPublishedName(property);
88 setMap.at(publishedName) = true;
89 }
90}
91
92#endif
void set(C *instance, const std::string &name, double value)
Definition: published.h:99
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Element class.
Definition: element.h:43
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition: element.cc:264
Parameters - Element class with booleans.
Definition: parameters.h:44
std::map< std::string, bool > setMap
Map that holds booleans for every member of element.
Definition: parameters.h:47
void inherit_properties(const Element &e)
Definition: parameters.cc:213
void flush()
Reset the parameters to defaults and setMap.
Definition: parameters.cc:205
Parameters()
Constructor.
Definition: parameters.cc:31
void set_value(std::string property, T value)
Set method by property name and value.
Definition: parameters.h:65