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