BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Data Structures | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
BDSMagnetStrength Class Reference

Efficient storage of magnet strengths. More...

#include <BDSMagnetStrength.hh>

Collaboration diagram for BDSMagnetStrength:
Collaboration graph

Data Structures

struct  unitsFactors
 Structure for unit names and numerical factors from Geant4 to SI(ish). More...
 

Public Member Functions

 BDSMagnetStrength ()
 Default constructor does nothing as class will return 0 for uninitialised keys. More...
 
 BDSMagnetStrength (const std::map< G4String, G4double > &keyvalues)
 This constructor allows instantiation with a map of keys and values. More...
 
std::ostream & WriteValuesInSIUnitsForSuvey (std::ostream &out, const G4int precision=14) const
 
G4double & operator[] (const G4String &key)
 Accessors with array / map [] operator. More...
 
const G4double & operator[] (const G4String &key) const
 
const G4double & at (const G4String &key) const
 
std::vector< G4double > NormalComponents () const
 Accessor for all normal components - k1 - k12. More...
 
std::vector< G4double > SkewComponents () const
 Accessor for all skew components - k1 - k12. More...
 
G4bool KeyHasBeenSet (const G4String &key) const
 Whether a key has been set. More...
 

Static Public Member Functions

static const std::vector< G4String > & AllKeys ()
 Accessor to all keys. More...
 
static G4bool ValidKey (const G4String &key)
 Whether or not the supplied key is a valid magnet strength parameter. More...
 
static const std::map< G4String, unitsFactors > & UnitsAndFactors ()
 Accessor to all units. More...
 
static std::vector< G4String > NormalComponentKeys ()
 Accessor for normal component keys - k1 - k12. More...
 
static std::vector< G4String > SkewComponentKeys ()
 Accessor for skew component keys - k1 - k12. More...
 
static G4String UnitName (const G4String &key)
 Access a unit name for a given key. More...
 
static G4double Unit (const G4String &key)
 Access a unit factor for a given key. More...
 

Private Types

typedef std::map< G4String, G4double > StrengthMap
 Typedefs up first so we can declare public iterators. More...
 

Private Member Functions

const G4double & GetValue (const G4String &key) const
 

Private Attributes

StrengthMap strengths
 

Static Private Attributes

static const std::vector< G4String > keys
 Vector of the allowed strength parameters. More...
 
static const std::map< G4String, unitsFactorsunitsFactorsMap
 Map of each unit name and numerical factor to each key. More...
 
static const std::vector< G4String > normalComponentKeys
 Vector of the normal component strength parameters. More...
 
static const std::vector< G4String > skewComponentKeys
 Vector of the normal component strength parameters. More...
 
static const G4double zero = 0.0
 Keep a single copy of 0.0 as it needs to be returned as a reference not a value. More...
 
static G4double variable = 0.0
 Dummy variable that can be overwritten. More...
 

Friends

std::ostream & operator<< (std::ostream &out, BDSMagnetStrength const &st)
 Output stream. More...
 
typedef StrengthMap::iterator iterator
 Iterator mechanics. More...
 
typedef StrengthMap::const_iterator const_iterator
 Iterator mechanics. More...
 
iterator begin ()
 Iterator mechanics. More...
 
iterator end ()
 Iterator mechanics. More...
 
const_iterator begin () const
 Iterator mechanics. More...
 
const_iterator end () const
 Iterator mechanics. More...
 
G4bool empty () const
 Iterator mechanics. More...
 

Detailed Description

Efficient storage of magnet strengths.

Based on std::map, this class stores magnet strengths.

As there will be one of these for every magnet and they may in future have to go up to high order normal plus skew (~40 doubles), it is more efficient to only store the required parameters. A pure quadrupole has no need of k20s, but a multipole may do. A static vector contains the possible magnet strength parameters that can be checked against. If a parameter is not specified in the map, its value is return as 0.

Angle in rad, Field in Geant4 units. k strengths as original (ie not converted to G4).

Author
Laurie Nevay

Definition at line 45 of file BDSMagnetStrength.hh.

Member Typedef Documentation

◆ const_iterator

typedef StrengthMap::const_iterator BDSMagnetStrength::const_iterator

Iterator mechanics.

Definition at line 118 of file BDSMagnetStrength.hh.

◆ iterator

typedef StrengthMap::iterator BDSMagnetStrength::iterator

Iterator mechanics.

Definition at line 117 of file BDSMagnetStrength.hh.

◆ StrengthMap

typedef std::map<G4String, G4double> BDSMagnetStrength::StrengthMap
private

Typedefs up first so we can declare public iterators.

Definition at line 49 of file BDSMagnetStrength.hh.

