Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GDMLEvaluator Class Reference

#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 &)
 
G4String ConvertToString (G4int ival)
 
G4String ConvertToString (G4double dval)
 

Detailed Description

Definition at line 47 of file G4GDMLEvaluator.hh.

Constructor & Destructor Documentation

G4GDMLEvaluator::G4GDMLEvaluator ( )

Definition at line 41 of file G4GDMLEvaluator.cc.

42 {
43  eval.clear();
44  eval.setStdMath();
46 }
static constexpr double candela
Definition: G4SIunits.hh:317
static constexpr double ampere
Definition: G4SIunits.hh:189
static constexpr double second
Definition: G4SIunits.hh:157
static constexpr double meter
Definition: G4SIunits.hh:82
static constexpr double kelvin
Definition: G4SIunits.hh:281
void setSystemOfUnits(double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)
static constexpr double kilogram
Definition: G4SIunits.hh:177
static constexpr double mole
Definition: G4SIunits.hh:286

Here is the call graph for this function:

Member Function Documentation

void G4GDMLEvaluator::Clear ( )

Definition at line 48 of file G4GDMLEvaluator.cc.

49 {
50  eval.clear();
51  eval.setStdMath();
53 
54  variableList.clear();
55 }
static constexpr double candela
Definition: G4SIunits.hh:317
static constexpr double ampere
Definition: G4SIunits.hh:189
static constexpr double second
Definition: G4SIunits.hh:157
static constexpr double meter
Definition: G4SIunits.hh:82
static constexpr double kelvin
Definition: G4SIunits.hh:281
void setSystemOfUnits(double meter=1.0, double kilogram=1.0, double second=1.0, double ampere=1.0, double kelvin=1.0, double mole=1.0, double candela=1.0)
static constexpr double kilogram
Definition: G4SIunits.hh:177
static constexpr double mole
Definition: G4SIunits.hh:286

Here is the call graph for this function:

Here is the caller graph for this function:

G4String G4GDMLEvaluator::ConvertToString ( G4int  ival)

Definition at line 285 of file G4GDMLEvaluator.cc.

286 {
287  std::ostringstream os;
288  os << ival;
289  G4String vl = os.str();
290  return vl;
291 }

Here is the caller graph for this function:

G4String G4GDMLEvaluator::ConvertToString ( G4double  dval)

Definition at line 293 of file G4GDMLEvaluator.cc.

294 {
295  std::ostringstream os;
296  os << dval;
297  G4String vl = os.str();
298  return vl;
299 }
void G4GDMLEvaluator::DefineConstant ( const G4String name,
G4double  value 
)

Definition at line 57 of file G4GDMLEvaluator.cc.

58 {
59  if (eval.findVariable(name))
60  {
61  G4String error_msg = "Redefinition of constant or variable: "+name;
62  G4Exception("G4GDMLEvaluator::DefineConstant()", "InvalidExpression",
63  FatalException, error_msg);
64  }
65  eval.setVariable(name.c_str(),value);
66 }
const XML_Char * name
Definition: expat.h:151
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void setVariable(const char *name, double value)
Definition: Evaluator.cc:687
bool findVariable(const char *name) const
Definition: Evaluator.cc:721

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GDMLEvaluator::DefineMatrix ( const G4String name,
G4int  coldim,
std::vector< G4double valueList 
)

Definition at line 80 of file G4GDMLEvaluator.cc.

83 {
84  const G4int size = valueList.size();
85 
86  if (size == 0)
87  {
88  G4String error_msg = "Matrix '"+name+"' is empty!";
89  G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize",
90  FatalException, error_msg);
91  }
92  /*
93  if (size == 1)
94  {
95  G4String error_msg = "Matrix '" + name
96  + "' has only one element! "
97  + "Define a constant instead!!";
98  G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize",
99  FatalException, error_msg);
100  }
101  */
102 
103  if (size % coldim != 0)
104  {
105  G4String error_msg = "Matrix '" + name + "' is not filled correctly!";
106  G4Exception("G4GDMLEvaluator::DefineMatrix()", "InvalidSize",
107  FatalException, error_msg);
108  }
109 
110  if ((size == coldim) || (coldim == 1)) // Row- or column matrix
111  {
112  for (G4int i=0;i<size;i++)
113  {
114  std::stringstream MatrixElementNameStream;
115  MatrixElementNameStream << name << "_" << i;
116  DefineConstant(MatrixElementNameStream.str(),valueList[i]);
117  }
118  }
119  else // Normal matrix
120  {
121  const G4int rowdim = size/coldim;
122 
123  for (G4int i=0;i<rowdim;i++)
124  {
125  for (G4int j=0;j<coldim;j++)
126  {
127  std::stringstream MatrixElementNameStream;
128  MatrixElementNameStream << name << "_" << i << "_" << j;
129  DefineConstant(MatrixElementNameStream.str(),valueList[coldim*i+j]);
130  }
131  }
132  }
133 }
void DefineConstant(const G4String &, G4double)
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GDMLEvaluator::DefineVariable ( const G4String name,
G4double  value 
)

Definition at line 68 of file G4GDMLEvaluator.cc.

69 {
70  if (eval.findVariable(name))
71  {
72  G4String error_msg = "Redefinition of constant or variable: "+name;
73  G4Exception("G4GDMLEvaluator::DefineVariable()", "InvalidExpression",
74  FatalException, error_msg);
75  }
76  eval.setVariable(name.c_str(),value);
77  variableList.push_back(name);
78 }
const XML_Char * name
Definition: expat.h:151
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void setVariable(const char *name, double value)
Definition: Evaluator.cc:687
bool findVariable(const char *name) const
Definition: Evaluator.cc:721

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4GDMLEvaluator::Evaluate ( const G4String in)

