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;
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 std::string digitization = gvolumePair.second->getDigitization();
140 if (find(snames.begin(), snames.end(), digitization) == snames.end())
141 snames.push_back(digitization);
150void GWorld::create_gsystemsMap(
SystemList systems) {
152 gsystemsMap->clear();
154 for (
auto& sysPtr : systems) {
157 gsystemsMap->emplace(key, sysPtr);
163void GWorld::load_systems() {
166 auto systemFactories = createSystemFactory();
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) {
221 auto rootSystem = std::make_shared<GSystem>(
230 rootSystem->addROOTVolume(worldVolumeDefinition);
240void GWorld::load_gmodifiers() {
244 auto modPtr = std::make_shared<GModifier>(mod);
245 gmodifiersMap.emplace(modPtr->getName(), modPtr);
249 for (
auto& [volumeName, modPtr] : gmodifiersMap)
252 GVolume* vol = searchForVolume(volumeName,
253 " is marked for modifications");
259 log->
info(2,
"g-modifying volume <", volumeName,
260 "> with modifier: ", *modPtr);
261 log->
info(2,
"After modifications:", *vol);
267void GWorld::assignG4Names() {
268 for (
auto& systemPair : *gsystemsMap) {
269 for (
auto& [volumeName, gvolume] : systemPair.second->getGVolumesMap()) {
271 std::string motherVolumeName = gvolume->getMotherName();
274 auto motherVolume = searchForVolume(motherVolumeName,
"mother of <" + gvolume->getName() +
">");
276 std::string g4motherName = motherVolume->getSystem() +
GSYSTEM_DELIMITER + motherVolumeName;
281 gvolume->assignG4Names(g4name, g4motherName);
std::shared_ptr< GLogger > log
void warning(Args &&... args) const
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::string getScalarString(const std::string &tag) const
std::vector< std::string > getYamlFiles() const
Load a system from CAD assets (e.g. STL) found in a directory.
Abstract base class for loading a GSystem from a specific source.
Placeholder factory for GDML-based systems.
Load a GSystem from a sqlite database.
Load a system from ASCII text files.
Geometry volume record loaded into a GSystem.
void modifyExistence(bool e)
Enable or disable this volume in the final assembled world.
void applyTilt(std::string t)
Apply an additional rotation to this volume.
void applyShift(std::string s)
Apply an additional translation to this volume.
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.
#define GSYSTEMSQLITETFACTORYLABEL
#define GSYSTEMCADTFACTORYLABEL
#define GSYSTEMASCIIFACTORYLABEL
#define GSYSTEM_DELIMITER
Delimiter used to build fully-qualified names (system/name).
#define ERR_GVOLUMENOTFOUND
#define ROOTWORLDGVOLUMENAME
Canonical name for the ROOT/world gvolume entry.
#define MOTHEROFUSALL
Special mother-name marker for the top-level world root.
#define GSYSTEMGDMLTFACTORYLABEL
std::vector< SystemPtr > SystemList
constexpr const char * GWORLD_LOGGER
#define UNINITIALIZEDSTRINGQUANTITY
std::vector< GModifier > getModifiers(const std::shared_ptr< GOptions > &gopts)
Build a list of volume modifiers from options.
SystemList getSystems(const std::shared_ptr< GOptions > &gopts)
Build a list of systems from options.
string getDirFromPath(const std::string &path)
string getFileFromPath(const std::string &path)