Constructor & Destructor Documentation

◆ BDSMagnetStrength() [1/2]

BDSMagnetStrength::BDSMagnetStrength ( )
inline

Default constructor does nothing as class will return 0 for uninitialised keys.

Definition at line 58 of file BDSMagnetStrength.hh.

◆ BDSMagnetStrength() [2/2]

BDSMagnetStrength::BDSMagnetStrength ( const std::map< G4String, G4double > &  keyvalues)
explicit

This constructor allows instantiation with a map of keys and values.

Definition at line 173 of file BDSMagnetStrength.cc.

References ValidKey().

Here is the call graph for this function:

◆ ~BDSMagnetStrength()

BDSMagnetStrength::~BDSMagnetStrength ( )
inline

Definition at line 63 of file BDSMagnetStrength.hh.

Member Function Documentation

◆ AllKeys()

static const std::vector< G4String > & BDSMagnetStrength::AllKeys ( )
inlinestatic

Accessor to all keys.

Definition at line 87 of file BDSMagnetStrength.hh.

References keys.

Referenced by BDSFieldFactory::PrepareFieldStrengthFromParameters().

Here is the caller graph for this function:

◆ at()

const G4double & BDSMagnetStrength::at ( const G4String &  key) const
inline

Definition at line 84 of file BDSMagnetStrength.hh.

◆ begin() [1/2]

iterator BDSMagnetStrength::begin ( )
inline

Iterator mechanics.

Definition at line 119 of file BDSMagnetStrength.hh.

References strengths.

◆ begin() [2/2]

const_iterator BDSMagnetStrength::begin ( ) const
inline

Iterator mechanics.

Definition at line 121 of file BDSMagnetStrength.hh.

References strengths.

◆ empty()

G4bool BDSMagnetStrength::empty ( ) const
inline

Iterator mechanics.

Definition at line 123 of file BDSMagnetStrength.hh.

References strengths.

◆ end() [1/2]

iterator BDSMagnetStrength::end ( )
inline

Iterator mechanics.

Definition at line 120 of file BDSMagnetStrength.hh.

References strengths.

◆ end() [2/2]

const_iterator BDSMagnetStrength::end ( ) const
inline

Iterator mechanics.

Definition at line 122 of file BDSMagnetStrength.hh.

References strengths.

◆ GetValue()

const G4double & BDSMagnetStrength::GetValue ( const G4String &  key) const
private

Accessor similar to [] but without linear search through keys to check validity. for fast internal use.

Definition at line 266 of file BDSMagnetStrength.cc.

References strengths, and zero.

Referenced by NormalComponents(), SkewComponents(), and WriteValuesInSIUnitsForSuvey().

Here is the caller graph for this function:

◆ KeyHasBeenSet()

G4bool BDSMagnetStrength::KeyHasBeenSet ( const G4String &  key) const

Whether a key has been set.

Definition at line 275 of file BDSMagnetStrength.cc.

References strengths.

Referenced by BDSFieldFactory::GetOuterScaling().

Here is the caller graph for this function:

◆ NormalComponentKeys()

static std::vector< G4String > BDSMagnetStrength::NormalComponentKeys ( )
inlinestatic

Accessor for normal component keys - k1 - k12.

Definition at line 96 of file BDSMagnetStrength.hh.

References normalComponentKeys.

Referenced by BDSComponentFactory::PrepareMagnetStrengthForMultipoles().

Here is the caller graph for this function:

◆ NormalComponents()

std::vector< G4double > BDSMagnetStrength::NormalComponents ( ) const

Accessor for all normal components - k1 - k12.

Definition at line 240 of file BDSMagnetStrength.cc.

References GetValue(), and normalComponentKeys.

Referenced by BDSOutputROOTEventModel::Fill().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator[]() [1/2]

G4double & BDSMagnetStrength::operator[] ( const G4String &  key)

Accessors with array / map [] operator.

Definition at line 213 of file BDSMagnetStrength.cc.

References strengths, and ValidKey().

Here is the call graph for this function:

◆ operator[]() [2/2]

const G4double & BDSMagnetStrength::operator[] ( const G4String &  key) const

Definition at line 232 of file BDSMagnetStrength.cc.

◆ SkewComponentKeys()

static std::vector< G4String > BDSMagnetStrength::SkewComponentKeys ( )
inlinestatic

Accessor for skew component keys - k1 - k12.

Definition at line 99 of file BDSMagnetStrength.hh.

References skewComponentKeys.

Referenced by BDSComponentFactory::PrepareMagnetStrengthForMultipoles().

Here is the caller graph for this function:

◆ SkewComponents()

