g4system
Loading...
Searching...
No Matches
checkAndReturnParameters.cc
Go to the documentation of this file.
1
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 << 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 std::vector<double> parameters = gutilities::getG4NumbersFromString(s->getParameters());
29 int actualNumberOfParameters = static_cast<int>(parameters.size());
30
31 // Table of valid counts for each primitive.
32 if (type == "G4Box") possibleNumberOfParameters = {3};
33 else if (type == "G4Tubs") possibleNumberOfParameters = {5};
34 else if (type == "G4CutTubs") possibleNumberOfParameters = {11};
35 else if (type == "G4Cons") possibleNumberOfParameters = {7};
36 else if (type == "G4Para") possibleNumberOfParameters = {6};
37 else if (type == "G4Trd") possibleNumberOfParameters = {5};
38 else if (type == "G4Trap") possibleNumberOfParameters = {4, 11};
39 else if (type == "G4Sphere") possibleNumberOfParameters = {6};
40 else if (type == "G4Orb") possibleNumberOfParameters = {1};
41 else if (type == "G4Torus") possibleNumberOfParameters = {5};
42
43 // Polycones: special rule supporting multiple constructor layouts.
44 else if (type == "G4Polycone" || type == "G4GenericPolycone") {
45 // first constructor -> (nPars mod 3) == 0
46 // second constructor -> ((nPars-3) mod 2) == 0
47 if (actualNumberOfParameters % 3 != 0 &&
48 (actualNumberOfParameters - 3) % 2 != 0) {
50 "Wrong number of parameters in the constructor of <",
51 name, "> of solid type <", type, ">: ", s->getParameters());
52 }
53 return parameters; // valid - return early
54 }
55
56 // Polyhedra: special rule supporting multiple constructor layouts.
57 else if (type == "G4Polyhedra") {
58 // first constructor -> ((nPars-4) mod 3) == 0
59 // second constructor -> ((nPars-4) mod 2) == 0
60 if ((actualNumberOfParameters - 4) % 3 != 0 &&
61 (actualNumberOfParameters - 4) % 2 != 0) {
63 "Wrong number of parameters in the constructor of <",
64 name, "> of solid type <", type, ">: ", s->getParameters());
65 }
66 return parameters; // valid - return early
67 }
68
69 else if (type == "G4EllipticalTube") possibleNumberOfParameters = {3};
70 else if (type == "G4Ellipsoid") possibleNumberOfParameters = {5};
71 else if (type == "G4EllipticalCone") possibleNumberOfParameters = {4};
72 else if (type == "G4Paraboloid") possibleNumberOfParameters = {3};
73 else if (type == "G4Hype") possibleNumberOfParameters = {5};
74 else if (type == "G4Tet") possibleNumberOfParameters = {12, 13};
75 else if (type == "G4TwistedBox") possibleNumberOfParameters = {4};
76 else if (type == "G4TwistedTrap") possibleNumberOfParameters = {5, 11};
77 else if (type == "G4TwistedTrd") possibleNumberOfParameters = {6};
78 else if (type == "G4TwistedTubs") possibleNumberOfParameters = {5};
79 else {
81 "The constructor of <", name,
82 "> uses an unknown solid type <", type, ">");
83 }
84
85 // Generic count check for fixed-count solids.
86 if (possibleNumberOfParameters.find(actualNumberOfParameters)
87 == possibleNumberOfParameters.end()) {
89 "Wrong number of parameters in the constructor of <", name,
90 "> of solid type <", type, ">: ", s->getParameters());
91 }
92
93 return parameters;
94}
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
void error(int exit_code, Args &&... args) const
std::string getName() const
std::string getParameters() 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.
#define ERR_G4PARAMETERSMISMATCH
Solid parameter count/format did not match expected constructors.
#define ERR_G4SOLIDTYPENOTFOUND
Requested solid type is not supported by the native factory.
vector< double > getG4NumbersFromString(const string &vstring, bool warnIfNotUnit=false)