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
37class GMagneto : public GBase<GMagneto> {
38public:
49 explicit GMagneto(const std::shared_ptr<GOptions>& gopts);
50
51private:
52 using gFieldMap = std::unordered_map<std::string, std::shared_ptr<GField>>;
53 using gFieldMgrMap = std::unordered_map<std::string, std::shared_ptr<G4FieldManager>>;
54
56 std::shared_ptr<gFieldMap> fields_map;
57
59 std::shared_ptr<gFieldMgrMap> fields_manager;
60
61public:
67 bool isField(const std::string& name) const { return fields_map->find(name) != fields_map->end(); }
68
73 std::vector<std::string> getFieldNames() const;
74
82 std::shared_ptr<GField> getField(std::string name) {
83 bool not_found = (fields_map->find(name) == fields_map->end());
84
85 if (not_found) { log->error(ERR_WRONG_FIELD_NOT_FOUND, "GField >", name, "< not found. Exiting."); }
86 return fields_map->at(name);
87 }
88
96 std::shared_ptr<G4FieldManager> getFieldMgr(std::string name) {
97
98 // Debug visibility: print out the full map of registered field managers.
99 for (const auto& [key, value] : *fields_manager) {
100 log->info(2, "GFieldManager >", key, "< >", value);
101 }
102
103 if (fields_manager->find(name) == fields_manager->end()) {
104 log->error(ERR_WRONG_FIELD_NOT_FOUND, "GField >", name, "< not found. Exiting.");
105 }
106
107 return fields_manager->at(name);
108 }
109};
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:37
std::shared_ptr< G4FieldManager > getFieldMgr(std::string name)
Retrieve the G4FieldManager associated with a given field name.
Definition gmagneto.h:96
std::shared_ptr< GField > getField(std::string name)
Retrieve a field object by name.
Definition gmagneto.h:82
bool isField(const std::string &name) const
Check whether a field with the given name exists.
Definition gmagneto.h:67
std::vector< std::string > getFieldNames() const
Return the configured field names.
Definition gmagneto.cc:49
GMagneto(const std::shared_ptr< GOptions > &gopts)
Construct and initialize the magnetic field registry.
Definition gmagneto.cc:15
#define ERR_WRONG_FIELD_NOT_FOUND