Definition at line 213 of file G4GDMLEvaluator.cc.

214 {
215  G4String expression = SolveBrackets(in);
216 
217  G4double value = 0.0;
218 
219  if (!expression.empty())
220  {
221  value = eval.evaluate(expression.c_str());
222 
223  if (eval.status() != G4Evaluator::OK)
224  {
225  eval.print_error();
226  G4String error_msg = "Error in expression: " + expression;
227  G4Exception("G4GDMLEvaluator::Evaluate()", "InvalidExpression",
228  FatalException, error_msg);
229  }
230  }
231  return value;
232 }
int status() const
Definition: Evaluator.cc:631
const XML_Char int const XML_Char * value
Definition: expat.h:331
void print_error() const
Definition: Evaluator.cc:641
double evaluate(const char *expression)
Definition: Evaluator.cc:611
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String SolveBrackets(const G4String &)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4int G4GDMLEvaluator::EvaluateInteger ( const G4String expression)

Definition at line 234 of file G4GDMLEvaluator.cc.

235 {
236  // This function is for evaluating integer expressions,
237  // like loop variables and matrix indices.
238  // Complains if the evaluated expression has a fractional
239  // part different from zero
240 
241  G4double value = Evaluate(expression);
242 
243  G4int whole = (G4int)value;
244  G4double frac = value - (G4double)whole;
245 
246  if (frac != 0.0)
247  {
248  G4String error_msg = "Expression '" + expression
249  + "' is expected to have an integer value!";
250  G4Exception("G4GDMLEvaluator::EvaluateInteger()", "InvalidExpression",
251  FatalException, error_msg);
252  }
253  return whole;
254 }
int G4int
Definition: G4Types.hh:78
const XML_Char int const XML_Char * value
Definition: expat.h:331
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
G4double Evaluate(const G4String &)

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4GDMLEvaluator::GetConstant ( const G4String name)

Definition at line 256 of file G4GDMLEvaluator.cc.

257 {
258  if (IsVariable(name))
259  {
260  G4String error_msg = "Constant '" + name
261  + "' is not defined! It is a variable!";
262  G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup",
263  FatalException, error_msg);
264  }
265  if (!eval.findVariable(name))
266  {
267  G4String error_msg = "Constant '" + name + "' is not defined!";
268  G4Exception("G4GDMLEvaluator::GetConstant()", "InvalidSetup",
269  FatalException, error_msg);
270  }
271  return Evaluate(name);
272 }
G4bool IsVariable(const G4String &) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
bool findVariable(const char *name) const
Definition: Evaluator.cc:721
G4double Evaluate(const G4String &)

Here is the call graph for this function:

Here is the caller graph for this function:

G4double G4GDMLEvaluator::GetVariable ( const G4String name)

Definition at line 274 of file G4GDMLEvaluator.cc.

275 {
276  if (!IsVariable(name))
277  {
278  G4String error_msg = "Variable '" + name + "' is not a defined!";
279  G4Exception("G4GDMLEvaluator::GetVariable()", "InvalidSetup",
280  FatalException, error_msg);
281  }
282  return Evaluate(name);
283 }
G4bool IsVariable(const G4String &) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double Evaluate(const G4String &)

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4GDMLEvaluator::IsVariable ( const G4String name) const

Definition at line 146 of file G4GDMLEvaluator.cc.

147 {
148  const size_t variableCount = variableList.size();
149 
150  for (size_t i=0;i<variableCount;i++)
151  {
152  if (variableList[i] == name) { return true; }
153  }
154 
155  return false;
156 }

Here is the caller graph for this function:

void G4GDMLEvaluator::SetVariable ( const G4String name,
G4double  value 
)

Definition at line 135 of file G4GDMLEvaluator.cc.

136 {
137  if (!IsVariable(name))
138  {
139  G4String error_msg = "Variable '" + name + "' is not defined!";
140  G4Exception("G4GDMLEvaluator::SetVariable()", "InvalidSetup",
141  FatalException, error_msg);
142  }
143  eval.setVariable(name.c_str(),value);
144 }
const XML_Char int const XML_Char * value
Definition: expat.h:331
G4bool IsVariable(const G4String &) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void setVariable(const char *name, double value)
Definition: Evaluator.cc:687

Here is the call graph for this function:

Here is the caller graph for this function:

G4String G4GDMLEvaluator::SolveBrackets ( const G4String in)

Definition at line 158 of file G4GDMLEvaluator.cc.

159 {
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);
163 
164  if (open==close) { return in; }
165 
166  if ((open>close) || (open==std::string::npos) || (close==std::string::npos))
167  {
168  G4String error_msg = "Bracket mismatch: " + in;
169  G4Exception("G4GDMLEvaluator::SolveBrackets()", "InvalidExpression",
170  FatalException, error_msg);
171  return in;
172  }
173 
174  std::string::size_type begin = open;
175  std::string::size_type end = 0;
176  std::string::size_type end1 = 0;
177  std::string out;
178  out.append(in,0,open);
179 
180  do // Loop for all possible matrix elements in 'in'
181  {
182  do // SolveBrackets for one matrix element
183  {
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;}
188 
189  std::stringstream indexStream;
190  indexStream << "_" << EvaluateInteger(in.substr(begin+1,end-begin-1))-1;
191 
192  out.append(indexStream.str());
193 
194  begin = end;
195 
196  } while (end<close);
197 
198  if (full==close) { return out; }
199 
200  open = in.find("[",begin);
201  close = in.find("]",begin+1);
202 
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));
205 
206  begin=open;
207 
208  } while (close<full);
209 
210  return out;
211 }
G4int EvaluateInteger(const G4String &)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4String & append(const G4String &)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: