g4system
Loading...
Searching...
No Matches
checkAndReturnParameters.cc
Go to the documentation of this file.
1
6
7// g4system
10
11// Validate and parse the constructor parameter list for native Geant4 solids.
12// Header documentation is authoritative; this implementation comment is intentionally brief.
14 // PRAGMA TODO: check non-zero pars for various constructors
15 // Example: G4Box should not have any dimension equal to zero.
16 //
17 // for(unsigned i=0; i<parameters.size(); ++i) {
18 // if(getG4Number(parameters[i]) == 0) {
19 // cout << guts::GWARNING << " Warning: G4Box has one side null!" << endl;
20 // }
21 // }
22
23 std::set<int> possibleNumberOfParameters;
24 std::string type = s->getType();
25 std::string name = s->getName();
26
27 // Convert comma-/space-separated string into a vector<double>.
28 if (!s->getParameters()) {
29 log->error(
30 g4system::ERR_G4VOLUMEBUILDFAILED, "Native solid <%1> has no constructor parameters",
31 s->getG4Name());
32 }
33 std::vector<double> parameters = gutilities::getG4NumbersFromString(*s->getParameters());
34 int actualNumberOfParameters = static_cast<int>(parameters.size());
35
36 // Table of valid counts for each primitive.
37 if (type == "G4Box") possibleNumberOfParameters = {3};
38 else if (type == "G4Tubs") possibleNumberOfParameters = {5};
39 else if (type == "G4CutTubs") possibleNumberOfParameters = {11};
40 else if (type == "G4Cons") possibleNumberOfParameters = {7};
41 else if (type == "G4Para") possibleNumberOfParameters = {6};
42 else if (type == "G4Trd") possibleNumberOfParameters = {5};
43 else if (type == "G4Trap") possibleNumberOfParameters = {4, 11};
44 else if (type == "G4Sphere") possibleNumberOfParameters = {6};
45 else if (type == "G4Orb") possibleNumberOfParameters = {1};
46 else if (type == "G4Torus") possibleNumberOfParameters = {5};
47
48 // Polycones: special rule supporting multiple constructor layouts.
49 else if (type == "G4Polycone" || type == "G4GenericPolycone") {
50 // first constructor -> (nPars mod 3) == 0
51 // second constructor -> ((nPars-3) mod 2) == 0
52 if (actualNumberOfParameters % 3 != 0 &&
53 (actualNumberOfParameters - 3) % 2 != 0) {
54 log->error(
56 "Wrong number of parameters in the constructor of <%1> of solid type <%2>: %3", name, type,
57 *s->getParameters());
58 }
59 return parameters; // valid - return early
60 }
61
62 // Polyhedra: special rule supporting multiple constructor layouts.
63 else if (type == "G4Polyhedra") {
64 // first constructor -> ((nPars-4) mod 3) == 0
65 // second constructor -> ((nPars-4) mod 2) == 0
66 if ((actualNumberOfParameters - 4) % 3 != 0 &&
67 (actualNumberOfParameters - 4) % 2 != 0) {
68 log->error(
70 "Wrong number of parameters in the constructor of <%1> of solid type <%2>: %3", name, type,
71 *s->getParameters());
72 }
73 return parameters; // valid - return early
74 }
75
76 else if (type == "G4EllipticalTube") possibleNumberOfParameters = {3};
77 else if (type == "G4Ellipsoid") possibleNumberOfParameters = {5};
78 else if (type == "G4EllipticalCone") possibleNumberOfParameters = {4};
79 else if (type == "G4Paraboloid") possibleNumberOfParameters = {3};
80 else if (type == "G4Hype") possibleNumberOfParameters = {5};
81 else if (type == "G4Tet") possibleNumberOfParameters = {12, 13};
82 else if (type == "G4TwistedBox") possibleNumberOfParameters = {4};
83 else if (type == "G4TwistedTrap") possibleNumberOfParameters = {5, 11};
84 else if (type == "G4TwistedTrd") possibleNumberOfParameters = {6};
85 else if (type == "G4TwistedTubs") possibleNumberOfParameters = {5};
86 else {
87 log->error(
88 g4system::ERR_G4SOLIDTYPENOTFOUND, "The constructor of <%1> uses an unknown solid type <%2>", name,
89 type);
90 }
91
92 // Generic count check for fixed-count solids.
93 if (possibleNumberOfParameters.find(actualNumberOfParameters)
94 == possibleNumberOfParameters.end()) {
95 log->error(
97 "Wrong number of parameters in the constructor of <%1> of solid type <%2>: %3", name, type,
98 *s->getParameters());
99 }
100
101 return parameters;
102}
std::vector< double > checkAndReturnParameters(const GVolume *s)
Validate the number of parameters for the given primitive and return them as numeric values.
std::shared_ptr< GLogger > log
const std::string & getG4Name() const
const std::optional< std::string > & getParameters() const
std::string getName() const
std::string getType() const
Factory that builds Geant4 native primitive solids (G4Box, G4Cons, G4Trap, ...) from GEMC GVolume rec...
Conventions, labels, and error codes used by the g4system geometry/material layer.
constexpr int ERR_G4VOLUMEBUILDFAILED
A volume could not be fully built (solid/logical/physical).
constexpr int ERR_G4SOLIDTYPENOTFOUND
Requested solid type is not supported by the native factory.
constexpr int ERR_G4PARAMETERSMISMATCH
Solid parameter count/format did not match expected constructors.
vector< double > getG4NumbersFromString(const string &vstring, bool warnIfNotUnit=false)