BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
beam.h
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 BEAM_H
20#define BEAM_H
21
22#include <iomanip>
23#include <iostream>
24#include <string>
25#include <vector>
26
27#include "published.h"
28#include "beamBase.h"
29
30namespace GMAD
31{
43 class Beam: public Published<BeamBase>, public BeamBase
44 {
45 public:
46 Beam();
47 explicit Beam(const GMAD::BeamBase& options);
48
50 template<typename T>
51 void set_value(std::string name, T value);
52
54 double get_value(std::string name) const;
55
56 std::string get_value_string(std::string property_name) const;
57
63 void Amalgamate(const Beam& optionsIn, bool override, int startFromEvent = 0);
64
66 bool HasBeenSet(const std::string& name) const;
67
68 inline const std::vector<std::string>& KeysOfSetValues() const {return setKeys;}
69
70 private:
72 void PublishMembers();
73 };
74
75 template<typename T>
76 void Beam::set_value(std::string name, T value)
77 {
78#ifdef BDSDEBUG
79 std::cout << "beam> setting value " << std::setw(25) << std::left << name << value << std::endl;
80#endif
81 // member method can throw runtime_error, catch and exit gracefully
82 try
83 {
84 set(this, name, value);
85 setKeys.push_back(name);
86 }
87 catch (const std::runtime_error&)
88 {
89 std::cerr << "Error: beam> unknown beam parameter \"" << name << "\" with value " << value << std::endl;
90 exit(1);
91 }
92 }
93}
94
95#endif
Options for a beam distribution.
Definition: beamBase.h:35
std::vector< std::string > setKeys
A list of all the keys that have been set in this instance.
Definition: beamBase.h:157
Beam class.
Definition: beam.h:44
void PublishMembers()
publish members so these can be looked up from parser
Definition: beam.cc:151
double get_value(std::string name) const
get method (only for doubles)
Definition: beam.cc:39
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
Definition: beam.cc:97
void set_value(std::string name, T value)
set methods by property name
Definition: beam.h:76
bool HasBeenSet(const std::string &name) const
Whether a parameter has been set using the set_value method or not.
Definition: beam.cc:142
Class that provides introspection to its members.
Definition: published.h:47
void set(BeamBase *instance, const std::string &name, double value)
Definition: published.h:99
Parser namespace for GMAD language. Combination of Geant4 and MAD.