BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
atom.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 ATOM_H
19#define ATOM_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24
25#include "published.h"
26
27namespace GMAD
28{
35 struct Atom : public Published<Atom>{
37 std::string name;
38
39 double A;
40 double Z;
41 std::string symbol;
42
44 Atom();
46 void clear();
48 void print()const;
50 template <typename T>
51 void set_value(std::string property, T value, bool bExit = false);
52
53 private:
55 void PublishMembers();
56 };
57
58 template <typename T>
59 void Atom::set_value(std::string property, T value, bool bExit )
60 {
61#ifdef BDSDEBUG
62 std::cout << "parser> Setting value " << std::setw(25) << std::left << property << value << std::endl;
63#endif
64 // member method can throw runtime_error, catch and exit gracefully
65 try
66 {set(this,property,value);}
67 catch(const std::runtime_error&)
68 {
69 std::cerr << "Error: parser> unknown atom option \"" << property << "\" with value \"" << value << "\"" << std::endl;
70 if(bExit)
71 {exit(1);}
72 else
73 {std::rethrow_exception(std::current_exception());}
74 }
75 }
76}
77
78#endif
Class that provides introspection to its members.
Definition published.h:48
void set(Atom *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.
Atom class.
Definition atom.h:35
double A
g*mol^-1
Definition atom.h:39
void set_value(std::string property, T value, bool bExit=false)
set methods by property name and value
Definition atom.h:59
void print() const
printout
Definition atom.cc:44
void clear()
reset
Definition atom.cc:28
Atom()
constructor
Definition atom.cc:22
std::string name
name
Definition atom.h:37
void PublishMembers()
publish members so these can be looked up from parser
Definition atom.cc:36