BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSMagnetStrength.hh
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 BDSMAGNETSTRENGTH_H
19#define BDSMAGNETSTRENGTH_H
20
21#include "globals.hh" // geant4 globals / types
22
23#include <map>
24#include <ostream>
25#include <vector>
26
44{
45private:
47 typedef std::map<G4String, G4double> StrengthMap;
48
53
54public:
57
59 explicit BDSMagnetStrength(const std::map<G4String, G4double>& keyvalues);
60
62
64 friend std::ostream& operator<< (std::ostream &out, BDSMagnetStrength const &st);
65
69 std::ostream& WriteValuesInSIUnitsForSuvey(std::ostream& out,
70 const G4int precision = 14) const;
71
74 {
75 G4String unit;
76 G4double factor;
77 };
78
80 G4double& operator[](const G4String& key);
81 const G4double& operator[](const G4String& key) const;
82 const G4double& at(const G4String& key) const {return (*this)[key];}
83
85 static const std::vector<G4String>& AllKeys() {return keys;}
86
88 static G4bool ValidKey(const G4String& key);
89
91 static const std::map<G4String, unitsFactors>& UnitsAndFactors() {return unitsFactorsMap;}
92
94 static inline std::vector<G4String> NormalComponentKeys() {return normalComponentKeys;}
95
97 static inline std::vector<G4String> SkewComponentKeys() {return skewComponentKeys;}
98
100 std::vector<G4double> NormalComponents() const;
101
103 std::vector<G4double> SkewComponents() const;
104
106 static G4String UnitName(const G4String& key);
107
109 static G4double Unit(const G4String& key);
110
112 G4bool KeyHasBeenSet(const G4String& key) const;
113
115 typedef StrengthMap::iterator iterator;
116 typedef StrengthMap::const_iterator const_iterator;
117 iterator begin() {return strengths.begin();}
118 iterator end() {return strengths.end();}
119 const_iterator begin() const {return strengths.begin();}
120 const_iterator end() const {return strengths.end();}
121 G4bool empty() const {return strengths.empty();}
123
124private:
127 const G4double& GetValue(const G4String& key) const;
128
130 static const std::vector<G4String> keys;
131
133 static const std::map<G4String, unitsFactors> unitsFactorsMap;
134
136 static const std::vector<G4String> normalComponentKeys;
137
139 static const std::vector<G4String> skewComponentKeys;
140
142 static const G4double zero;
143
145 static G4double variable;
146};
147
148
149#endif
Efficient storage of magnet strengths.
std::vector< G4double > NormalComponents() const
Accessor for all normal components - k1 - k12.
std::vector< G4double > SkewComponents() const
Accessor for all skew components - k1 - k12.
std::map< G4String, G4double > StrengthMap
Typedefs up first so we can declare public iterators.
G4bool KeyHasBeenSet(const G4String &key) const
Whether a key has been set.
std::ostream & WriteValuesInSIUnitsForSuvey(std::ostream &out, const G4int precision=14) const
static G4double variable
Dummy variable that can be overwritten.
static G4bool ValidKey(const G4String &key)
Whether or not the supplied key is a valid magnet strength parameter.
static std::vector< G4String > SkewComponentKeys()
Accessor for skew component keys - k1 - k12.
const G4double & GetValue(const G4String &key) const
G4double & operator[](const G4String &key)
Accessors with array / map [] operator.
static const std::vector< G4String > keys
Vector of the allowed strength parameters.
static const std::map< G4String, unitsFactors > & UnitsAndFactors()
Accessor to all units.
friend std::ostream & operator<<(std::ostream &out, BDSMagnetStrength const &st)
Output stream.
static const std::vector< G4String > & AllKeys()
Accessor to all keys.
BDSMagnetStrength()
Default constructor does nothing as class will return 0 for uninitialised keys.
const_iterator end() const
Iterator mechanics.
G4bool empty() const
Iterator mechanics.
iterator end()
Iterator mechanics.
static const G4double zero
Keep a single copy of 0.0 as it needs to be returned as a reference not a value.
static const std::vector< G4String > skewComponentKeys
Vector of the normal component strength parameters.
const_iterator begin() const
Iterator mechanics.
static const std::map< G4String, unitsFactors > unitsFactorsMap
Map of each unit name and numerical factor to each key.
static G4String UnitName(const G4String &key)
Access a unit name for a given key.
StrengthMap::const_iterator const_iterator
Iterator mechanics.
static G4double Unit(const G4String &key)
Access a unit factor for a given key.
iterator begin()
Iterator mechanics.
static std::vector< G4String > NormalComponentKeys()
Accessor for normal component keys - k1 - k12.
StrengthMap::iterator iterator
Iterator mechanics.
static const std::vector< G4String > normalComponentKeys
Vector of the normal component strength parameters.
Structure for unit names and numerical factors from Geant4 to SI(ish).