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>(
70 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
71 const std::string& facName = sysPtr->getFactoryName();
73 if (facName.empty()) {
76 "Factory name for system <%1> is empty! This system will not be loaded.", sysName);
80 if (factoryMap.count(facName))
continue;
84 manager.RegisterObjectFactory<GSystemCADFactory>(facName, gopts);
86 manager.RegisterObjectFactory<GSystemGDMLFactory>(facName, gopts);
88 manager.RegisterObjectFactory<GSystemSQLiteFactory>(facName, gopts);
90 manager.RegisterObjectFactory<GSystemTextFactory>(facName, gopts);
98 auto facPtr = std::unique_ptr<GSystemFactory>(manager.CreateObject<GSystemFactory>(facName));
106 factoryMap.emplace(facName, std::move(facPtr));
110 manager.clearDLMap();
118GVolume* GWorld::searchForVolume(
const std::string& volumeName,
const std::string& purpose)
const {
119 for (
auto& systemPair : *gsystemsMap) {
120 GVolume* thisVolume = systemPair.second->getGVolume(volumeName);
121 if (thisVolume !=
nullptr) {
122 log->info(1,
"gvolume named <%1> found with purpose: %2", volumeName, purpose);
135 std::vector<std::string> snames;
138 for (
auto& systemPair : *gsystemsMap) {
139 for (
auto& gvolumePair : systemPair.second->getGVolumesMap()) {
140 const auto& digitization = gvolumePair.second->getDigitization();
141 if (digitization && find(snames.begin(), snames.end(), *digitization) == snames.end()) {
142 snames.push_back(*digitization);
151void GWorld::create_gsystemsMap(
SystemList systems) {
153 gsystemsMap->clear();
155 for (
auto& sysPtr : systems) {
158 gsystemsMap->emplace(key, sysPtr);
164void GWorld::load_systems() {
165 const std::string dbhost = gopts->getRequiredScalarString(
"sql");
167 auto systemFactories = createSystemFactory();
168 const bool no_systems_defined = gsystemsMap->empty();
171 const auto yamlFiles = gopts->getYamlFiles();
173 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
174 const std::string& factoryName = sysPtr->getFactoryName();
176 if (factoryName.empty()) {
180 auto facIt = systemFactories.find(factoryName);
181 if (facIt == systemFactories.end()) {
186 auto& factory = facIt->second;
193 for (
const auto& yaml : yamlFiles) {
196 log->warning(
"Directory extracted from YAML <%1> is empty.", yaml);
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 <%1>", 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 <%1> with modifier: %2", volumeName, *modPtr);
287 log->info(2,
"After modifications:%1", *vol);
293void GWorld::assignG4Names() {
294 for (
auto& systemPair : *gsystemsMap) {
295 for (
auto& [volumeName, gvolume] : systemPair.second->getGVolumesMap()) {
297 std::string motherVolumeName = gvolume->getMotherName();
300 auto motherVolume = searchForVolume(motherVolumeName,
"mother of <" + gvolume->getName() +
">");
307 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[]