61 G4String error_msg =
"Redefinition of constant or variable: "+
name;
62 G4Exception(
"G4GDMLEvaluator::DefineConstant()",
"InvalidExpression",
72 G4String error_msg =
"Redefinition of constant or variable: "+
name;
73 G4Exception(
"G4GDMLEvaluator::DefineVariable()",
"InvalidExpression",
77 variableList.push_back(name);
82 std::vector<G4double> valueList)
84 const G4int size = valueList.size();
88 G4String error_msg =
"Matrix '"+name+
"' is empty!";
89 G4Exception(
"G4GDMLEvaluator::DefineMatrix()",
"InvalidSize",
103 if (size % coldim != 0)
105 G4String error_msg =
"Matrix '" + name +
"' is not filled correctly!";
106 G4Exception(
"G4GDMLEvaluator::DefineMatrix()",
"InvalidSize",
110 if ((size == coldim) || (coldim == 1))
112 for (
G4int i=0;i<size;i++)
114 std::stringstream MatrixElementNameStream;
115 MatrixElementNameStream << name <<
"_" << i;
121 const G4int rowdim = size/coldim;
123 for (
G4int i=0;i<rowdim;i++)
125 for (
G4int j=0;j<coldim;j++)
127 std::stringstream MatrixElementNameStream;
128 MatrixElementNameStream << name <<
"_" << i <<
"_" << j;
129 DefineConstant(MatrixElementNameStream.str(),valueList[coldim*i+j]);
139 G4String error_msg =
"Variable '" + name +
"' is not defined!";
140 G4Exception(
"G4GDMLEvaluator::SetVariable()",
"InvalidSetup",
148 const size_t variableCount = variableList.size();
150 for (
size_t i=0;i<variableCount;i++)
152 if (variableList[i] == name) {
return true; }
160 std::string::size_type full = in.size();
161 std::string::size_type
open = in.find(
"[",0);
162 std::string::size_type
close = in.find(
"]",0);
164 if (open==close) {
return in; }
166 if ((open>close) || (open==std::string::npos) || (close==std::string::npos))
168 G4String error_msg =
"Bracket mismatch: " +
in;
169 G4Exception(
"G4GDMLEvaluator::SolveBrackets()",
"InvalidExpression",
174 std::string::size_type begin =
open;
175 std::string::size_type end = 0;
176 std::string::size_type end1 = 0;
178 out.append(in,0,open);
184 end = in.find(
",",begin+1);
185 end1= in.find(
"]",begin+1);
186 if (end>end1) { end = end1; }
187 if (end==std::string::npos) { end =
close;}
189 std::stringstream indexStream;
190 indexStream <<
"_" <<
EvaluateInteger(in.substr(begin+1,end-begin-1))-1;
192 out.append(indexStream.str());
198 if (full==close) {
return out; }
200 open = in.find(
"[",begin);
201 close = in.find(
"]",begin+1);
203 if (open==close) { out.
append(in.substr(end+1,full-end-1));
return out; }
204 out.
append(in.substr(end+1,open-end-1));
208 }
while (close<full);
219 if (!expression.empty())
221 value = eval.
evaluate(expression.c_str());
226 G4String error_msg =
"Error in expression: " + expression;
227 G4Exception(
"G4GDMLEvaluator::Evaluate()",
"InvalidExpression",
248 G4String error_msg =
"Expression '" + expression
249 +
"' is expected to have an integer value!";
250 G4Exception(
"G4GDMLEvaluator::EvaluateInteger()",
"InvalidExpression",
260 G4String error_msg =
"Constant '" + name
261 +
"' is not defined! It is a variable!";
262 G4Exception(
"G4GDMLEvaluator::GetConstant()",
"InvalidSetup",
267 G4String error_msg =
"Constant '" + name +
"' is not defined!";
268 G4Exception(
"G4GDMLEvaluator::GetConstant()",
"InvalidSetup",
278 G4String error_msg =
"Variable '" + name +
"' is not a defined!";
279 G4Exception(
"G4GDMLEvaluator::GetVariable()",
"InvalidSetup",