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 - 2024.
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, bool bExit = true);
59
61 Parameters();
62 };
63
64 template <typename T>
65 void Parameters::set_value(std::string property, T value, bool bExit)
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 {
73 Published<Element>::set(this,property,value);
74 }
75 catch(const std::runtime_error&)
76 {
77 // not implemented mad parameters will be ignored
78 if (property == "harmon" || property == "lag" || property == "volt")
79 {return;}
80
81 std::cerr << "Error: element> unknown parameter \"" << property << "\" with value " << value << std::endl;
82
83 willExit = bExit;
84 return;
85 }
86 // record property set
87 // property name can be different, so look up in alternate names
88 std::string publishedName = getPublishedName(property);
89 setMap.at(publishedName) = true;
90 }
91}
92
93#endif
void set(C *instance, const std::string &name, double value)
Definition published.h:101
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Element class.
Definition element.h:45
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition element.cc:299
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)
void flush()
Reset the parameters to defaults and setMap.
void set_value(std::string property, T value, bool bExit=true)
Set method by property name and value.
Definition parameters.h:65
Parameters()
Constructor.
Definition parameters.cc:31