25 create_gsystemsMap(gsystems);
41 create_gsystemsMap(gsystems);
51std::map<std::string, std::unique_ptr<GSystemFactory>> GWorld::createSystemFactory() {
54 std::map<std::string, std::unique_ptr<GSystemFactory>> factoryMap;
58 auto sqliteFactory = std::unique_ptr<GSystemFactory>(
69 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
70 const std::string& facName = sysPtr->getFactoryName();
72 if (facName.empty()) {
74 "Factory name for system <", sysName,
75 "> is empty! This system will not be loaded.");
79 if (factoryMap.count(facName))
continue;
83 manager.RegisterObjectFactory<GSystemCADFactory>(facName, gopts);
85 manager.RegisterObjectFactory<GSystemGDMLFactory>(facName, gopts);
87 manager.RegisterObjectFactory<GSystemSQLiteFactory>(facName, gopts);
89 manager.RegisterObjectFactory<GSystemTextFactory>(facName, gopts);
92 "Unrecognized factory name <", facName,
93 "> for system <", sysName,
">");
97 auto facPtr = std::unique_ptr<GSystemFactory>(manager.CreateObject<GSystemFactory>(facName));
101 "Failed to create factory <", facName,
102 "> for system <", sysName,
">");
105 factoryMap.emplace(facName, std::move(facPtr));
109 manager.clearDLMap();
117GVolume* GWorld::searchForVolume(
const std::string& volumeName,
const std::string& purpose)
const {
118 for (
auto& systemPair : *gsystemsMap) {
119 GVolume* thisVolume = systemPair.second->getGVolume(volumeName);
120 if (thisVolume !=
nullptr) {
121 log->info(1,
"gvolume named <", volumeName,
"> found with purpose: ", purpose);
127 "gvolume named <", volumeName,
"> (", purpose,
") not found in gsystemsMap ", purpose);
133 std::vector<std::string> snames;
136 for (
auto& systemPair : *gsystemsMap) {
137 for (
auto& gvolumePair : systemPair.second->getGVolumesMap()) {
138 const auto& digitization = gvolumePair.second->getDigitization();
139 if (digitization && find(snames.begin(), snames.end(), *digitization) == snames.end()) {
140 snames.push_back(*digitization);
149void GWorld::create_gsystemsMap(
SystemList systems) {
151 gsystemsMap->clear();
153 for (
auto& sysPtr : systems) {
156 gsystemsMap->emplace(key, sysPtr);
162void GWorld::load_systems() {
163 const std::string dbhost = gopts->getRequiredScalarString(
"sql");
165 auto systemFactories = createSystemFactory();
166 const bool no_systems_defined = gsystemsMap->empty();
169 const auto yamlFiles = gopts->getYamlFiles();
171 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
172 const std::string& factoryName = sysPtr->getFactoryName();
174 if (factoryName.empty()) {
176 "Factory name for system <", sysName,
"> is empty!");
179 auto facIt = systemFactories.find(factoryName);
180 if (facIt == systemFactories.end()) {
182 "Factory <", factoryName,
"> not found for system <", sysName,
">");
185 auto& factory = facIt->second;
188 "Factory pointer <", factoryName,
"> is nullptr");
193 for (
const auto& yaml : yamlFiles) {
196 log->warning(
"Directory extracted from YAML <", yaml,
"> is empty.");
197 factory->addPossibleFileLocation(dir);
201 factory->loadSystem(sysPtr.get());
202 factory->closeSystem();
207 auto world_is_defined =
false;
208 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
211 log->info(1,
"ROOT world volume found in system <", sysName,
">");
212 world_is_defined =
true;
216 if (!world_is_defined) {
219 const std::string worldVolumeDefinition =
222 auto rootSystem = std::make_shared<GSystem>(
231 rootSystem->addROOTVolume(worldVolumeDefinition);
233 if (no_systems_defined) {
234 std::vector<std::string> viewerBoxPars = {
254 "default visible volume for field-only visualization"
256 rootSystem->addGVolume(viewerBoxPars);
267void GWorld::load_gmodifiers() {
271 auto modPtr = std::make_shared<GModifier>(mod);
272 gmodifiersMap.emplace(modPtr->getName(), modPtr);
276 for (
auto& [volumeName, modPtr] : gmodifiersMap)
279 GVolume* vol = searchForVolume(volumeName,
280 " is marked for modifications");
286 log->info(2,
"g-modifying volume <", volumeName,
287 "> with modifier: ", *modPtr);
288 log->info(2,
"After modifications:", *vol);
294void GWorld::assignG4Names() {
295 for (
auto& systemPair : *gsystemsMap) {
296 for (
auto& [volumeName, gvolume] : systemPair.second->getGVolumesMap()) {
298 std::string motherVolumeName = gvolume->getMotherName();
301 auto motherVolume = searchForVolume(motherVolumeName,
"mother of <" + gvolume->getName() +
">");
308 gvolume->assignG4Names(g4name, g4motherName);
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
std::shared_ptr< GLogger > log
Abstract base class for loading a GSystem from a specific source.
Load a GSystem from a sqlite database.
Geometry volume record loaded into a GSystem.
void applyTilt(std::optional< std::string > t)
Apply an additional rotation to this volume.
void applyShift(std::optional< std::string > s)
Apply an additional translation to this volume.
void modifyExistence(bool e)
Enable or disable this volume in the final assembled world.
std::vector< std::string > getSensitiveDetectorsList()
Collect the list of sensitive detector identifiers.
GWorld(const std::shared_ptr< GOptions > &gopts)
Construct the world from configuration.
Conventions and shared constants for the detector-system module.
std::vector< SystemPtr > SystemList
constexpr const char * GWORLD_LOGGER
constexpr int ERR_FACTORYNOTFOUND
constexpr char GSYSTEMGDMLTFACTORYLABEL[]
constexpr char DEFAULTG4PLACEMENTTYPE[]
constexpr char GSYSTEMCADTFACTORYLABEL[]
constexpr char GSYSTEM_DELIMITER[]
Delimiter used to build fully-qualified names (system/name).
constexpr char DEFAULTROTATION[]
constexpr char GSYSTEMSQLITETFACTORYLABEL[]
constexpr char MOTHEROFUSALL[]
Special mother-name marker for the top-level world root.
constexpr char DEFAULTPOSITION[]
constexpr char GSYSTEMASCIIFACTORYLABEL[]
std::vector< GModifier > getModifiers(const std::shared_ptr< GOptions > &gopts)
Build a list of volume modifiers from options.
constexpr char ROOTWORLDGVOLUMENAME[]
Canonical name for the ROOT/world gvolume entry.
SystemList getSystems(const std::shared_ptr< GOptions > &gopts)
Build a list of systems from options.
constexpr int ERR_GVOLUMENOTFOUND
string getDirFromPath(const std::string &path)
string getFileFromPath(const std::string &path)
constexpr char SERIALIZED_NULL_TOKEN[]