gfields
gmagneto.h
Go to the documentation of this file.
1 #ifndef GMAGNETO_H
2 #define GMAGNETO_H 1
3 
4 // gemc
5 #include "gfield.h"
6 #include "gfieldOptions.h"
7 #include "gStateMessage.h"
8 
15 class GMagneto : public GStateMessage {
16 public:
21  GMagneto(GOptions *gopts);
22 
27  delete gFieldMap;
28  delete gFieldMgrMap;
29  }
30 
31 private:
32 
33  std::map<std::string, GField *> *gFieldMap;
34  std::map<std::string, G4FieldManager *> *gFieldMgrMap;
35 
36 public:
37 
43  bool isField(std::string name) {
44  return gFieldMap->find(name) != gFieldMap->end();
45  }
46 
47 
54  GField *getField(std::string name) {
55  bool not_found = (gFieldMap->find(name) == gFieldMap->end());
56 
57  if (not_found) {
58  logError("GField " + name + " not found.", EC__WRONG_FIELD_NOT_FOUND);
59  }
60  return gFieldMap->at(name);
61  }
62 
69  G4FieldManager *getFieldMgr(std::string name) {
70  if (gFieldMgrMap->find(name) == gFieldMgrMap->end()) {
71  logError("G4FieldManager " + name + " not found.", EC__WRONG_FIELD_NOT_FOUND);
72  }
73 
74  return gFieldMgrMap->at(name);
75  }
76 
77 };
78 
79 
80 #endif
Abstract base class representing a magnetic field.
Definition: gfield.h:69
Represents a world containing collections of GFields and G4FieldManagers.
Definition: gmagneto.h:15
~GMagneto()
Destructor to clean up dynamically allocated memory.
Definition: gmagneto.h:26
G4FieldManager * getFieldMgr(std::string name)
Retrieves a G4FieldManager object by its name.
Definition: gmagneto.h:69
GField * getField(std::string name)
Retrieves a GField object by its name.
Definition: gmagneto.h:54
bool isField(std::string name)
Checks if a field with the given name exists.
Definition: gmagneto.h:43
GMagneto(GOptions *gopts)
Constructs a GMagneto object and loads field definitions from options.
Definition: gmagneto.cc:9
#define EC__WRONG_FIELD_NOT_FOUND