BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSMagnetStrength.hh
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 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
46{
47private:
49 typedef std::map<G4String, G4double> StrengthMap;
50
55
56public:
59
61 explicit BDSMagnetStrength(const std::map<G4String, G4double>& keyvalues);
62
64
66 friend std::ostream& operator<< (std::ostream &out, BDSMagnetStrength const &st);
67
71 std::ostream& WriteValuesInSIUnitsForSuvey(std::ostream& out,
72 const G4int precision = 14) const;
73
76 {
77 G4String unit;
78 G4double factor;
79 };
80
82 G4double& operator[](const G4String& key);
83 const G4double& operator[](const G4String& key) const;
84 const G4double& at(const G4String& key) const {return (*this)[key];}
85
87 static const std::vector<G4String>& AllKeys() {return keys;}
88
90 static G4bool ValidKey(const G4String& key);
91
93 static const std::map<G4String, unitsFactors>& UnitsAndFactors() {return unitsFactorsMap;}
94
96 static inline std::vector<G4String> NormalComponentKeys() {return normalComponentKeys;}
97
99 static inline std::vector<G4String> SkewComponentKeys() {return skewComponentKeys;}
100
102 std::vector<G4double> NormalComponents() const;
103
105 std::vector<G4double> SkewComponents() const;
106
108 static G4String UnitName(const G4String& key);
109
111 static G4double Unit(const G4String& key);
112
114 G4bool KeyHasBeenSet(const G4String& key) const;
115
117 typedef StrengthMap::iterator iterator;
118 typedef StrengthMap::const_iterator const_iterator;
119 iterator begin() {return strengths.begin();}
120 iterator end() {return strengths.end();}
121 const_iterator begin() const {return strengths.begin();}
122 const_iterator end() const {return strengths.end();}
123 G4bool empty() const {return strengths.empty();}
125
126private:
129 const G4double& GetValue(const G4String& key) const;
130
132 static const std::vector<G4String> keys;
133
135 static const std::map<G4String, unitsFactors> unitsFactorsMap;
136
138 static const std::vector<G4String> normalComponentKeys;
139
141 static const std::vector<G4String> skewComponentKeys;
142
144 static const G4double zero;
145
147 static G4double variable;
148};
149
150
151#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).