g4system
Loading...
Searching...
No Matches
geant4Dependencies.cc
Go to the documentation of this file.
1// geant4Dependencies.cc : dependency checks used by factory default implementations.
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 std::string copyOf = s->getCopyOf();
26 std::string solidsOpr = s->getSolidsOpr();
27 std::string gsystem = s->getSystem();
28
29 std::string message;
30
31 if (copyOf != "" && copyOf != UNINITIALIZEDSTRINGQUANTITY) { message = ", copyOf: " + copyOf; }
32 else if (solidsOpr != "" && copyOf != UNINITIALIZEDSTRINGQUANTITY) { message = ", solidsOpr: " + solidsOpr; }
33
34 log->debug(NORMAL, className(), " checkSolidDependencies: checking dependencies for <",
35 s->getName(), ">", message);
36
37 /*──────────────────────────────────── copyOf: volumeName ───────────────────────────────────*/
38 if (copyOf != "" && copyOf != UNINITIALIZEDSTRINGQUANTITY) {
39 auto volume_copy = gsystem + "/" + copyOf;
40 if (getSolidFromMap(volume_copy, g4s) != nullptr) {
41 log->info(2, "<", s->getName(), "> is a copy of <", volume_copy, ">, which already exists");
42 return true;
43 }
44 log->info(2, "<", s->getName(), "> is a copy of <", volume_copy,
45 ">, which already exists, which does not exist yet");
46 return false;
47 }
48
49 /*──────────────────────────────────── Boolean solid operations ──────────────────────────────*/
50 else if (solidsOpr != "" && solidsOpr != UNINITIALIZEDSTRINGQUANTITY) {
51 // The solids operation is expected to be tokenized into: left operand, operator, right operand.
52 std::vector<std::string> solidOperations =
54
55 if (solidOperations.size() == 3) {
56 // Supported operators: + (union), - (subtraction), * (intersection).
57 if (solidOperations[1] == "+" || solidOperations[1] == "-" || solidOperations[1] == "*") {
58 auto left = getSolidFromMap(solidOperations[0], g4s);
59 if (left == nullptr) left = getSolidFromMap(gsystem + "/" + solidOperations[0], g4s);
60 auto right = getSolidFromMap(solidOperations[2], g4s);
61 if (right == nullptr) right = getSolidFromMap(gsystem + "/" + solidOperations[2], g4s);
62
63 // Operand solids must exist before the boolean solid can be created.
64 if (left != nullptr && right != nullptr)
65 return true;
66 }
67 return false;
68 }
69 return false;
70 }
71
72 /*──────────────────────────────────── default path ──────────────────────────────────*/
73 return true; // ordinary primitive – no extra prerequisites
74}
75
77 [[maybe_unused]] std::unordered_map<std::string,
78 G4Volume*>* g4s) {
79 // Placeholder for future logical checks (materials/sensitive detector prerequisites).
80 return true;
81}
82
83// Verify that both the candidate logical volume and its mother logical volume exist before placement.
84// Header documentation is authoritative; this implementation comment is intentionally brief.
86 std::unordered_map<std::string,
87 G4Volume*>* g4s) {
88 std::string vname = s->getG4Name();
89 std::string motherName = s->getG4MotherName();
90
91 // Candidate wrapper must exist in the map before we can reason about its logical/physical state.
92 if (g4s->find(vname) == g4s->end()) {
93 log->info(2, "dependencies: ", vname, " not found in gvolume map yet.");
94 return false;
95 }
96
97 // Candidate logical must exist (or be available through a copy source).
98 if (getLogicalFromMap(vname, g4s) == nullptr) {
99 // If it is a copy, require that the source logical volume exists.
100 std::string copyOf = s->getCopyOf();
101 if (copyOf != "" && copyOf != UNINITIALIZEDSTRINGQUANTITY) {
102 auto gsystem = s->getSystem();
103 auto volume_copy = gsystem + "/" + copyOf;
104 if (getLogicalFromMap(volume_copy, g4s) == nullptr) {
105 log->info(2, "dependencies: copy ", volume_copy, " logical volume not found yet.");
106 return false;
107 }
108 }
109 else {
110 log->info(2, "dependencies: ", vname, " logical volume not found yet.");
111 return false;
112 }
113 }
114
115 // Mother logical must exist unless this is the world volume.
116 if (motherName != MOTHEROFUSALL && getLogicalFromMap(motherName, g4s) == nullptr) {
117 log->info(2, "dependencies: ", vname,
118 " mother <", motherName, "> logical volume not found yet.");
119 return false;
120 }
121
122 // Everything satisfied – emit verbose trace.
123 if (motherName != MOTHEROFUSALL) {
124 log->info(2, "dependencies: <", vname, "> and mother <", motherName,
125 "> logical volumes are found. Ready to build or get physical volume.");
126 }
127 else {
128 log->info(2, "dependencies: <", vname,
129 "> logical volume is found. Ready to build or get physical volume.");
130 }
131 return true;
132}
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
void debug(debug_type type, Args &&... args) const
void info(int level, Args &&... args) const
std::string getCopyOf() const
std::string getName() const
std::string getG4Name() const
std::string getSystem() const
std::string getG4MotherName() const
std::string getSolidsOpr() const
Abstract factory that converts a GEMC DB GVolume into Geant4 objects.
NORMAL
#define MOTHEROFUSALL
#define UNINITIALIZEDSTRINGQUANTITY
vector< std::string > getStringVectorFromString(const std::string &input)