gfields
Loading...
Searching...
No Matches
gmagneto.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include "gfield.h"
5#include "gfield_options.h"
6#include "gfieldConventions.h"
7
36class GMagneto : public GBase<GMagneto> {
37public:
48 explicit GMagneto(const std::shared_ptr<GOptions>& gopts);
49
50private:
51 using gFieldMap = std::unordered_map<std::string, std::shared_ptr<GField>>;
52 using gFieldMgrMap = std::unordered_map<std::string, std::shared_ptr<G4FieldManager>>;
53
55 std::shared_ptr<gFieldMap> fields_map;
56
58 std::shared_ptr<gFieldMgrMap> fields_manager;
59
60public:
66 bool isField(const std::string& name) const { return fields_map->find(name) != fields_map->end(); }
67
75 std::shared_ptr<GField> getField(std::string name) {
76 bool not_found = (fields_map->find(name) == fields_map->end());
77
78 if (not_found) { log->error(ERR_WRONG_FIELD_NOT_FOUND, "GField >", name, "< not found. Exiting."); }
79 return fields_map->at(name);
80 }
81
89 std::shared_ptr<G4FieldManager> getFieldMgr(std::string name) {
90
91 // Debug visibility: print out the full map of registered field managers.
92 for (const auto& [key, value] : *fields_manager) {
93 log->info(2, "GFieldManager >", key, "< >", value);
94 }
95
96 if (fields_manager->find(name) == fields_manager->end()) { log->error(ERR_WRONG_FIELD_NOT_FOUND, "GField >", name, "< not found. Exiting."); }
97
98 return fields_manager->at(name);
99 }
100};
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
Manager for magnetic fields and their associated G4FieldManager objects.
Definition gmagneto.h:36
std::shared_ptr< G4FieldManager > getFieldMgr(std::string name)
Retrieve the G4FieldManager associated with a given field name.
Definition gmagneto.h:89
std::shared_ptr< GField > getField(std::string name)
Retrieve a field object by name.
Definition gmagneto.h:75
bool isField(const std::string &name) const
Check whether a field with the given name exists.
Definition gmagneto.h:66
GMagneto(const std::shared_ptr< GOptions > &gopts)
Construct and initialize the magnetic field registry.
Definition gmagneto.cc:12
#define ERR_WRONG_FIELD_NOT_FOUND