gfields
Loading...
Searching...
No Matches
gmagneto.cc
Go to the documentation of this file.
1// gemc
2#include "gfactory.h"
3
4// gfields
5#include "gmagneto.h"
6#include "gfield_options.h"
7
8// #include "G4TransportationManager.hh"
9// #include "G4PropagatorInField.hh"
10
11
12GMagneto::GMagneto(const std::shared_ptr<GOptions>& gopts) : GBase(gopts, GMAGNETO_LOGGER) {
13 // Allocate the registries that will hold field objects and their corresponding managers.
14 fields_map = std::make_shared<gFieldMap>();
15 fields_manager = std::make_shared<gFieldMgrMap>();
16
17 // Factory manager responsible for loading plugins and instantiating objects.
18 GManager gFieldManager(gopts);
19
20 // Translate user configuration (options) into concrete field definitions.
21 // TODO: this should be done in gemc instead and passed to gmagneto? could be kept here
22 std::vector<GFieldDefinition> field_definition_array = gfields::get_GFieldDefinition(gopts);
23
24 for (auto& field_definition : field_definition_array) {
25 std::string name = field_definition.name;
26 log->info(1, field_definition);
27
28 // Only create each named field once; repeated names are ignored by this map check.
29 if (fields_map->find(name) == fields_map->end()) {
30 // Load the plugin, instantiate the field object, and cache it by name.
31 fields_map->emplace(name, gFieldManager.LoadAndRegisterObjectFromLibrary<GField>(field_definition.gfieldPluginName(), gopts));
32
33 // Pass the configuration down to the concrete implementation so it can parse/cache parameters.
34 fields_map->at(name)->load_field_definitions(field_definition);
35
36 // Create and cache the Geant4 field manager responsible for stepping/chord finding.
37 fields_manager->emplace(name, fields_map->at(name)->create_FieldManager());
38 }
39 }
40
41 // TODO: add min and max steps
42 // G4TransportationManager::GetTransportationManager()->GetPropagatorInField()->SetLargestAcceptableStep(10);
43}
std::shared_ptr< GLogger > log
Abstract base class representing a magnetic field.
Definition gfield.h:99
void info(int level, Args &&... args) const
GMagneto(const std::shared_ptr< GOptions > &gopts)
Construct and initialize the magnetic field registry.
Definition gmagneto.cc:12
std::shared_ptr< T > LoadAndRegisterObjectFromLibrary(std::string_view name, const std::shared_ptr< GOptions > &gopts)
constexpr const char * GMAGNETO_LOGGER
Definition gfield.h:13
std::vector< GFieldDefinition > get_GFieldDefinition(const std::shared_ptr< GOptions > &gopts)
Build the list of field definitions from the provided options.