#include <G4GDMLEvaluator.hh>
Public Member Functions | |
G4GDMLEvaluator () | |
void | Clear () |
void | DefineConstant (const G4String &, G4double) |
void | DefineVariable (const G4String &, G4double) |
void | DefineMatrix (const G4String &, G4int, std::vector< G4double >) |
void | SetVariable (const G4String &, G4double) |
G4bool | IsVariable (const G4String &) const |
G4String | SolveBrackets (const G4String &) |
G4double | Evaluate (const G4String &) |
G4int | EvaluateInteger (const G4String &) |
G4double | GetConstant (const G4String &) |
G4double | GetVariable (const G4String &) |
Definition at line 47 of file G4GDMLEvaluator.hh.
G4GDMLEvaluator::G4GDMLEvaluator | ( | ) |
Definition at line 41 of file G4GDMLEvaluator.cc.
00042 { 00043 eval.clear(); 00044 eval.setStdMath(); 00045 eval.setSystemOfUnits(meter,kilogram,second,ampere,kelvin,mole,candela); 00046 }
void G4GDMLEvaluator::Clear | ( | ) |
Definition at line 48 of file G4GDMLEvaluator.cc.
Referenced by G4GDMLReadStructure::Clear().
00049 { 00050 eval.clear(); 00051 eval.setStdMath(); 00052 eval.setSystemOfUnits(meter,kilogram,second,ampere,kelvin,mole,candela); 00053 00054 variableList.clear(); 00055 }
Definition at line 57 of file G4GDMLEvaluator.cc.
References FatalException, and G4Exception().
Referenced by G4GDMLReadDefine::ConstantRead(), DefineMatrix(), G4GDMLReadDefine::ExpressionRead(), and G4GDMLReadDefine::QuantityRead().
00058 { 00059 if (eval.findVariable(name)) 00060 { 00061 G4String error_msg = "Redefinition of constant or variable: "+name; 00062 G4Exception("G4GDMLEvaluator::DefineConstant()", "InvalidExpression", 00063 FatalException, error_msg); 00064 } 00065 eval.setVariable(name.c_str(),value); 00066 }
Definition at line 80 of file G4GDMLEvaluator.cc.
References DefineConstant(), FatalException, and G4Exception().
Referenced by G4GDMLReadDefine::MatrixRead().
00083 { 00084 const G4int size = valueList.size(); 00085 00086 if (size == 0) 00087 { 00088 G4String error_msg = "Matrix '"+name+"' is empty!"; 00089 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 00090 FatalException, error_msg); 00091 } 00092 /* 00093 if (size == 1) 00094 { 00095 G4String error_msg = "Matrix '" + name 00096 + "' has only one element! " 00097 + "Define a constant instead!!"; 00098 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 00099 FatalException, error_msg); 00100 } 00101 */ 00102 00103 if (size % coldim != 0) 00104 { 00105 G4String error_msg = "Matrix '" + name + "' is not filled correctly!"; 00106 G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize", 00107 FatalException, error_msg); 00108 } 00109 00110 if ((size == coldim) || (coldim == 1)) // Row- or column matrix 00111 { 00112 for (G4int i=0;i<size;i++) 00113 { 00114 std::stringstream MatrixElementNameStream; 00115 MatrixElementNameStream << name << "_" << i; 00116 DefineConstant(MatrixElementNameStream.str(),valueList[i]); 00117 } 00118 } 00119 else // Normal matrix 00120 { 00121 const G4int rowdim = size/coldim; 00122 00123 for (G4int i=0;i<rowdim;i++) 00124 { 00125 for (G4int j=0;j<coldim;j++) 00126 { 00127 std::stringstream MatrixElementNameStream; 00128 MatrixElementNameStream << name << "_" << i << "_" << j; 00129 DefineConstant(MatrixElementNameStream.str(),valueList[coldim*i+j]); 00130 } 00131 } 00132 } 00133 }
Definition at line 68 of file G4GDMLEvaluator.cc.
References FatalException, and G4Exception().
Referenced by G4GDMLReadDefine::VariableRead().
00069 { 00070 if (eval.findVariable(name)) 00071 { 00072 G4String error_msg = "Redefinition of constant or variable: "+name; 00073 G4Exception("G4GDMLEvaluator::DefineVariable()", "InvalidExpression", 00074 FatalException, error_msg); 00075 } 00076 eval.setVariable(name.c_str(),value); 00077 variableList.push_back(name); 00078 }
Definition at line 213 of file G4GDMLEvaluator.cc.
References FatalException, G4Exception(), and SolveBrackets().
Referenced by G4GDMLReadMaterials::AtomRead(), G4GDMLReadStructure::AxisRead(), G4GDMLReadParamvol::Box_dimensionsRead(), G4GDMLReadSolids::BoxRead(), G4GDMLReadParamvol::Cone_dimensionsRead(), G4GDMLReadSolids::ConeRead(), G4GDMLReadDefine::ConstantRead(), G4GDMLReadSolids::CutTubeRead(), G4GDMLReadStructure::DivisionvolRead(), G4GDMLReadMaterials::DRead(), G4GDMLReadSolids::ElconeRead(), G4GDMLReadMaterials::ElementRead(), G4GDMLReadSolids::EllipsoidRead(), G4GDMLReadSolids::EltubeRead(), EvaluateInteger(), G4GDMLReadDefine::ExpressionRead(), G4GDMLReadMaterials::FractionRead(), G4GDMLReadSolids::GenTrapRead(), GetConstant(), GetVariable(), G4GDMLReadParamvol::Hype_dimensionsRead(), G4GDMLReadSolids::HypeRead(), G4GDMLReadMaterials::MaterialRead(), G4GDMLReadDefine::MatrixRead(), G4GDMLReadMaterials::MEERead(), G4GDMLReadSolids::OpticalSurfaceRead(), G4GDMLReadParamvol::Orb_dimensionsRead(), G4GDMLReadSolids::OrbRead(), G4GDMLReadParamvol::Para_dimensionsRead(), G4GDMLReadSolids::ParaboloidRead(), G4GDMLReadParamvol::ParameterisedRead(), G4GDMLReadSolids::ParaRead(), G4GDMLReadSolids::PolyconeRead(), G4GDMLReadSolids::PolyhedraRead(), G4GDMLReadDefine::PositionRead(), G4GDMLReadMaterials::PRead(), G4GDMLReadSolids::QuadrangularRead(), G4GDMLReadStructure::QuantityRead(), G4GDMLReadDefine::QuantityRead(), G4GDMLReadSolids::ReflectedSolidRead(), G4GDMLReadDefine::RotationRead(), G4GDMLReadDefine::ScaleRead(), G4GDMLReadSolids::SectionRead(), G4GDMLReadParamvol::Sphere_dimensionsRead(), G4GDMLReadSolids::SphereRead(), G4GDMLReadSolids::TetRead(), G4GDMLReadParamvol::Torus_dimensionsRead(), G4GDMLReadSolids::TorusRead(), G4GDMLReadParamvol::Trap_dimensionsRead(), G4GDMLReadSolids::TrapRead(), G4GDMLReadParamvol::Trd_dimensionsRead(), G4GDMLReadSolids::TrdRead(), G4GDMLReadMaterials::TRead(), G4GDMLReadSolids::TriangularRead(), G4GDMLReadParamvol::Tube_dimensionsRead(), G4GDMLReadSolids::TubeRead(), G4GDMLReadSolids::TwistedboxRead(), G4GDMLReadSolids::TwistedtrapRead(), G4GDMLReadSolids::TwistedtrdRead(), G4GDMLReadSolids::TwistedtubsRead(), G4GDMLReadSolids::TwoDimVertexRead(), G4GDMLReadDefine::VariableRead(), G4GDMLReadDefine::VectorRead(), G4GDMLReadSolids::XtruRead(), and G4GDMLReadSolids::ZplaneRead().
00214 { 00215 G4String expression = SolveBrackets(in); 00216 00217 G4double value = 0.0; 00218 00219 if (!expression.empty()) 00220 { 00221 value = eval.evaluate(expression.c_str()); 00222 00223 if (eval.status() != G4Evaluator::OK) 00224 { 00225 eval.print_error(); 00226 G4String error_msg = "Error in expression: " + expression; 00227 G4Exception("G4GDMLEvaluator::Evaluate()", "InvalidExpression", 00228 FatalException, error_msg); 00229 } 00230 } 00231 return value; 00232 }
Definition at line 234 of file G4GDMLEvaluator.cc.
References Evaluate(), FatalException, and G4Exception().
Referenced by G4GDMLReadMaterials::CompositeRead(), G4GDMLReadStructure::DivisionvolRead(), G4GDMLReadMaterials::IsotopeRead(), G4GDMLRead::LoopRead(), G4GDMLReadDefine::MatrixRead(), G4GDMLReadSolids::PolyhedraRead(), SolveBrackets(), and G4GDMLReadStructure::Volume_contentRead().
00235 { 00236 // This function is for evaluating integer expressions, 00237 // like loop variables and matrix indices. 00238 // Complains if the evaluated expression has a fractional 00239 // part different from zero 00240 00241 G4double value = Evaluate(expression); 00242 00243 G4int whole = (G4int)value; 00244 G4double frac = value - (G4double)whole; 00245 00246 if (frac != 0.0) 00247 { 00248 G4String error_msg = "Expression '" + expression 00249 + "' is expected to have an integer value!"; 00250 G4Exception("G4GDMLEvaluator::EvaluateInteger()", "InvalidExpression", 00251 FatalException, error_msg); 00252 } 00253 return whole; 00254 }
Definition at line 256 of file G4GDMLEvaluator.cc.
References Evaluate(), FatalException, G4Exception(), and IsVariable().
Referenced by G4GDMLReadDefine::GetConstant().
00257 { 00258 if (IsVariable(name)) 00259 { 00260 G4String error_msg = "Constant '" + name 00261 + "' is not defined! It is a variable!"; 00262 G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup", 00263 FatalException, error_msg); 00264 } 00265 if (!eval.findVariable(name)) 00266 { 00267 G4String error_msg = "Constant '" + name + "' is not defined!"; 00268 G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup", 00269 FatalException, error_msg); 00270 } 00271 return Evaluate(name); 00272 }
Definition at line 274 of file G4GDMLEvaluator.cc.
References Evaluate(), FatalException, G4Exception(), and IsVariable().
Referenced by G4GDMLReadDefine::GetVariable().
00275 { 00276 if (!IsVariable(name)) 00277 { 00278 G4String error_msg = "Variable '" + name + "' is not a defined!"; 00279 G4Exception("G4GDMLEvaluator::GetVariable()", "InvalidSetup", 00280 FatalException, error_msg); 00281 } 00282 return Evaluate(name); 00283 }
Definition at line 146 of file G4GDMLEvaluator.cc.
Referenced by GetConstant(), GetVariable(), G4GDMLReadDefine::IsValidID(), G4GDMLRead::LoopRead(), and SetVariable().
00147 { 00148 const size_t variableCount = variableList.size(); 00149 00150 for (size_t i=0;i<variableCount;i++) 00151 { 00152 if (variableList[i] == name) { return true; } 00153 } 00154 00155 return false; 00156 }
Definition at line 135 of file G4GDMLEvaluator.cc.
References FatalException, G4Exception(), and IsVariable().
Referenced by G4GDMLRead::LoopRead().
00136 { 00137 if (!IsVariable(name)) 00138 { 00139 G4String error_msg = "Variable '" + name + "' is not defined!"; 00140 G4Exception("G4GDMLEvaluator::SetVariable()", "InvalidSetup", 00141 FatalException, error_msg); 00142 } 00143 eval.setVariable(name.c_str(),value); 00144 }
Definition at line 158 of file G4GDMLEvaluator.cc.
References G4String::append(), EvaluateInteger(), FatalException, and G4Exception().
Referenced by Evaluate(), G4GDMLRead::GenerateName(), and G4GDMLRead::GeneratePhysvolName().
00159 { 00160 std::string::size_type full = in.size(); 00161 std::string::size_type open = in.find("[",0); 00162 std::string::size_type close = in.find("]",0); 00163 00164 if (open==close) { return in; } 00165 00166 if ((open>close) || (open==std::string::npos) || (close==std::string::npos)) 00167 { 00168 G4String error_msg = "Bracket mismatch: " + in; 00169 G4Exception("G4GDMLEvaluator::SolveBrackets()", "InvalidExpression", 00170 FatalException, error_msg); 00171 return in; 00172 } 00173 00174 std::string::size_type begin = open; 00175 std::string::size_type end = 0; 00176 std::string::size_type end1 = 0; 00177 std::string out; 00178 out.append(in,0,open); 00179 00180 do // Loop for all possible matrix elements in 'in' 00181 { 00182 do // SolveBrackets for one matrix element 00183 { 00184 end = in.find(",",begin+1); 00185 end1= in.find("]",begin+1); 00186 if (end>end1) { end = end1; } 00187 if (end==std::string::npos) { end = close;} 00188 00189 std::stringstream indexStream; 00190 indexStream << "_" << EvaluateInteger(in.substr(begin+1,end-begin-1))-1; 00191 00192 out.append(indexStream.str()); 00193 00194 begin = end; 00195 00196 } while (end<close); 00197 00198 if (full==close) { return out; } 00199 00200 open = in.find("[",begin); 00201 close = in.find("]",begin+1); 00202 00203 if (open==close) { out.append(in.substr(end+1,full-end-1)); return out; } 00204 out.append(in.substr(end+1,open-end-1)); 00205 00206 begin=open; 00207 00208 } while (close<full); 00209 00210 return out; 00211 }