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