std::vector< G4double > BDSMagnetStrength::SkewComponents ( ) const

Accessor for all skew components - k1 - k12.

Definition at line 249 of file BDSMagnetStrength.cc.

References GetValue(), and skewComponentKeys.

Referenced by BDSOutputROOTEventModel::Fill().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unit()

G4double BDSMagnetStrength::Unit ( const G4String &  key)
static

Access a unit factor for a given key.

Definition at line 205 of file BDSMagnetStrength.cc.

References unitsFactorsMap, and ValidKey().

Referenced by BDSOutputROOTEventModel::Fill(), and BDSFieldFactory::PrepareFieldStrengthFromParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnitName()

G4String BDSMagnetStrength::UnitName ( const G4String &  key)
static

Access a unit name for a given key.

Definition at line 197 of file BDSMagnetStrength.cc.

References unitsFactorsMap, and ValidKey().

Referenced by BDSSurvey::WriteHeader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnitsAndFactors()

static const std::map< G4String, unitsFactors > & BDSMagnetStrength::UnitsAndFactors ( )
inlinestatic

Accessor to all units.

Definition at line 93 of file BDSMagnetStrength.hh.

References unitsFactorsMap.

◆ ValidKey()

G4bool BDSMagnetStrength::ValidKey ( const G4String &  key)
static

Whether or not the supplied key is a valid magnet strength parameter.

Definition at line 258 of file BDSMagnetStrength.cc.

References keys.

Referenced by BDSMagnetStrength(), operator[](), BDSFieldFactory::PrepareFieldStrengthFromParameters(), Unit(), and UnitName().

Here is the caller graph for this function:

◆ WriteValuesInSIUnitsForSuvey()

std::ostream & BDSMagnetStrength::WriteValuesInSIUnitsForSuvey ( std::ostream &  out,
const G4int  precision = 14 
) const

Print out each magnet strength value in order according to keys multiplied by the correct factors to return to the units on the input side of BDSIM rather than the Geant4 ones used internally.

Definition at line 189 of file BDSMagnetStrength.cc.

References GetValue(), keys, and unitsFactorsMap.

Referenced by BDSSurvey::Write().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
BDSMagnetStrength const &  st 
)
friend

Output stream.

Definition at line 182 of file BDSMagnetStrength.cc.

Field Documentation

◆ keys

const std::vector< G4String > BDSMagnetStrength::keys
staticprivate

Vector of the allowed strength parameters.

Definition at line 132 of file BDSMagnetStrength.hh.

Referenced by AllKeys(), ValidKey(), and WriteValuesInSIUnitsForSuvey().

◆ normalComponentKeys

const std::vector< G4String > BDSMagnetStrength::normalComponentKeys
staticprivate
Initial value:
= {
"k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9", "k10", "k11", "k12"}

Vector of the normal component strength parameters.

Definition at line 138 of file BDSMagnetStrength.hh.

Referenced by NormalComponentKeys(), and NormalComponents().

◆ skewComponentKeys

const std::vector< G4String > BDSMagnetStrength::skewComponentKeys
staticprivate
Initial value:
= {
"k1s", "k2s", "k3s", "k4s", "k5s", "k6s", "k7s", "k8s", "k9s", "k10s", "k11s", "k12s"}

Vector of the normal component strength parameters.

Definition at line 141 of file BDSMagnetStrength.hh.

Referenced by SkewComponentKeys(), and SkewComponents().

◆ strengths

StrengthMap BDSMagnetStrength::strengths
private

A map containing the values for various magnet strengths. It only contains the set magnet strengths. If a strength isn't specified, it's assumed to be zero without having to store the 0 value.

Definition at line 54 of file BDSMagnetStrength.hh.

Referenced by begin(), empty(), end(), GetValue(), KeyHasBeenSet(), and operator[]().

◆ unitsFactorsMap

const std::map< G4String, BDSMagnetStrength::unitsFactors > BDSMagnetStrength::unitsFactorsMap
staticprivate

Map of each unit name and numerical factor to each key.

Definition at line 135 of file BDSMagnetStrength.hh.

Referenced by Unit(), UnitName(), UnitsAndFactors(), and WriteValuesInSIUnitsForSuvey().

◆ variable

G4double BDSMagnetStrength::variable = 0.0
staticprivate

Dummy variable that can be overwritten.

Definition at line 147 of file BDSMagnetStrength.hh.

◆ zero

const G4double BDSMagnetStrength::zero = 0.0
staticprivate

Keep a single copy of 0.0 as it needs to be returned as a reference not a value.

Definition at line 144 of file BDSMagnetStrength.hh.

Referenced by GetValue().


The documentation for this class was generated from the following files: