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();
167 const bool no_systems_defined = gsystemsMap->empty();
172 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
173 const std::string& factoryName = sysPtr->getFactoryName();
175 if (factoryName.empty()) {
177 "Factory name for system <", sysName,
"> is empty!");
180 auto facIt = systemFactories.find(factoryName);
181 if (facIt == systemFactories.end()) {
183 "Factory <", factoryName,
"> not found for system <", sysName,
">");
186 auto& factory = facIt->second;
189 "Factory pointer <", factoryName,
"> is nullptr");
194 for (
const auto& yaml : yamlFiles) {
197 log->
warning(
"Directory extracted from YAML <", yaml,
"> is empty.");
198 factory->addPossibleFileLocation(dir);
202 factory->loadSystem(sysPtr.get());
203 factory->closeSystem();
208 auto world_is_defined =
false;
209 for (
auto& [sysName, sysPtr] : *gsystemsMap) {
212 log->
info(1,
"ROOT world volume found in system <", sysName,
">");
213 world_is_defined =
true;
217 if (!world_is_defined) {
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() +
">");
303 std::string g4motherName = motherVolume->getSystem() +
GSYSTEM_DELIMITER + motherVolumeName;
308 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) whose definitions live in the sqlite database.
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 DEFAULTG4PLACEMENTTYPE
#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)