BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
beam.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 BEAM_H
19#define BEAM_H
20
21#include <iomanip>
22#include <iostream>
23#include <string>
24#include <vector>
25
26#include "published.h"
27#include "beamBase.h"
28
29namespace GMAD
30{
42 class Beam: public Published<BeamBase>, public BeamBase
43 {
44 public:
45 Beam();
46 explicit Beam(const GMAD::BeamBase& options);
47
49 void print() const;
50
52 template<typename T>
53 void set_value(std::string name, T value, bool bExit = true);
54
56 double get_value(std::string name) const;
57
58 std::string get_value_string(std::string property_name) const;
59
65 void Amalgamate(const Beam& optionsIn, bool override, int startFromEvent = 0);
66
68 bool HasBeenSet(const std::string& name) const;
69
70 inline const std::vector<std::string>& KeysOfSetValues() const {return setKeys;}
71
72 private:
74 void PublishMembers();
75 };
76
77 template<typename T>
78 void Beam::set_value(std::string name, T value, bool bExit)
79 {
80#ifdef BDSDEBUG
81 std::cout << "beam> setting value " << std::setw(25) << std::left << name << value << std::endl;
82#endif
83 // member method can throw runtime_error, catch and exit gracefully
84 try
85 {
86 set(this, name, value);
87 setKeys.push_back(name);
88 }
89 catch (const std::runtime_error&)
90 {
91 std::cerr << "Error: beam> unknown beam parameter \"" << name << "\" with value \"" << value << "\"" << std::endl;
92 if(bExit)
93 {exit(1);}
94 else
95 {std::rethrow_exception(std::current_exception());}
96 }
97 }
98}
99
100#endif
Options for a beam distribution.
Definition beamBase.h:34
std::vector< std::string > setKeys
A list of all the keys that have been set in this instance.
Definition beamBase.h:174
Beam class.
Definition beam.h:43
void PublishMembers()
publish members so these can be looked up from parser
Definition beam.cc:150
void print() const
Print some properties.
Definition beam.cc:350
double get_value(std::string name) const
get method (only for doubles)
Definition beam.cc:38
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
Definition beam.cc:96
bool HasBeenSet(const std::string &name) const
Whether a parameter has been set using the set_value method or not.
Definition beam.cc:141
void set_value(std::string name, T value, bool bExit=true)
set methods by property name
Definition beam.h:78
Class that provides introspection to its members.
Definition published.h:48
void set(BeamBase *instance, const std::string &name, double value)
Definition published.h:100
Parser namespace for GMAD language. Combination of Geant4 and MAD.