gsystem
Loading...
Searching...
No Matches
loadGeometry.cc
Go to the documentation of this file.
1
8// gsystem
9#include "systemCadFactory.h"
10#include "gsystemConventions.h"
11
12// gemc
13#include "gutilities.h"
14
15
16// c++
17#include <filesystem>
18
19using namespace std;
20
21void GSystemCADFactory::loadGeometry(GSystem* s) {
23
24 if (filesystem::exists(dirLocation)) {
25 vector<string> cadFiles = gutilities::getListOfFilesInDirectory(dirLocation, {".stl"});
26
27 // Import each STL as a volume. Each volume name is derived from the filename.
28 for (const auto& cf : cadFiles) {
29 s->addVolumeFromFile(GSYSTEMCADTFACTORYLABEL, dirLocation.append("/").append(cf));
30 }
31
32 // If the file cad__<variation>.yaml is found in dirLocation, modify the gvolumes accordingly.
33 string cad_yaml = dirLocation + "/cad__" + s->getVariation() + ".yaml";
34
35 if (filesystem::exists(cad_yaml)) {
36 log->info(0, "Loading modifiers from YAML file: " + cad_yaml);
37
38 // Parse the YAML file.
39 // YAML types are external; use \c in documentation (this code is intentionally unchanged).
40 YAML::Node ynode = YAML::LoadFile(cad_yaml);
41
42 for (auto& [volumeName, gvolume] : s->getGVolumesMap()) {
43 // Each top-level YAML key is expected to match a volume name.
44 auto vmod = ynode[volumeName];
45 log->info(0, "Looking for cad modifiers for Volume: ", volumeName, ", found: ", vmod);
46
47 // The following commented block shows the intended application of YAML overrides
48 // to already-imported volumes (shift/tilt/existence/mother/color/material/etc.).
49 // if (vmod != nullptr) {
50 // auto shift = vmod["shift"];
51 // if (shift != nullptr) {
52 // gvolume->applyShift(shift);
53 // }
54 // auto tilt = vmod["tilt"];
55 // if (tilt != nullptr) {
56 // gvolume->applyTilt(tilt);
57 // }
58 // auto exists = vmod["exists"];
59 // if (exists != nullptr) {
60 // gvolume->modifyExistence(exists);
61 // }
62 // auto mother = vmod["mother"];
63 // if (mother != nullptr) {
64 // gvolume->resetMotherName(mother);
65 // }
66 // auto color = vmod["color"];
67 // if (color != nullptr) {
68 // gvolume->setColor(color);
69 // }
70 // auto material = vmod["material"];
71 // if (material != nullptr) {
72 // gvolume->setMaterial(material);
73 // }
74 // auto digitization = vmod["digitization"];
75 // if (digitization != nullptr) {
76 // gvolume->setDigitization(digitization);
77 // }
78 // auto identifier = vmod["identifier"];
79 // if (identifier != nullptr) {
80 // gvolume->setGIdentity(identifier);
81 // }
82 // }
83 }
84 }
85 }
86 else {
87 log->error(ERR_GDIRNOTFOUND, "CAD Directory >" + s->getFilePath() + "< not found.");
88 }
89}
std::shared_ptr< GLogger > log
void info(int level, Args &&... args) const
void error(int exit_code, Args &&... args) const
std::vector< std::string > possibleLocationOfFiles
List of candidate directories used by file-based factories.
Represents a single detector system (e.g., calorimeter, tracker).
Definition gsystem.h:32
std::string getVariation() const
Definition gsystem.h:110
std::string getFilePath()
Gets the full file path of the system.
Definition gsystem.cc:194
void addVolumeFromFile(const std::string &importType, const std::string &filename)
Add a volume imported from a file (CAD, GDML, etc.).
Definition gsystem.cc:113
Conventions and shared constants for the detector-system module.
#define GSYSTEMCADTFACTORYLABEL
#define ERR_GDIRNOTFOUND
vector< string > getListOfFilesInDirectory(const string &dirName, const vector< string > &extensions)
string searchForDirInLocations(const string &dirName, const vector< string > &possibleLocations)