BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
parser.cc
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#include "parser.h"
20
21#include <algorithm>
22#include <cmath>
23#include <iostream>
24#include <list>
25#include <set>
26#include <string>
27#include <vector>
28
29// for getpwuid: http://linux.die.net/man/3/getpwuid
30#include <unistd.h>
31#include <sys/types.h>
32#include <pwd.h>
33
34#include "array.h"
35#include "sym_table.h"
36
37namespace {
38 // helper method
39 // replace algorithm of all substring instances
40 // from http://stackoverflow.com/questions/2896600/how-to-replace-all-occurrences-of-a-character-in-string
41 void replaceAll(std::string& source, const std::string& from, const std::string& to)
42 {
43 std::string newString;
44 newString.reserve( source.length() ); // avoids a few memory allocations
45
46 std::string::size_type lastPos = 0;
47 std::string::size_type findPos;
48
49 while( std::string::npos != ( findPos = source.find( from, lastPos )))
50 {
51 newString.append( source, lastPos, findPos - lastPos );
52 newString += to;
53 lastPos = findPos + from.length();
54 }
55
56 // Care for the rest after last occurrence
57 newString += source.substr( lastPos );
58
59 source.swap( newString );
60 }
61}
62
63namespace GMAD {
64 // Explicitly make the templates we need here
65 template void Parser::Add<Atom, FastList<Atom> >();
66 template void Parser::Add<Aperture, FastList<Aperture> >();
67 template void Parser::Add<BLMPlacement, FastList<BLMPlacement> >();
68 template void Parser::Add<CavityModel, FastList<CavityModel> >();
69 template void Parser::Add<Crystal, FastList<Crystal> >();
70 template void Parser::Add<Field, FastList<Field> >();
71 template void Parser::Add<Material, FastList<Material> >();
72 template void Parser::Add<Modulator, FastList<Modulator> >();
73 template void Parser::Add<NewColour, FastList<NewColour> >();
74 template void Parser::Add<PhysicsBiasing, FastList<PhysicsBiasing> >();
75 template void Parser::Add<Placement, FastList<Placement> >();
76 template void Parser::Add<Query, FastList<Query> >();
77 template void Parser::Add<Region, FastList<Region> >();
78 template void Parser::Add<SamplerPlacement, FastList<SamplerPlacement> >();
79 template void Parser::Add<Scorer, FastList<Scorer> >();
80 template void Parser::Add<ScorerMesh, FastList<ScorerMesh> >();
81 template void Parser::Add<Tunnel, FastList<Tunnel> >();
82
83 template void Parser::Add<Atom, FastList<Atom> >(bool unique, const std::string& className);
84 template void Parser::Add<Aperture, FastList<Aperture> >(bool unique, const std::string& className);
85 template void Parser::Add<BLMPlacement, FastList<BLMPlacement> >(bool unique, const std::string& className);
86 template void Parser::Add<CavityModel, FastList<CavityModel> >(bool unique, const std::string& className);
87 template void Parser::Add<CoolingChannel, FastList<CoolingChannel> >(bool unique, const std::string& className);
88 template void Parser::Add<Crystal, FastList<Crystal> >(bool unique, const std::string& className);
89 template void Parser::Add<Field, FastList<Field> >(bool unique, const std::string& className);
90 template void Parser::Add<ScorerMesh, FastList<ScorerMesh> >(bool unique, const std::string& className);
91 template void Parser::Add<Material, FastList<Material> >(bool unique, const std::string& className);
92 template void Parser::Add<Modulator, FastList<Modulator> >(bool unique, const std::string& className);
93 template void Parser::Add<NewColour, FastList<NewColour> >(bool unique, const std::string& className);
94 template void Parser::Add<PhysicsBiasing, FastList<PhysicsBiasing> >(bool unique, const std::string& className);
95 //template void Parser::Add<Placement, FastList<Placement> >(bool unique, const std::string& className);
96 template void Parser::Add<Query, FastList<Query> >(bool unique, const std::string& className);
97 template void Parser::Add<Region, FastList<Region> >(bool unique, const std::string& className);
98 template void Parser::Add<SamplerPlacement, FastList<SamplerPlacement> >(bool unique, const std::string& className);
99 template void Parser::Add<Scorer, FastList<Scorer> >(bool unique, const std::string& className);
100 template void Parser::Add<Tunnel, FastList<Tunnel> >(bool unique, const std::string& className);
101 template void Parser::Add<Laser, FastList<Laser> >(bool unique, const std::string& className);
102}
103
104using namespace GMAD;
105
106namespace GMAD {
107 extern std::string yyfilename;
108}
109
110extern int yyparse();
111extern FILE *yyin;
112
113Parser* Parser::instance = nullptr;
114
116
117}
118
120{
121 if (!instance)
122 {
123 std::cerr << "Parser has not been initialized!" << std::endl;
124 exit(1);
125 }
126 return instance;
127}
128
129Parser* Parser::Instance(const std::string& name)
130{
131 if(instance)
132 {
133 std::cerr << "Warning parser was already initialized!" << std::endl;
134 delete instance;
135 }
136 instance = new Parser(name);
137 return instance;
138}
139
141{
142 beamline_list.erase();
143 // delete allocated lines
144 for (auto element : allocated_lines)
145 {delete element;}
146
147 instance = nullptr;
148}
149
150Parser::Parser(std::string name)
151{
152 instance = this;
153#ifdef BDSDEBUG
154 std::cout << "gmad_parser> opening file" << std::endl;
155#endif
156 // replace all ~ symbols with home directory to allow for that
157 // note $HOME is not necessarily equivalent to ~
158 // see http://linux.die.net/man/3/getpwuid
159 std::string tilde("~");
160 std::string home(getpwuid(getuid())->pw_dir);
161
162 replaceAll(name,tilde,home);
163
164 FILE *f = fopen(name.c_str(),"r");
165
166 if(f==nullptr)
167 {
168 std::cerr << "gmad_parser> Can't open input file " << name << std::endl;
169 exit(1);
170 }
171 // set global string for parser
172 yyfilename = std::string(name);
173
174 Initialise();
175
176 std::cout.precision(10); // set output precision to 10 decimals
177
178 ParseFile(f);
179}
180
181void Parser::ParseFile(FILE *f)
182{
183 yyin=f;
184
185#ifdef BDSDEBUG
186 std::cout << "gmad_parser> beginning to parse file" << std::endl;
187#endif
188
189 while(!feof(yyin))
190 {yyparse();}
191
193#ifdef BDSDEBUG
194 std::cout << "gmad_parser> finished to parsing file" << std::endl;
195#endif
196 // clear temporary stuff
197#ifdef BDSDEBUG
198 std::cout << "gmad_parser> clearing temporary lists" << std::endl;
199#endif
200 element_list.clear();
201 tmp_list.clear();
203 for(auto it : var_list)
204 {delete it;}
205
206#ifdef BDSDEBUG
207 std::cout << "gmad_parser> finished" << std::endl;
208#endif
209
210 fclose(f);
211}
212
214{
215 const int reserved = 1;
216 // embedded arithmetical functions
217 add_func("sqrt",std::sqrt);
218 add_func("cos",std::cos);
219 add_func("sin",std::sin);
220 add_func("exp",std::exp);
221 add_func("log",std::log);
222 add_func("tan",std::tan);
223 add_func("asin",std::asin);
224 add_func("acos",std::acos);
225 add_func("atan",std::atan);
226 add_func("abs",std::abs);
227
228 add_var("pi", 4.0*std::atan(1),reserved);
229 add_var("twopi", 8.0*std::atan(1),reserved);
230 add_var("halfpi", 2.0*std::atan(1),reserved);
231
232 add_var("PeV",1e6, reserved);
233 add_var("TeV",1e3, reserved);
234 add_var("GeV",1.0 ,reserved);
235 add_var("MeV",1e-3,reserved);
236 add_var("keV",1e-6,reserved);
237 add_var("KeV",1e-6,reserved); // for compatibility
238 add_var("eV" ,1e-9,reserved);
239
240 add_var("PJ", 1e12, reserved);
241 add_var("GJ", 1e9, reserved);
242 add_var("MJ", 1e6, reserved);
243 add_var("kJ", 1e3, reserved);
244 add_var("J", 1, reserved);
245 add_var("mJ", 1e-3, reserved);
246 add_var("uJ", 1e-6, reserved);
247 add_var("nJ", 1e-9, reserved);
248 add_var("pJ", 1e-12, reserved);
249
250 add_var("mV",1e-3,reserved);
251 add_var("V" ,1.0, reserved);
252 add_var("kV",1e+3,reserved);
253 add_var("MV",1e+6,reserved);
254 add_var("GV",1e+9,reserved);
255
256 add_var("Tesla",1.0,reserved);
257 add_var("T", 1.0,reserved);
258
259 add_var("km" ,1e3 ,reserved);
260 add_var("m" ,1.0 ,reserved);
261 add_var("cm" ,1e-2,reserved);
262 add_var("mm" ,1e-3,reserved);
263 add_var("um" ,1e-6,reserved);
264 add_var("mum",1e-6,reserved);
265 add_var("nm" ,1e-9,reserved);
266 add_var("ang",1e-10,reserved);
267 add_var("pm" ,1e-12,reserved);
268
269 add_var("s" ,1.0 ,reserved);
270 add_var("ms" ,1.e-3,reserved);
271 add_var("us" ,1.e-6,reserved);
272 add_var("ns" ,1.e-9,reserved);
273 add_var("ps" ,1.e-12,reserved);
274
275 add_var("Hz" ,1.0, reserved);
276 add_var("kHz",1e+3, reserved);
277 add_var("MHz",1e+6, reserved);
278 add_var("GHz",1e+9, reserved);
279 add_var("THz",1e+12,reserved);
280
281 add_var("rad" ,1.0, reserved);
282 add_var("mrad",1e-3,reserved);
283 add_var("urad",1e-6,reserved);
284 add_var("nrad",1e-9,reserved);
285
286 add_var("degrees",std::atan(1)/45,reserved);
287
288 add_var("clight",2.99792458e+8,reserved);
289
290 add_var("kg_per_cubic_m", 1e-3, reserved);
291 add_var("g_per_cubic_m", 1e-6, reserved);
292 add_var("g_per_cubic_cm", 1, reserved);
293
294 add_var("pascal", 1/101324.99987983676, reserved);
295 add_var("bar", 1/1.0132499987983676, reserved);
296 add_var("torr", 0.00131579, reserved);
297 add_var("atmosphere", 1, reserved);
298
299 params.flush();
300}
301
303{
304 std::cout << "parsing complete..." << std::endl;
305 exit(0);
306}
307
308void Parser::write_table(std::string* name, ElementType type, bool isLine)
309{
310 Element e;
311 e.set(params,*name,type);
312 if (isLine)
313 {
314 e.lst = new std::list<Element>(tmp_list);
315 allocated_lines.push_back(e.lst);
316 // clean list
317 tmp_list.clear();
318 sequences.push_back(*name); // append to all sequence definitions
319 }
320
321 // insert element with uniqueness requirement
322 element_list.push_back(e,true);
323}
324
326{
327 for (const auto& name : sequences)
328 {
329 FastList<Element>* newLine = new FastList<Element>();
330 expand_line(*newLine, name);
331 expandedSequences[name] = newLine;
332 }
333}
334
335void Parser::expand_line(const std::string& name,
336 const std::string& start,
337 const std::string& end)
338{
339 expand_line(beamline_list, name, start, end);
340}
341
343 const std::string& name,
344 const std::string& start,
345 const std::string& end)
346{
347 const Element& line = find_element(name);
348 if(line.type != ElementType::_LINE && line.type != ElementType::_REV_LINE )
349 {
350 std::cerr << "Error with use command: \"" << name << "\" is not a line" << std::endl;
351 exit(1);
352 }
353
354 // delete the previous beamline
355 target.clear();
356
357 // expand the desired beamline
358 Element e;
359 e.type = line.type;
360 e.name = name;
361 e.l = 0;
362 e.lst = nullptr;
363
364 target.push_back(e);
365
366#ifdef BDSDEBUG
367 std::cout << "expanding line " << name << ", range = " << start << end << std::endl;
368#endif
369 if (!line.lst)
370 {return;} //list empty
371
372 // first expand the whole range
373 std::list<Element>::iterator sit = line.lst->begin();
374 std::list<Element>::iterator eit = line.lst->end();
375
376 // copy the list into the resulting list
377 switch(line.type)
378 {
379 case ElementType::_LINE:
380 {target.insert(target.end(),sit,eit); break;}
381 case ElementType::_REV_LINE:
382 {target.insert(target.end(),line.lst->rbegin(),line.lst->rend()); break;}
383 default:
384 {target.insert(target.end(),sit,eit); break;}
385 }
386 // bool to check if beamline is fully expanded
387 bool is_expanded = false;
388
389 // parse starting from the second element until the list is expanded
390 int iteration = 0;
391 while (!is_expanded)
392 {
393 is_expanded = true;
394 // start at second element
395 std::list<Element>::iterator it = ++target.begin();
396 for (; it!=target.end(); ++it)
397 {
398 Element& element = *it; // alias
399 const ElementType& type = element.type;
400#ifdef BDSDEBUG
401 std::cout << element.name << " , " << type << std::endl;
402#endif
403 // if list - expand further
404 if (type != ElementType::_LINE && type != ElementType::_REV_LINE)
405 {continue;}
406 is_expanded = false;
407 // lookup the line in main list
408 std::list<Element>::const_iterator tmpit = element_list.find(element.name);
409 std::list<Element>::const_iterator iterEnd = element_list.end();
410 if ( (tmpit != iterEnd) && ( (*tmpit).lst != nullptr) )
411 { // sublist found and not empty
412 const Element& list = *tmpit; // alias
413#ifdef BDSDEBUG
414 std::cout << "inserting sequence for " << element.name << " - " << list.name << " ...";
415#endif
416 if (type == ElementType::_LINE)
417 {target.insert(it,list.lst->begin(),list.lst->end());}
418 else if (type == ElementType::_REV_LINE)
419 {
420 //iterate over list and invert any sublines contained within. SPM
421 std::list<Element> tmpList;
422 tmpList.insert(tmpList.end(),list.lst->begin(),list.lst->end());
423 for (std::list<Element>::iterator itLineInverter = tmpList.begin();
424 itLineInverter != tmpList.end(); ++itLineInverter)
425 {
426 if ( (*itLineInverter).type == ElementType::_LINE)
427 {(*itLineInverter).type = ElementType::_REV_LINE;}
428 else if ((*itLineInverter).type == ElementType::_REV_LINE)
429 {(*itLineInverter).type = ElementType::_LINE;}
430 }
431 target.insert(it,tmpList.rbegin(),tmpList.rend());
432 }
433#ifdef BDSDEBUG
434 std::cout << "inserted" << std::endl;
435#endif
436 // delete the list pointer
437 target.erase(it--);
438 }
439 else if ( tmpit != iterEnd )
440 { // entry points to a scalar element type -
441 //transfer properties from the main list
442#ifdef BDSDEBUG
443 std::cout << "keeping element..." << element.name << std::endl;
444#endif
445 // copy properties
446 element = (*tmpit);
447
448#ifdef BDSDEBUG
449 std::cout << "done" << std::endl;
450#endif
451 }
452 else
453 { // element of undefined type
454 std::cerr << "Error : Expanding line \"" << name << "\" : element \"" << element.name
455 << "\" has not been defined! " << std::endl;
456 exit(1);
457 }
458 }
459 iteration++;
460 if ( iteration > MAX_EXPAND_ITERATIONS )
461 {
462 std::cerr << "Error : Line expansion of '" << name << "' seems to loop, " << std::endl
463 << "possible recursive line definition, quitting" << std::endl;
464 exit(1);
465 }
466 }// while
467
468 // leave only the desired range
469 //
470 // rule - from first occurrence of 'start' till first 'end' coming after 'start'
471
472 if ( !start.empty()) // determine the start element
473 {
474 std::list<Element>::const_iterator startIt = target.find(std::string(start));
475
476 if(startIt!=target.end())
477 {target.erase(target.begin(),startIt);}
478 }
479
480 if ( !end.empty()) // determine the end element
481 {
482 std::list<Element>::const_iterator endIt = target.find(std::string(end));
483
484 if(endIt!=target.end())
485 {target.erase(++endIt,target.end());}
486 }
487
488 // insert the tunnel if present
489
490 std::list<Element>::iterator itTunnel = element_list.find("tunnel");
491 if (itTunnel!=element_list.end())
492 {target.push_back(*itTunnel);}
493}
494
495const FastList<Element>& Parser::get_sequence(const std::string& name)
496{
497 // search for previously queried beamlines
498 const auto search = expandedSequences.find(name);
499 if (search != expandedSequences.end())
500 {return *(search->second);}
501 else
502 {std::cerr << "parser> no such sequence \"" << name << "\"" << std::endl; exit(1);}
503}
504
505void Parser::set_sampler(const std::string& name,
506 int count,
507 ElementType type,
508 const std::string& samplerType,
509 double samplerRadius,
510 int particleSetID)
511{
512 // if count equal to -2 add to all elements regardless of name
513 // typically used for output elements like samplers
514 // skip first element and add one at the end
515 if (count == -2)
516 {
517 for (auto it = beamline_list.begin(); it != beamline_list.end(); ++it)
518 {// skip LINEs
519 if((*it).type == ElementType::_LINE || (*it).type == ElementType::_REV_LINE)
520 {continue;}
521 // if type not equal to NONE and elements have to match type
522 if (type != ElementType::_NONE && type != (*it).type)
523 {continue;}
524
525 (*it).setSamplerInfo(samplerType,(*it).name,samplerRadius,particleSetID);
526 }
527 }
528 else if (count == -1) // if count equal to -1 add sampler to all element instances
529 {
530 auto itPair = beamline_list.equal_range(name);
531 if (itPair.first == itPair.second)
532 {
533 std::string msg = "parser> SetSampler> current beamline doesn't contain element \"" + name + "\"";
534 yyerror2(msg.c_str());
535 }
536 for (auto it = itPair.first; it != itPair.second; ++it)
537 {
538 // if sampler is attached to a marker, really attach it to the previous element with the name of marker
539 auto elementIt = (it->second);
540 std::string samplerName = elementIt->name;
541 if ((*elementIt).type == ElementType::_MARKER)
542 {
543 // need to find real element before
544 // but careful not to go beyond first element also!
545 while ((*elementIt).isSpecial())
546 {
547 elementIt--;
548 // have to break first before continue since in while loop
549 if (elementIt == beamline_list.begin())
550 {break;}
551 }
552
553 if (elementIt==beamline_list.begin())
554 {
555 std::cout << "parser> SetSampler> WARNING: no element before marker " << name << ", no sampler added" << std::endl;
556 continue;
557 }
558 }
559 (*elementIt).setSamplerInfo(samplerType,samplerName,samplerRadius,particleSetID);
560 }
561 }
562 else
563 {
564 auto it = beamline_list.find(name,count);
565 if (it==beamline_list.end())
566 {
567 std::string msg = "parser> SetSampler> current beamline doesn't contain element \"" + name + "\" with number " + std::to_string(count);
568 yyerror2(msg.c_str());
569 }
570 // if sampler is attached to a marker, really attach it to the previous element with the name of marker
571 std::string samplerName = (*it).name;
572 if ((*it).type == ElementType::_MARKER)
573 {
574 // need to find real element before
575 // but careful not to go beyond first element also!
576 while ((*it).isSpecial())
577 {
578 it--;
579 if (it == beamline_list.begin())
580 {
581 std::cout << "parser> SetSampler> WARNING: no element before marker " << name << ", no sampler added" << std::endl;
582 return;
583 }
584 }
585 }
586 (*it).setSamplerInfo(samplerType,samplerName,samplerRadius,particleSetID);
587 }
588}
589
590int Parser::add_sampler_partIDSet(std::list<int>* samplerPartIDListIn)
591{
592 if (!samplerPartIDListIn)
593 {return -1;}
594 std::set<int> partIDs = std::set<int>(std::begin(*samplerPartIDListIn), std::end(*samplerPartIDListIn));
595 auto alreadyExists = samplerFilters.count(partIDs);
596 if (alreadyExists > 0)
597 {return setToSamplerFilterID[partIDs];}
598 else
599 {
600 int particleSetID = (int) samplerFilterIDToSet.size();
601 samplerFilterIDToSet[particleSetID] = partIDs;
602 setToSamplerFilterID[partIDs] = particleSetID;
603 samplerFilters.insert(partIDs);
604 return particleSetID;
605 }
606}
607
608void Parser::add_sampler(const std::string& name, int count, ElementType type, std::string samplerType, std::list<int>* samplerPartIDListIn)
609{
610#ifdef BDSDEBUG
611 std::cout << "inserting sampler " << name;
612 if (count>=0)
613 {std::cout << "[" << count << "]";}
614 std::cout << std::endl;
615#endif
616 int particleSetID = add_sampler_partIDSet(samplerPartIDListIn);
617 set_sampler(name,count,type,samplerType,0,particleSetID);
618}
619
620Element& Parser::find_element(const std::string& element_name)
621{
622 std::list<Element>::iterator it = element_list.find(element_name);
623 std::list<Element>::const_iterator iterEnd = element_list.end();
624
625 if(it == iterEnd)
626 {
627 std::cerr << "parser.h> Error: element (type) \"" << element_name
628 << "\" has not been defined." << std::endl;
629 exit(1);
630 }
631 return (*it);
632}
633
634const Element& Parser::find_element(const std::string& element_name)const
635{
636 auto search = element_list.find(element_name);
637 if (search == element_list.end())
638 {
639 std::cerr << "parser.h> Error: unknown element \"" << element_name << "\"." << std::endl;
640 exit(1);
641 }
642 return (*search);
643}
644
645const Element* Parser::find_placement_element_safe(const std::string& element_name) const
646{
647 const Element* result = nullptr;
648 auto search = placement_elements.find(element_name);
649 if (search != placement_elements.end())
650 {
651 const GMAD::Element& ele = *search;
652 result = &ele;
653 }
654 return result;
655}
656
657const Element* Parser::find_element_safe(const std::string& element_name) const
658{
659 const Element* result = nullptr;
660 auto search = element_list.find(element_name);
661 if (search != element_list.end())
662 {
663 const GMAD::Element& ele = *search;
664 result = &ele;
665 }
666 return result;
667}
668
669double Parser::property_lookup(const std::string& element_name, const std::string& property_name)const
670{
671 const Element& element = find_element(element_name);
672 return element.property_lookup(property_name);
673}
674
675void Parser::add_element_temp(const std::string& name, int number, bool pushfront, ElementType linetype)
676{
677#ifdef BDSDEBUG
678 std::cout << "matched sequence element, " << name;
679 if (number > 1)
680 {std::cout << " * " << number;}
681 std::cout << std::endl;
682#endif
683 // add to temporary element sequence
684 Element e;
685 e.name = name;
686 e.type = linetype;
687 e.lst = nullptr;
688 if (pushfront)
689 {
690 for (int i = 0; i < number; i++)
691 {tmp_list.push_front(e);}
692 }
693 else
694 {
695 for (int i = 0; i < number; i++)
696 {tmp_list.push_back(e);}
697 }
698}
699
700int Parser::copy_element_to_params(const std::string& elementName)
701{
702 int type;
703#ifdef BDSDEBUG
704 std::cout << "newinstance : VARIABLE -- " << elementName << std::endl;
705#endif
706 const Element& element = find_element(elementName);
707
708 // inherit properties from the base type
709 type = static_cast<int>(element.type);
710 params.inherit_properties(element);
711
712 return type;
713}
714
715void Parser::add_func(std::string name, double (*func)(double))
716{
717 Symtab *sp=symtab_map.symcreate(name);
718 sp->Set(func);
719}
720
721void Parser::add_var(std::string name, double value, int is_reserved)
722{
723 Symtab* sp = symtab_map.symcreate(name);
724 sp->Set(value,is_reserved);
725}
726
727bool Parser::InvalidSymbolName(const std::string& s, std::string& errorReason)
728{
729 bool result = false;
730 if (options.NameExists(s))
731 {result = true; errorReason = "The variable name \"" + s + "\" is an option name and cannot be used as a variable name";}
732 return result;
733}
734
735Symtab * Parser::symcreate(const std::string& s)
736{
737 return symtab_map.symcreate(s);
738}
739
740Symtab * Parser::symlook(const std::string& s)
741{
742 return symtab_map.symlook(s);
743}
744void Parser::Store(double value)
745{
746 tmparray.push_front(value);
747}
748
749void Parser::Store(const std::string& name)
750{
751 tmpstring.push_front(name);
752}
753
755{
756 array->Copy(tmparray);
757 tmparray.clear();
758}
759
761{
762 array->Copy(tmpstring);
763 tmpstring.clear();
764}
765
767{
768 params.flush();
769 samplerFilters.clear();
770}
771
772void Parser::Overwrite(const std::string& objectName)
773{
774 // find object and set values
775
776 // possible object types are:
777 // element, atom, colour, crystal, coolingchannel, field, laser, material, physicsbiasing, placement,
778 // query, region, tunnel, cavitymodel, samplerplacement, aperture, scorer, scorermesh, blm
779 bool extended = false;
780 auto element_it = element_list.find(objectName);
781 if (element_it != element_list.end())
782 {
783 ExtendObject(*element_it);
784 extended = true;
785 }
786 else
787 {
788 auto it = xsecbias_list.find(objectName);
789 if (it != xsecbias_list.end() )
790 {
791 ExtendObject(*it);
792 extended = true;
793 }
794 }
795 // vectors
796 if (!extended) {
797 if ( (extended = FindAndExtend<Atom> (objectName)) ) {}
798 else if ( (extended = FindAndExtend<NewColour> (objectName)) ) {}
799 else if ( (extended = FindAndExtend<Crystal> (objectName)) ) {}
800 else if ( (extended = FindAndExtend<CoolingChannel> (objectName)) ) {}
801 else if ( (extended = FindAndExtend<Field> (objectName)) ) {}
802 else if ( (extended = FindAndExtend<Material> (objectName)) ) {}
803 else if ( (extended = FindAndExtend<Placement> (objectName)) ) {}
804 else if ( (extended = FindAndExtend<Query> (objectName)) ) {}
805 else if ( (extended = FindAndExtend<Region> (objectName)) ) {}
806 else if ( (extended = FindAndExtend<Tunnel> (objectName)) ) {}
807 else if ( (extended = FindAndExtend<CavityModel>(objectName)) ) {}
808 else if ( (extended = FindAndExtend<SamplerPlacement>(objectName)) ) {}
809 else if ( (extended = FindAndExtend<Scorer> (objectName)) ) {}
810 else if ( (extended = FindAndExtend<ScorerMesh> (objectName)) ) {}
811 else if ( (extended = FindAndExtend<Aperture> (objectName)) ) {}
812 else if ( (extended = FindAndExtend<BLMPlacement> (objectName)) ) {}
813 else if ( (extended = FindAndExtend<Modulator> (objectName)) ) {}
814 else if ( (extended = FindAndExtend<Laser> (objectName)) ) {}
815 }
816
817 if (!extended)
818 {
819 std::cerr << "parser.h> Error: object \"" << objectName
820 << "\" has not been defined and can't be extended." << std::endl;
821 exit(1);
822 }
823
824 // clear maps
825 extendedNumbers.clear();
826 extendedStrings.clear();
827 extendedVectors.clear();
828}
829
830template <class C>
831bool Parser::FindAndExtend(const std::string& objectName)
832{
833 GMAD::FastList<C>& fl = GetList<C>();
834 auto search = fl.find(objectName);
835 if (search != fl.end())
836 {
837 ExtendObject(*search);
838 return true;
839 }
840 return false;
841}
842
843template<class C>
844void Parser::ExtendObject(C& object)
845{
846 for (auto& option : extendedNumbers)
847 {object.set_value(option.first, option.second);}
848 for (auto& option : extendedStrings)
849 {object.set_value(option.first, option.second);}
850 for (auto& option : extendedVectors)
851 {object.set_value(option.first, option.second);}
852}
853
854void Parser::AddVariable(std::string* name)
855{
856 var_list.push_back(name);
857}
858
860{
861 beamline_list.print();
862}
863
865{
866 element_list.print();
867}
868
870{
871 options.print();
872}
873
874bool Parser::TryPrintingObject(const std::string& objectName) const
875{
876 // We just don't know the type of the object, only the name, so we must
877 // search each member vector. Try to optimise by returning once done.
878 // This is a cpu-heavy solution vs a memory-heavy one that would have to
879 // keep a duplicate copy of all objects for printing.
880
881 const std::string& on = objectName; // shortcut
882
883 // we use a lambda to compare against obj.name instead of obj itself
884 auto searchAtom = std::find_if(atom_list.begin(), atom_list.end(), [&on](const Atom& obj) {return obj.name == on;});
885 if (searchAtom != atom_list.end())
886 {searchAtom->print(); return true;}
887 auto searchNewColour = std::find_if(colour_list.begin(), colour_list.end(), [&on](const NewColour& obj) {return obj.name == on;});
888 if (searchNewColour != colour_list.end())
889 {searchNewColour->print(); return true;}
890 auto searchCrystal = std::find_if(crystal_list.begin(), crystal_list.end(), [&on](const Crystal& obj) {return obj.name == on;});
891 if (searchCrystal != crystal_list.end())
892 {searchCrystal->print(); return true;}
893 auto searchCoolingChannel = std::find_if(coolingchannel_list.begin(), coolingchannel_list.end(), [&on](const CoolingChannel& obj) {return obj.name == on;});
894 if (searchCoolingChannel != coolingchannel_list.end())
895 {searchCoolingChannel->print(); return true;}
896 auto searchField = std::find_if(field_list.begin(), field_list.end(), [&on](const Field& obj) {return obj.name == on;});
897 if (searchField != field_list.end())
898 {searchField->print(); return true;}
899 auto searchLaser = std::find_if(laser_list.begin(), laser_list.end(), [&on](const Laser& obj) {return obj.name == on;});
900 if (searchLaser != laser_list.end())
901 {searchLaser->print(); return true;}
902 auto searchMaterial = std::find_if(material_list.begin(), material_list.end(), [&on](const Material& obj) {return obj.name == on;});
903 if (searchMaterial != material_list.end())
904 {searchMaterial->print(); return true;}
905 auto searchQuery = std::find_if(query_list.begin(), query_list.end(), [&on](const Query& obj) {return obj.name == on;});
906 if (searchQuery != query_list.end())
907 {searchQuery->print(); return true;}
908 auto searchRegion = std::find_if(region_list.begin(), region_list.end(), [&on](const Region& obj) {return obj.name == on;});
909 if (searchRegion != region_list.end())
910 {searchRegion->print(); return true;}
911 auto searchTunnel = std::find_if(tunnel_list.begin(), tunnel_list.end(), [&on](const Tunnel& obj) {return obj.name == on;});
912 if (searchTunnel != tunnel_list.end())
913 {searchTunnel->print(); return true;}
914 auto searchXsecbias = std::find_if(xsecbias_list.begin(), xsecbias_list.end(), [&on](const PhysicsBiasing& obj) {return obj.name == on;});
915 if (searchXsecbias != xsecbias_list.end())
916 {searchXsecbias->print(); return true;}
917 auto searchPlacement = std::find_if(placement_list.begin(), placement_list.end(), [&on](const Placement& obj) {return obj.name == on;});
918 if (searchPlacement != placement_list.end())
919 {searchPlacement->print(); return true;}
920 auto searchCavityModel = std::find_if(cavitymodel_list.begin(), cavitymodel_list.end(), [&on](const CavityModel& obj) {return obj.name == on;});
921 if (searchCavityModel != cavitymodel_list.end())
922 {searchCavityModel->print(); return true;}
923 auto searchSamplerPlacement = std::find_if(samplerplacement_list.begin(), samplerplacement_list.end(), [&on](const SamplerPlacement& obj) {return obj.name == on;});
924 if (searchSamplerPlacement != samplerplacement_list.end())
925 {searchSamplerPlacement->print(); return true;}
926 auto searchScorer = std::find_if(scorer_list.begin(), scorer_list.end(), [&on](const Scorer& obj) {return obj.name == on;});
927 if (searchScorer != scorer_list.end())
928 {searchScorer->print(); return true;}
929 auto searchScorerMesh = std::find_if(scorermesh_list.begin(), scorermesh_list.end(), [&on](const ScorerMesh& obj) {return obj.name == on;});
930 if (searchScorerMesh != scorermesh_list.end())
931 {searchScorerMesh->print(); return true;}
932 auto searchAperture = std::find_if(aperture_list.begin(), aperture_list.end(), [&on](const Aperture& obj) {return obj.name == on;});
933 if (searchAperture != aperture_list.end())
934 {searchAperture->print(); return true;}
935 auto searchBLMPlacement = std::find_if(blm_list.begin(), blm_list.end(), [&on](const BLMPlacement& obj) {return obj.name == on;});
936 if (searchBLMPlacement != blm_list.end())
937 {searchBLMPlacement->print(); return true;}
938 auto searchModulator = std::find_if(modulator_list.begin(), modulator_list.end(), [&on](const Modulator& obj) {return obj.name == on;});
939 if (searchModulator != modulator_list.end())
940 {searchModulator->print(); return true;}
941
942 return false;
943}
944
946{
947 return beamline_list;
948}
949
950//template specialisation
951// put explicitly in namespace since g++ complains
952namespace GMAD {
953
954 template<> Aperture& Parser::GetGlobal() {return aperture;}
955 template<> Aperture* Parser::GetGlobalPtr(){return &aperture;}
956 template<> FastList<Aperture>& Parser::GetList<Aperture>() {return aperture_list;}
957
958 template<> Atom& Parser::GetGlobal(){return atom;}
959 template<> Atom* Parser::GetGlobalPtr(){return &atom;}
960 template<> FastList<Atom>& Parser::GetList<Atom>(){return atom_list;}
961
962 template<> Beam& Parser::GetGlobal(){return beam;}
963 template<> Beam* Parser::GetGlobalPtr(){return &beam;}
964
965 template<> BLMPlacement& Parser::GetGlobal() {return blm;}
966 template<> BLMPlacement* Parser::GetGlobalPtr() {return &blm;}
967 template<> FastList<BLMPlacement>& Parser::GetList<BLMPlacement>() {return blm_list;}
968
969 template<> CavityModel& Parser::GetGlobal(){return cavitymodel;}
970 template<> CavityModel* Parser::GetGlobalPtr(){return &cavitymodel;}
971 template<> FastList<CavityModel>& Parser::GetList<CavityModel>(){return cavitymodel_list;}
972
973 template<> NewColour& Parser::GetGlobal(){return colour;}
974 template<> NewColour* Parser::GetGlobalPtr(){return &colour;}
975 template<> FastList<NewColour>& Parser::GetList<NewColour>(){return colour_list;}
976
977 template<> CoolingChannel& Parser::GetGlobal(){return coolingchannel;}
978 template<> CoolingChannel* Parser::GetGlobalPtr(){return &coolingchannel;}
979 template<> FastList<CoolingChannel>& Parser::GetList<CoolingChannel>(){return coolingchannel_list;}
980
981 template<> Crystal& Parser::GetGlobal(){return crystal;}
982 template<> Crystal* Parser::GetGlobalPtr(){return &crystal;}
983 template<> FastList<Crystal>& Parser::GetList<Crystal>(){return crystal_list;}
984
985 template<> Field& Parser::GetGlobal(){return field;}
986 template<> Field* Parser::GetGlobalPtr(){return &field;}
987 template<> FastList<Field>& Parser::GetList<Field>(){return field_list;}
988
989
990 template<> Material& Parser::GetGlobal(){return material;}
991 template<> Material* Parser::GetGlobalPtr(){return &material;}
992 template<> FastList<Material>& Parser::GetList<Material>(){return material_list;}
993
994 template<> Laser& Parser::GetGlobal(){return laser;}
995 template<> Laser* Parser::GetGlobalPtr(){return &laser;}
996 template<> FastList<Laser>& Parser::GetList<Laser>(){return laser_list;}
997
998 template<> Modulator& Parser::GetGlobal() {return modulator;}
999 template<> Modulator* Parser::GetGlobalPtr() {return &modulator;}
1000 template<> FastList<Modulator>& Parser::GetList<Modulator>() {return modulator_list;}
1001
1002 template<> Options& Parser::GetGlobal(){return options;}
1003 template<> Options* Parser::GetGlobalPtr(){return &options;}
1004
1005 template<> Parameters& Parser::GetGlobal(){return params;}
1006 template<> Parameters* Parser::GetGlobalPtr(){return &params;}
1007
1008 template<> PhysicsBiasing& Parser::GetGlobal(){return xsecbias;}
1009 template<> PhysicsBiasing* Parser::GetGlobalPtr(){return &xsecbias;}
1010 template<> FastList<PhysicsBiasing>& Parser::GetList<PhysicsBiasing, FastList<PhysicsBiasing>>(){return xsecbias_list;}
1011
1012 template<> Placement& Parser::GetGlobal(){return placement;}
1013 template<> Placement* Parser::GetGlobalPtr(){return &placement;}
1014 template<> FastList<Placement>& Parser::GetList<Placement>(){return placement_list;}
1015
1016 template<> Query& Parser::GetGlobal(){return query;}
1017 template<> Query* Parser::GetGlobalPtr(){return &query;}
1018 template<> FastList<Query>& Parser::GetList<Query>(){return query_list;}
1019
1020 template<> Region& Parser::GetGlobal(){return region;}
1021 template<> Region* Parser::GetGlobalPtr(){return &region;}
1022 template<> FastList<Region>& Parser::GetList<Region>(){return region_list;}
1023
1025 template<> SamplerPlacement* Parser::GetGlobalPtr(){return &samplerplacement;}
1026 template<> FastList<SamplerPlacement>& Parser::GetList<SamplerPlacement>() {return samplerplacement_list;}
1027
1028 template<> Scorer& Parser::GetGlobal(){return scorer;}
1029 template<> Scorer* Parser::GetGlobalPtr(){return &scorer;}
1030 template<> FastList<Scorer>& Parser::GetList<Scorer>() {return scorer_list;}
1031
1032 template<> ScorerMesh& Parser::GetGlobal(){return scorermesh;}
1033 template<> ScorerMesh* Parser::GetGlobalPtr(){return &scorermesh;}
1034 template<> FastList<ScorerMesh>& Parser::GetList<ScorerMesh>() {return scorermesh_list;}
1035
1036 template<> Tunnel& Parser::GetGlobal(){return tunnel;}
1037 template<> Tunnel* Parser::GetGlobalPtr(){return &tunnel;}
1038 template<> FastList<Tunnel>& Parser::GetList<Tunnel>(){return tunnel_list;}
1039
1040
1041 template<>
1042 void Parser::ExtendValue(const std::string& property, double value)
1043 {extendedNumbers[property]=value;}
1044
1045 template<>
1046 void Parser::ExtendValue(const std::string& property, std::string value)
1047 {extendedStrings[property]=value;}
1048
1049 template<>
1050 void Parser::ExtendValue(const std::string& property, Array* value)
1051 {extendedVectors[property]=value;}
1052
1053 template <class C, class Container>
1055 {
1056 // copy from global
1057 C& global = GetGlobal<C>();
1058 C inst(global);
1059 // reset global
1060 global.clear();
1061#ifdef BDSDEBUG
1062 inst.print();
1063#endif
1064 GetList<C, Container>().push_back(inst);
1065 }
1066
1067 template <class C, class Container>
1068 void Parser::Add(bool unique, const std::string& className)
1069 {
1070 // copy from global
1071 C& global = GetGlobal<C>();
1072 C inst(global);
1073 // reset global
1074 global.clear();
1075#ifdef BDSDEBUG
1076 inst.print();
1077#endif
1078 GetList<C, Container>().push_back(inst, unique, className);
1079 }
1080
1087 template <>
1088 void Parser::Add<Placement, FastList<Placement>>(bool unique, const std::string& className)
1089 {
1090 // copy from global
1091 Placement& global = GetGlobal<Placement>();
1092 Placement inst(global);
1093 // reset global
1094 global.clear();
1095#ifdef BDSDEBUG
1096 inst.print();
1097#endif
1098 GetList<Placement, FastList<Placement>>().push_back(inst, unique, className);
1099 // if an element definition is used for a placement, keep a separate copy of it
1100 if (!inst.bdsimElement.empty())
1101 {
1102 const Element* elDef = find_element_safe(inst.bdsimElement);
1103 if (!elDef)
1104 {
1105 std::cerr << "The bdsimElement referred to in \"" << inst.name << "\" (\""
1106 << inst.bdsimElement << "\") cannot be found and should be defined"
1107 << " before this placement" << std::endl;
1108 exit(1);
1109 }
1110 placement_elements.push_back(Element(*elDef));
1111 }
1112 }
1113}
Aperture class.
Definition aperture.h:38
Representation of arrays used in tokens.
Definition array.h:40
void Copy(Container< std::string, std::allocator< std::string > > &cpy)
Copy STL string containers into symbols.
Definition array.h:86
blm for parser.
Beam class.
Definition beam.h:44
RF CavityModel class for parser.
Definition cavitymodel.h:35
Cooling channel parameters.
Crystal class for parser.
Definition crystal.h:37
List with Efficient Lookup.
Definition fastlist.h:42
FastListIterator begin()
Definition fastlist.h:218
FastListIterator insert(FastListInputIterator position, const T &val)
template definitions need to be in header
Definition fastlist.h:118
FastListIterator end()
Definition fastlist.h:223
void clear()
empty lists
Definition fastlist.h:172
void erase()
erase elements
Definition fastlist.h:178
void push_back(const T &el, bool unique=false, const std::string &objectName="element")
Definition fastlist.h:155
FastListConstIterator find(std::string name, unsigned int count=1) const
Definition fastlist.h:257
Field class for parser.
Definition field.h:37
Placement class for laser.
Definition laser.h:36
Modulator class for parser.
Definition modulator.h:37
Colour definition for parser.
Definition newcolour.h:40
void print() const
print some properties
Options class.
Definition options.h:44
Parser class.
Definition parser.h:82
void Overwrite(const std::string &objectName)
Overwrite object with current values.
Definition parser.cc:772
FastList< Atom > atom_list
List of parser defined instances of that object.
Definition parser.h:239
void Add()
Insert global object of parser class C in Container class.
Definition parser.cc:1054
Parser()
Default contructor.
Definition parser.cc:115
std::vector< std::list< Element > * > allocated_lines
Definition parser.h:272
double property_lookup(const std::string &element_name, const std::string &property_name) const
access property of Element with element_name
Definition parser.cc:669
FastList< BLMPlacement > blm_list
List of parser defined instances of that object.
Definition parser.h:256
std::vector< std::string > sequences
Names of all defined sequences in the parser with 'line'.
Definition parser.h:324
void FillString(Array *)
Definition parser.cc:760
const int MAX_EXPAND_ITERATIONS
maximum number of nested lines
Definition parser.h:265
void quit()
Exit method.
Definition parser.cc:302
Laser laser
The one instance we fill before appending to a list.
Definition parser.h:281
Scorer scorer
The one instance we fill before appending to a list.
Definition parser.h:290
void ExtendValue(const std::string &property, T value)
Add value to be extended to object.
void ExtendObject(C &object)
Extend object with maps.
Definition parser.cc:844
FastList< Crystal > crystal_list
List of parser defined instances of that object.
Definition parser.h:241
FastList< Placement > placement_list
List of parser defined instances of that object.
Definition parser.h:249
Material material
The one instance we fill before appending to a list.
Definition parser.h:282
virtual ~Parser()
Destructor.
Definition parser.cc:140
Atom atom
The one instance we fill before appending to a list.
Definition parser.h:276
Symtab * symlook(const std::string &s)
look up parser symbol
Definition parser.cc:740
static Parser * Instance()
Access method.
Definition parser.cc:119
std::map< std::string, FastList< Element > * > expandedSequences
Cached copy of expanded sequences.
Definition parser.h:327
FastList< Region > region_list
List of parser defined instances of that object.
Definition parser.h:246
FastList< Modulator > modulator_list
List of parser defined instances of that object.
Definition parser.h:257
FastList< NewColour > colour_list
List of parser defined instances of that object.
Definition parser.h:240
Parameters params
The one instance we fill before appending to a list.
Definition parser.h:275
int add_sampler_partIDSet(std::list< int > *samplerPartIDListIn)
Definition parser.cc:590
FastList< Scorer > scorer_list
List of parser defined instances of that object.
Definition parser.h:253
FastList< Tunnel > tunnel_list
List of parser defined instances of that object.
Definition parser.h:247
FastList< Element > element_list
List of all encountered elements.
Definition parser.h:313
CoolingChannel coolingchannel
The one instance we fill before appending to a list.
Definition parser.h:279
void add_sampler(const std::string &name, int count, ElementType type, std::string samplerType, std::list< int > *samplerPartIDListIn=nullptr)
insert a sampler into beamline_list
Definition parser.cc:608
C & GetGlobal()
Get global object of parser class C.
int copy_element_to_params(const std::string &elementName)
copy properties from Element into params, returns element type as integer, returs _NONE if not found
Definition parser.cc:700
Crystal crystal
The one instance we fill before appending to a list.
Definition parser.h:278
bool TryPrintingObject(const std::string &objectName) const
Definition parser.cc:874
Options options
General options.
Definition parser.h:235
Element & find_element(const std::string &element_name)
find element
Definition parser.cc:620
FastList< Aperture > aperture_list
List of parser defined instances of that object.
Definition parser.h:255
Modulator modulator
The one instance we fill before appending to a list.
Definition parser.h:294
FastList< CoolingChannel > coolingchannel_list
List of parser defined instances of that object.
Definition parser.h:242
Tunnel tunnel
The one instance we fill before appending to a list.
Definition parser.h:287
void expand_line(FastList< Element > &target, const std::string &name, const std::string &start="", const std::string &end="")
Definition parser.cc:342
FastList< PhysicsBiasing > xsecbias_list
List of parser defined instances of that object.
Definition parser.h:248
void write_table(std::string *name, ElementType type, bool isLine=false)
Method that transfers parameters to element properties.
Definition parser.cc:308
FastList< ScorerMesh > scorermesh_list
List of parser defined instances of that object.
Definition parser.h:254
const Element * find_placement_element_safe(const std::string &element_name) const
search placement_element
Definition parser.cc:645
void PrintElements() const
Print methods.
Definition parser.cc:864
FastList< Element > placement_elements
Definition parser.h:318
std::vector< std::string * > var_list
Variable vector for memory storage.
Definition parser.h:332
FastList< Element > beamline_list
Beamline.
Definition parser.h:237
void add_element_temp(const std::string &name, int number, bool pushfront, ElementType linetype)
add element to temporary element sequence tmp_list
Definition parser.cc:675
std::set< std::set< int > > samplerFilters
Definition parser.h:336
FastList< SamplerPlacement > samplerplacement_list
List of parser defined instances of that object.
Definition parser.h:252
Field field
The one instance we fill before appending to a list.
Definition parser.h:280
std::list< Element > tmp_list
Temporary list.
Definition parser.h:321
Query query
The one instance we fill before appending to a list.
Definition parser.h:285
Aperture aperture
The one instance we fill before appending to a list.
Definition parser.h:292
void AddVariable(std::string *name)
Add variable memory to variable list for memory management.
Definition parser.cc:854
BLMPlacement blm
The one instance we fill before appending to a list.
Definition parser.h:293
std::map< std::string, std::string > extendedStrings
Map for options of type string for extending objects.
Definition parser.h:308
Region region
The one instance we fill before appending to a list.
Definition parser.h:286
void ParseFile(FILE *f)
Parse the input file and construct beamline_list and options.
Definition parser.cc:181
bool FindAndExtend(const std::string &objectName)
Laser instance.
Definition parser.cc:831
SymbolMap symtab_map
Parser symbol map.
Definition parser.h:330
void PrintBeamline() const
Print methods.
Definition parser.cc:859
const FastList< Element > & get_sequence(const std::string &name)
Definition parser.cc:495
std::map< std::string, Array * > extendedVectors
Map for options of type vector for extending objects.
Definition parser.h:310
void set_sampler(const std::string &name, int count, ElementType type, const std::string &samplerType, double samplerRadius=0, int particleSetID=-1)
Set sampler.
Definition parser.cc:505
Symtab * symcreate(const std::string &s)
create new parser symbol
Definition parser.cc:735
NewColour colour
The one instance we fill before appending to a list.
Definition parser.h:277
ScorerMesh scorermesh
The one instance we fill before appending to a list.
Definition parser.h:291
const FastList< Element > & GetBeamline() const
Definition parser.cc:945
void PrintOptions() const
Print methods.
Definition parser.cc:869
void ClearParams()
Definition parser.cc:766
void FillArray(Array *)
Definition parser.cc:754
FastList< Field > field_list
List of parser defined instances of that object.
Definition parser.h:243
FastList< CavityModel > cavitymodel_list
List of parser defined instances of that object.
Definition parser.h:251
std::map< std::string, double > extendedNumbers
Map for options of type double for extending objects.
Definition parser.h:306
Placement placement
The one instance we fill before appending to a list.
Definition parser.h:284
std::list< double > tmparray
temporary list for reading of arrays in parser
Definition parser.h:268
CavityModel cavitymodel
The one instance we fill before appending to a list.
Definition parser.h:288
FastList< Query > query_list
List of parser defined instances of that object.
Definition parser.h:245
void Store(double value)
Add value to front of temporary list.
Definition parser.cc:744
static Parser * instance
Instance.
Definition parser.h:100
PhysicsBiasing xsecbias
The one instance we fill before appending to a list.
Definition parser.h:283
FastList< Laser > laser_list
List of parser defined instances of that object.
Definition parser.h:250
Beam beam
Beam instance;.
Definition parser.h:233
void add_func(std::string name, double(*func)(double))
Add function to parser.
Definition parser.cc:715
void Initialise()
Initialisation of parser functions and constants.
Definition parser.cc:213
FastList< Material > material_list
List of parser defined instances of that object.
Definition parser.h:244
const Element * find_element_safe(const std::string &element_name) const
find element by pointer - nullptr if not found - searches element_list
Definition parser.cc:657
void expand_sequences()
Expand all sequences define with 'line' into FastLists.
Definition parser.cc:325
std::list< std::string > tmpstring
temporary list for reading of arrays in parser
Definition parser.h:269
SamplerPlacement samplerplacement
The one instance we fill before appending to a list.
Definition parser.h:289
Physics biasing class for parser.
Placement class for parser.
Definition placement.h:41
std::string name
Name of this placement.
Definition placement.h:43
void clear()
reset
Definition placement.cc:33
void print() const
print some properties
Definition placement.cc:91
std::string bdsimElement
Name of bdsim-built component to place instead of piece of geometry.
Definition placement.h:45
Query structure class for parser.
Definition query.h:37
Region class for parser.
Definition region.h:36
Sampler placement class for parser.
ScorerMesh class for parser.
Definition scorermesh.h:40
Scorer class for parser.
Definition scorer.h:37
void clear()
Destructor that clears memory.
Definition symbolmap.cc:48
Symtab * symlook(std::string s)
Look up parser symbol.
Definition symbolmap.cc:42
Symtab * symcreate(std::string s)
Create new parser symbol.
Definition symbolmap.cc:28
Common header for the lexer and the parser to share Symbol table for numeric variables,...
Definition sym_table.h:33
void Set(Array *)
Set to Array value.
Definition sym_table.cc:37
Tunnel class for parser.
Definition tunnel.h:35
Parser namespace for GMAD language. Combination of Geant4 and MAD.
ElementType
types of elements
Definition elementtype.h:28
Atom class.
Definition atom.h:36
Element class.
Definition element.h:45
double property_lookup(std::string property_name) const
Definition element.cc:720
void set(const Parameters &params)
set method from Parameters structure
Definition element.cc:748
std::list< Element > * lst
in case the element is a list itself (line)
Definition element.h:286
double l
length in metres
Definition element.h:51
ElementType type
element enum
Definition element.h:46
Material class.
Definition material.h:39
Parameters - Element class with booleans.
Definition parameters.h:44
void inherit_properties(const Element &e)
void flush()
Reset the parameters to defaults and setMap.