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()) {
30 "Native solid <", s->getG4Name(), "> has no constructor parameters");
31 }
32 std::vector<double> parameters = gutilities::getG4NumbersFromString(*s->getParameters());
33 int actualNumberOfParameters = static_cast<int>(parameters.size());
34
35 // Table of valid counts for each primitive.
36 if (type == "G4Box") possibleNumberOfParameters = {3};
37 else if (type == "G4Tubs") possibleNumberOfParameters = {5};
38 else if (type == "G4CutTubs") possibleNumberOfParameters = {11};
39 else if (type == "G4Cons") possibleNumberOfParameters = {7};
40 else if (type == "G4Para") possibleNumberOfParameters = {6};
41 else if (type == "G4Trd") possibleNumberOfParameters = {5};
42 else if (type == "G4Trap") possibleNumberOfParameters = {4, 11};
43 else if (type == "G4Sphere") possibleNumberOfParameters = {6};
44 else if (type == "G4Orb") possibleNumberOfParameters = {1};
45 else if (type == "G4Torus") possibleNumberOfParameters = {5};
46
47 // Polycones: special rule supporting multiple constructor layouts.
48 else if (type == "G4Polycone" || type == "G4GenericPolycone") {
49 // first constructor -> (nPars mod 3) == 0
50 // second constructor -> ((nPars-3) mod 2) == 0
51 if (actualNumberOfParameters % 3 != 0 &&
52 (actualNumberOfParameters - 3) % 2 != 0) {
54 "Wrong number of parameters in the constructor of <",
55 name, "> of solid type <", type, ">: ", *s->getParameters());
56 }
57 return parameters; // valid - return early
58 }
59
60 // Polyhedra: special rule supporting multiple constructor layouts.
61 else if (type == "G4Polyhedra") {
62 // first constructor -> ((nPars-4) mod 3) == 0
63 // second constructor -> ((nPars-4) mod 2) == 0
64 if ((actualNumberOfParameters - 4) % 3 != 0 &&
65 (actualNumberOfParameters - 4) % 2 != 0) {
67 "Wrong number of parameters in the constructor of <",
68 name, "> of solid type <", type, ">: ", *s->getParameters());
69 }
70 return parameters; // valid - return early
71 }
72
73 else if (type == "G4EllipticalTube") possibleNumberOfParameters = {3};
74 else if (type == "G4Ellipsoid") possibleNumberOfParameters = {5};
75 else if (type == "G4EllipticalCone") possibleNumberOfParameters = {4};
76 else if (type == "G4Paraboloid") possibleNumberOfParameters = {3};
77 else if (type == "G4Hype") possibleNumberOfParameters = {5};
78 else if (type == "G4Tet") possibleNumberOfParameters = {12, 13};
79 else if (type == "G4TwistedBox") possibleNumberOfParameters = {4};
80 else if (type == "G4TwistedTrap") possibleNumberOfParameters = {5, 11};
81 else if (type == "G4TwistedTrd") possibleNumberOfParameters = {6};
82 else if (type == "G4TwistedTubs") possibleNumberOfParameters = {5};
83 else {
85 "The constructor of <", name,
86 "> uses an unknown solid type <", type, ">");
87 }
88
89 // Generic count check for fixed-count solids.
90 if (possibleNumberOfParameters.find(actualNumberOfParameters)
91 == possibleNumberOfParameters.end()) {
93 "Wrong number of parameters in the constructor of <", name,
94 "> of solid type <", type, ">: ", *s->getParameters());
95 }
96
97 return parameters;
98}
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)