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) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef PARAMETERS_H
19#define PARAMETERS_H
20
21#include <string>
22#include <iostream>
23#include <iomanip>
24#include <map>
25#include "element.h"
26
27namespace GMAD
28{
29 extern bool willExit;
30
31 class Array;
32
43 struct Parameters : public Element {
44
46 std::map<std::string,bool> setMap;
47
49 void flush();
50
53 void inherit_properties(const Element& e);
54
56 template <typename T>
57 void set_value(std::string property, T value, bool bExit = true);
59 void set_value_array(const std::string& property, Array* value, bool bExit = true); // TODO keep separate as template calling order
60
62 Parameters();
63 };
64
65 template <typename T>
66 void Parameters::set_value(std::string property, T value, bool bExit)
67 {
68#ifdef BDSDEBUG
69 std::cout << "element> Setting value " << std::setw(25) << std::left << property << value << std::endl;
70#endif
71 // member method can throw runtime_error, catch and exit gracefully
72 try
73 {
74 Published<Element>::set(this,property,value);
75 }
76 catch(const std::runtime_error&)
77 {
78 // not implemented mad parameters will be ignored
79 if (property == "harmon" || property == "lag" || property == "volt")
80 {return;}
81
82 std::cerr << "Error: element> unknown parameter \"" << property << "\" with value " << value << std::endl;
83
84 willExit = bExit;
85 return;
86 }
87 // record property set
88 // property name can be different, so look up in alternate names
89 std::string publishedName = getPublishedName(property);
90 setMap.at(publishedName) = true;
91 }
92}
93
94#endif
Representation of arrays used in tokens.
Definition array.h:39
void set(C *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Element class.
Definition element.h:47
std::string getPublishedName(const std::string &name) const
returns 'official' member name for property
Definition element.cc:309
Parameters - Element class with booleans.
Definition parameters.h:43
std::map< std::string, bool > setMap
Map that holds booleans for every member of element.
Definition parameters.h:46
void inherit_properties(const Element &e)
void set_value_array(const std::string &property, Array *value, bool bExit=true)
Set method for lists.
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:66
Parameters()
Constructor.
Definition parameters.cc:30