g4system
Loading...
Searching...
No Matches
geant4Dependencies.cc
Go to the documentation of this file.
1// geant4Dependencies.cc : dependency checks used by factory default implementations.
12
13// guts
14#include "gutilities.h"
15
16// g4system
17#include "gsystemConventions.h"
18#include "g4objectsFactory.h"
19
21 std::unordered_map<std::string,
22 G4Volume*>* g4s) {
23 // Dependency check applies only to solids that rely on other solids (copy/boolean operations).
24 // Ordinary primitives have no extra prerequisites.
25 const auto& copyOf = s->getCopyOf();
26 const auto& solidsOpr = s->getSolidsOpr();
27 std::string gsystem = s->getSystem();
28
29 std::string message;
30
31 if (copyOf) { message = ", copyOf: " + *copyOf; }
32 else if (solidsOpr) { message = ", solidsOpr: " + *solidsOpr; }
33
34 log->debug(
35 NORMAL, "%1 checkSolidDependencies: checking dependencies for <%2>%3", className(), s->getName(),
36 message);
37
38 /*──────────────────────────────────── copyOf: volumeName ───────────────────────────────────*/
39 if (copyOf) {
40 auto volume_copy = gsystem + "/" + *copyOf;
41 if (getSolidFromMap(volume_copy, g4s) != nullptr) {
42 log->info(2, "<%1> is a copy of <%2>, which already exists", s->getName(), volume_copy);
43 return true;
44 }
45 log->info(
46 2, "<%1> is a copy of <%2>, which already exists, which does not exist yet", s->getName(),
47 volume_copy);
48 return false;
49 }
50
51 /*──────────────────────────────────── Boolean solid operations ──────────────────────────────*/
52 else if (solidsOpr) {
53 // The solids operation is expected to be tokenized into: left operand, operator, right operand.
54 std::vector<std::string> solidOperations =
56
57 // A leading "@" marks GEMC2's Operation:@ absolute-coordinate placement (see buildSolid.cc); it
58 // is not an operand, so drop it before checking the operand dependencies.
59 if (!solidOperations.empty() && solidOperations[0] == "@") {
60 solidOperations.erase(solidOperations.begin());
61 }
62
63 if (solidOperations.size() == 3) {
64 // Supported operators: + (union), - (subtraction), * (intersection).
65 if (solidOperations[1] == "+" || solidOperations[1] == "-" || solidOperations[1] == "*") {
66 auto left = getSolidFromMap(solidOperations[0], g4s);
67 if (left == nullptr) left = getSolidFromMap(gsystem + "/" + solidOperations[0], g4s);
68 auto right = getSolidFromMap(solidOperations[2], g4s);
69 if (right == nullptr) right = getSolidFromMap(gsystem + "/" + solidOperations[2], g4s);
70
71 // Operand solids must exist before the boolean solid can be created.
72 if (left != nullptr && right != nullptr)
73 return true;
74 }
75 return false;
76 }
77 return false;
78 }
79
80 /*──────────────────────────────────── default path ──────────────────────────────────*/
81 return true; // ordinary primitive – no extra prerequisites
82}
83
85 [[maybe_unused]] std::unordered_map<std::string,
86 G4Volume*>* g4s) {
87 // Placeholder for future logical checks (materials/sensitive detector prerequisites).
88 return true;
89}
90
91// Verify that both the candidate logical volume and its mother logical volume exist before placement.
92// Header documentation is authoritative; this implementation comment is intentionally brief.
94 std::unordered_map<std::string,
95 G4Volume*>* g4s) {
96 std::string vname = s->getG4Name();
97 std::string motherName = s->getG4MotherName();
98
99 // Candidate wrapper must exist in the map before we can reason about its logical/physical state.
100 if (g4s->find(vname) == g4s->end()) {
101 log->info(2, "dependencies: %1 not found in gvolume map yet.", vname);
102 return false;
103 }
104
105 // Candidate logical must exist (or be available through a copy source).
106 if (getLogicalFromMap(vname, g4s) == nullptr) {
107 // If it is a copy, require that the source logical volume exists.
108 const auto& copyOf = s->getCopyOf();
109 if (copyOf) {
110 auto gsystem = s->getSystem();
111 auto volume_copy = gsystem + "/" + *copyOf;
112 if (getLogicalFromMap(volume_copy, g4s) == nullptr) {
113 log->info(2, "dependencies: copy %1 logical volume not found yet.", volume_copy);
114 return false;
115 }
116 }
117 else {
118 log->info(2, "dependencies: %1 logical volume not found yet.", vname);
119 return false;
120 }
121 }
122
123 // Mother logical must exist unless this is the world volume.
124 if (motherName != gsystem::MOTHEROFUSALL && getLogicalFromMap(motherName, g4s) == nullptr) {
125 log->info(2, "dependencies: %1 mother <%2> logical volume not found yet.", vname, motherName);
126 return false;
127 }
128
129 // Everything satisfied – emit verbose trace.
130 if (motherName != gsystem::MOTHEROFUSALL) {
131 log->info(
132 2,
133 "dependencies: <%1> and mother <%2> logical volumes are found. Ready to build or get physical "
134 "volume.", vname, motherName);
135 }
136 else {
137 log->info(
138 2, "dependencies: <%1> logical volume is found. Ready to build or get physical volume.", vname);
139 }
140 return true;
141}
bool checkSolidDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Check whether all prerequisites to build a solid are satisfied.
virtual std::string_view className() const =0
Short, human-readable factory name for logging.
static bool checkLogicalDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Logical dependency check placeholder.
bool checkPhysicalDependencies(const GVolume *s, std::unordered_map< std::string, G4Volume * > *g4s)
Verify prerequisites to build a physical placement.
static G4VSolid * getSolidFromMap(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Lookup solid in the g4s map.
static G4LogicalVolume * getLogicalFromMap(const std::string &volume_name, std::unordered_map< std::string, G4Volume * > *g4s)
Lookup logical volume in the g4s map.
Convenience container holding a Geant4 solid, logical, and physical volume.
Definition g4volume.h:52
std::shared_ptr< GLogger > log
const std::string & getG4Name() const
const std::optional< std::string > & getSolidsOpr() const
const std::optional< std::string > & getCopyOf() const
std::string getName() const
std::string getSystem() const
const std::string & getG4MotherName() const
Abstract factory that converts a GEMC DB GVolume into Geant4 objects.
NORMAL
constexpr char MOTHEROFUSALL[]
vector< std::string > getStringVectorFromString(const std::string &input)