LDMX Software
MagneticFieldStore.h
Go to the documentation of this file.
1
7#ifndef SIMCORE_MAGNETICFIELDSTORE_H_
8#define SIMCORE_MAGNETICFIELDSTORE_H_
9
10// Geant4
11#include "G4MagneticField.hh"
12
13namespace simcore {
14
20 public:
24 typedef std::map<std::string, G4MagneticField*> MagFieldMap;
25
31 static MagneticFieldStore INSTANCE;
32 return &INSTANCE;
33 }
34
41 for (auto& nameField : magFields_) {
42 delete nameField.second;
43 }
44 magFields_.clear();
45 }
46
51 G4MagneticField* getMagneticField(const std::string& name) {
52 return magFields_.at(name);
53 }
54
60 void addMagneticField(const std::string& name, G4MagneticField* magField) {
61 magFields_[name] = magField;
62 }
63
64 private:
69};
70
71} // namespace simcore
72
73#endif
Global store to access magnetic field objects.
std::map< std::string, G4MagneticField * > MagFieldMap
Map of names to magnetic fields.
MagFieldMap magFields_
Map of names to magnetic fields.
static MagneticFieldStore * getInstance()
Get the global instance of the magnetic field store.
G4MagneticField * getMagneticField(const std::string &name)
Get a magnetic field by name.
void addMagneticField(const std::string &name, G4MagneticField *magField)
Add a magnetic field by name.