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) Royal Holloway,
3University of London 2001 - 2023.
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 BDSMAGNETSTRENGTH_H
20#define BDSMAGNETSTRENGTH_H
21
22#include "globals.hh" // geant4 globals / types
23
24#include <map>
25#include <ostream>
26#include <vector>
27
45{
46private:
48 typedef std::map<G4String, G4double> StrengthMap;
49
54
55public:
58
60 explicit BDSMagnetStrength(const std::map<G4String, G4double>& keyvalues);
61
63
65 friend std::ostream& operator<< (std::ostream &out, BDSMagnetStrength const &st);
66
70 std::ostream& WriteValuesInSIUnitsForSuvey(std::ostream& out,
71 const G4int precision = 14) const;
72
75 {
76 G4String unit;
77 G4double factor;
78 };
79
81 G4double& operator[](const G4String& key);
82 const G4double& operator[](const G4String& key) const;
83 const G4double& at(const G4String& key) const {return (*this)[key];}
84
86 static const std::vector<G4String>& AllKeys() {return keys;}
87
89 static G4bool ValidKey(const G4String& key);
90
92 static const std::map<G4String, unitsFactors>& UnitsAndFactors() {return unitsFactorsMap;}
93
95 static inline std::vector<G4String> NormalComponentKeys() {return normalComponentKeys;}
96
98 static inline std::vector<G4String> SkewComponentKeys() {return skewComponentKeys;}
99
101 std::vector<G4double> NormalComponents() const;
102
104 std::vector<G4double> SkewComponents() const;
105
107 static G4String UnitName(const G4String& key);
108
110 static G4double Unit(const G4String& key);
111
113 G4bool KeyHasBeenSet(const G4String& key) const;
114
116 typedef StrengthMap::iterator iterator;
117 typedef StrengthMap::const_iterator const_iterator;
118 iterator begin() {return strengths.begin();}
119 iterator end() {return strengths.end();}
120 const_iterator begin() const {return strengths.begin();}
121 const_iterator end() const {return strengths.end();}
122 G4bool empty() const {return strengths.empty();}
124
125private:
128 const G4double& GetValue(const G4String& key) const;
129
131 static const std::vector<G4String> keys;
132
134 static const std::map<G4String, unitsFactors> unitsFactorsMap;
135
137 static const std::vector<G4String> normalComponentKeys;
138
140 static const std::vector<G4String> skewComponentKeys;
141
143 static const G4double zero;
144
146 static G4double variable;
147};
148
149
150#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).