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 // Operand solids must exist before the boolean solid can be created.
59 if (getSolidFromMap(solidOperations[0], g4s) != nullptr &&
60 getSolidFromMap(solidOperations[2], g4s) != nullptr)
61 return true;
62 }
63 return false;
64 }
65 return false;
66 }
67
68 /*──────────────────────────────────── default path ──────────────────────────────────*/
69 return true; // ordinary primitive – no extra prerequisites
70}
71
73 [[maybe_unused]] std::unordered_map<std::string,
74 G4Volume*>* g4s) {
75 // Placeholder for future logical checks (materials/sensitive detector prerequisites).
76 return true;
77}
78
79// Verify that both the candidate logical volume and its mother logical volume exist before placement.
80// Header documentation is authoritative; this implementation comment is intentionally brief.
82 std::unordered_map<std::string,
83 G4Volume*>* g4s) {
84 std::string vname = s->getG4Name();
85 std::string motherName = s->getG4MotherName();
86
87 // Candidate wrapper must exist in the map before we can reason about its logical/physical state.
88 if (g4s->find(vname) == g4s->end()) {
89 log->info(2, "dependencies: ", vname, " not found in gvolume map yet.");
90 return false;
91 }
92
93 // Candidate logical must exist (or be available through a copy source).
94 if (getLogicalFromMap(vname, g4s) == nullptr) {
95 // If it is a copy, require that the source logical volume exists.
96 std::string copyOf = s->getCopyOf();
97 if (copyOf != "" && copyOf != UNINITIALIZEDSTRINGQUANTITY) {
98 auto gsystem = s->getSystem();
99 auto volume_copy = gsystem + "/" + copyOf;
100 if (getLogicalFromMap(volume_copy, g4s) == nullptr) {
101 log->info(2, "dependencies: copy ", volume_copy, " logical volume not found yet.");
102 return false;
103 }
104 }
105 else {
106 log->info(2, "dependencies: ", vname, " logical volume not found yet.");
107 return false;
108 }
109 }
110
111 // Mother logical must exist unless this is the world volume.
112 if (motherName != MOTHEROFUSALL && getLogicalFromMap(motherName, g4s) == nullptr) {
113 log->info(2, "dependencies: ", vname,
114 " mother <", motherName, "> logical volume not found yet.");
115 return false;
116 }
117
118 // Everything satisfied – emit verbose trace.
119 if (motherName != MOTHEROFUSALL) {
120 log->info(2, "dependencies: <", vname, "> and mother <", motherName,
121 "> logical volumes are found. Ready to build or get physical volume.");
122 }
123 else {
124 log->info(2, "dependencies: <", vname,
125 "> logical volume is found. Ready to build or get physical volume.");
126 }
127 return true;
128}
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:50
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)