BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
parameters.cc
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#include "parameters.h"
19
20#include <cstdio>
21#include <iomanip>
22#include <iostream>
23#include <list>
24#include <string>
25
26#include "array.h"
27
28using namespace GMAD;
29
31{
32 // fill setMap, needs to match published member names
33 // usually same but some exceptions, those are commented
34 setMap["userTypeName"] = false;
35 setMap["userParameters"] = false;
36
37 setMap["l"] = false;
38 setMap["scaling"] = false;
39 setMap["scalingFieldOuter"] = false;
40 setMap["ks"] = false;
41 setMap["k1"] = false;
42 setMap["k2"] = false;
43 setMap["k3"] = false;
44 setMap["k4"] = false;
45 setMap["angle"] = false;
46 setMap["B"] = false;
47 setMap["e1"] = false;
48 setMap["e2"] = false;
49 setMap["fint"] = false;
50 setMap["fintx"] = false;
51 setMap["fintK2"] = false;
52 setMap["fintxK2"] = false;
53 setMap["h1"] = false;
54 setMap["h2"] = false;
55 setMap["hgap"] = false;
56 setMap["kick"] = false;
57 setMap["hkick"] = false;
58 setMap["vkick"] = false;
59 setMap["knl"] = false;
60 setMap["ksl"] = false;
61 setMap["gradient"] = false;
62 setMap["E"] = false;
63 setMap["gradient"] = false;
64 setMap["frequency"] = false;
65 setMap["phase"] = false;
66 setMap["tOffset"] = false;
67 setMap["fieldModulator"] = false;
68 setMap["kg"] = false;
69
70 setMap["kick1"] = false;
71 setMap["kick2"] = false;
72 setMap["kick3"] = false;
73 setMap["kick4"] = false;
74 setMap["rmat11"] = false;
75 setMap["rmat12"] = false;
76 setMap["rmat13"] = false;
77 setMap["rmat14"] = false;
78 setMap["rmat21"] = false;
79 setMap["rmat22"] = false;
80 setMap["rmat23"] = false;
81 setMap["rmat24"] = false;
82 setMap["rmat31"] = false;
83 setMap["rmat32"] = false;
84 setMap["rmat33"] = false;
85 setMap["rmat34"] = false;
86 setMap["rmat41"] = false;
87 setMap["rmat42"] = false;
88 setMap["rmat43"] = false;
89 setMap["rmat44"] = false;
90
91 setMap["beampipeThickness"] = false;
92 setMap["aper1"] = false;
93 setMap["aper2"] = false;
94 setMap["aper3"] = false;
95 setMap["aper4"] = false;
96 setMap["apertureType"] = false;
97 setMap["beampipeMaterial"] = false;
98 setMap["vacuumMaterial"] = false;
99
100 setMap["magnetGeometryType"] = false;
101 setMap["horizontalWidth"] = false;
102 setMap["yokeOnInside"] = false;
103 setMap["hStyle"] = false;
104 setMap["vhRatio"] = false;
105 setMap["coilWidthFraction"] = false;
106 setMap["coilHeightFraction"] = false;
107 setMap["tilt"] = false;
108 setMap["xsize"] = false;
109 setMap["ysize"] = false;
110 setMap["xsizeOut"] = false;
111 setMap["ysizeOut"] = false;
112 setMap["xsizeLeft"] = false;
113 setMap["xsizeRight"] = false;
114 setMap["offsetX"] = false;
115 setMap["offsetY"] = false;
116 setMap["xsize2"] = false;
117 setMap["ysize2"] = false;
118 setMap["offsetX2"] = false;
119 setMap["offsetY2"] = false;
120 setMap["tilt2"] = false;
121 setMap["outerShape"] = false;
122
123 setMap["tscint"] = false;
124 setMap["twindow"] = false;
125 setMap["tmount"] = false;
126 setMap["windowScreenGap"] = false;
127 setMap["screenXSize"] = false;
128 setMap["screenYSize"] = false;
129 setMap["layerThicknesses"] = false;
130 setMap["layerMaterials"] = false;
131 setMap["layerIsSampler"] = false;
132
133 setMap["screenPSize"] = false;
134 setMap["screenEndZ"] = false;
135 setMap["poleStartZ"] = false;
136 setMap["screenWidth"] = false;
137 setMap["awakeMagnetOffsetX"] = false;
138 setMap["scintmaterial"] = false;
139 setMap["windowmaterial"] = false;
140 setMap["mountmaterial"] = false;
141
142 setMap["xdir"] = false;
143 setMap["ydir"] = false;
144 setMap["zdir"] = false;
145 setMap["wavelength"] = false;
146 setMap["gradient"] = false;
147 setMap["phi"] = false;
148 setMap["theta"] = false;
149 setMap["psi"] = false;
150 setMap["axisX"] = false;
151 setMap["axisY"] = false;
152 setMap["axisZ"] = false;
153 setMap["axisAngle"] = false;
154
155 setMap["numberWedges"] = false;
156 setMap["wedgeLength"] = false;
157 setMap["degraderHeight"] = false;
158 setMap["materialThickness"] = false;
159 setMap["degraderOffset"] = false;
160
161 setMap["laserBeam"] = false;
162 setMap["laserOffsetTheta"] = false;
163 setMap["laserOffsetPhi"] = false;
164 setMap["laserOffsetX"] = false;
165 setMap["laserOffsetY"] = false;
166 setMap["laserOffsetZ"] = false;
167
168 setMap["wireDiameter"] = false;
169 setMap["wireLength"] = false;
170 setMap["wireOffsetX"] = false;
171 setMap["wireOffsetY"] = false;
172 setMap["wireOffsetZ"] = false;
173 setMap["wireAngle"] = false;
174
175 setMap["undulatorPeriod"] = false;
176 setMap["undulatorGap"] = false;
177 setMap["undulatorMagnetHeight"] = false;
178
179 setMap["anodeLength"] = false;
180 setMap["anodeRadius"] = false;
181 setMap["anodeThickness"] = false;
182 setMap["electrodeLength"] = false;
183 setMap["electrodeRadius"] = false;
184 setMap["electrodeThickness"] = false;
185
186 setMap["bias"] = false;
187 setMap["biasMaterial"] = false;
188 setMap["biasVacuum"] = false;
189 setMap["biasMaterialLV"] = false;
190
191 setMap["minimumKineticEnergy"] = false;
192
193 setMap["samplerName"] = false;
194 setMap["samplerType"] = false;
195 setMap["samplerRadius"] = false;
196 setMap["region"] = false;
197 setMap["fieldOuter"] = false;
198 setMap["fieldVacuum"] = false;
199 setMap["fieldAll"] = false;
200
201 setMap["geometryFile"] = false;
202 setMap["stripOuterVolume"] = false;
203 setMap["autoColour"] = false;
204 setMap["elementLengthIsArcLength"] = false;
205 setMap["material"] = false;
206 setMap["namedVacuumVolumes"] = false;
207 setMap["markAsCollimator"] = false;
208 setMap["spec"] = false;
209 setMap["cavityModel"] = false;
210 setMap["cavityFieldType"] = false;
211
212 setMap["dicomDataPath"] = false;
213 setMap["dicomDataFile"] = false;
214
215 setMap["colour"] = false;
216
217 setMap["jawTiltLeft"] = false;
218 setMap["jawTiltRight"] = false;
219
220 setMap["tipMaterial"] = false;
221 setMap["tipThickness"] = false;
222
223 setMap["crystalLeft"] = false;
224 setMap["crystalRight"] = false;
225 setMap["crystalBoth"] = false;
226 setMap["crystalAngleYAxisLeft"] = false;
227 setMap["crystalAngleYAxisRight"] = false;
228
229 setMap["coolingDefinition"] = false;
230}
231
233{
235
236 for (auto& i : setMap)
237 {i.second = false;}
238}
239
241{
242 // copy parameters into temporary buffer params from element e
243 // parameters already set in params have priority and are not overridden
244 // this is used for the inheritance / newinstance mechanism
245
246 for (auto& i : setMap)
247 {
248 if(i.second == false)
249 {
250 std::string property = i.first;
251 // method can in theory throw runtime_error (shouldn't happen), catch and exit gracefully
252 try
253 {Published<Element>::set(this,(Element*)&e,property);}
254 catch(const std::runtime_error&)
255 {
256 std::cerr << "Error: element> unknown property \"" << property
257 << "\" from element " << e.name << std::endl;
258 exit(1);
259 }
260 i.second = true;
261 }
262 }
263}
264
265void Parameters::set_value_array(const std::string& property, Array* value, bool bExit)
266{
267 auto search1 = attribute_map_list_int.find(property);
268 if (search1 != attribute_map_list_int.end())
269 {
270 value->set_vector(*search1->second);
271 std::string publishedName = getPublishedName(property);
272 setMap.at(publishedName) = true;
273 return;
274 }
275
276 auto search2 = attribute_map_list_double.find(property);
277 if (search2 != attribute_map_list_double.end())
278 {
279 value->set_vector(*search2->second);
280 std::string publishedName = getPublishedName(property);
281 setMap.at(publishedName) = true;
282 return;
283 }
284
285 auto search3 = attribute_map_list_string.find(property);
286 if (search3 != attribute_map_list_string.end()) {
287 value->set_vector(*search3->second);
288 std::string publishedName = getPublishedName(property);
289 setMap.at(publishedName) = true;
290 return;
291 }
292
293 std::cerr << "Error: parser> unknown element option \"" << property << "\", or doesn't expect vector type" << std::endl;
294 if(bExit)
295 {exit(1);}
296 else
297 {std::rethrow_exception(std::current_exception());}
298
299}
Representation of arrays used in tokens.
Definition array.h:39
void set_vector(Container< std::string, std::allocator< std::string > > &dst) const
Copy symbols into STL string containers.
Definition array.h:101
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
void flush()
flush method
Definition element.cc:509
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.
Parameters()
Constructor.
Definition parameters.cc:30