CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
HepTool::Evaluator Class Reference

#include <Evaluator.h>

+ Inheritance diagram for HepTool::Evaluator:

Public Types

enum  {
  OK , WARNING_EXISTING_VARIABLE , WARNING_EXISTING_FUNCTION , WARNING_BLANK_STRING ,
  ERROR_NOT_A_NAME , ERROR_SYNTAX_ERROR , ERROR_UNPAIRED_PARENTHESIS , ERROR_UNEXPECTED_SYMBOL ,
  ERROR_UNKNOWN_VARIABLE , ERROR_UNKNOWN_FUNCTION , ERROR_EMPTY_PARAMETER , ERROR_CALCULATION_ERROR
}
 

Public Member Functions

 Evaluator ()
 
 ~Evaluator ()
 
double evaluate (const char *expression)
 
int status () const
 
int error_position () const
 
void print_error () const
 
std::string error_name () const
 
void setVariable (const char *name, double value)
 
void setVariable (const char *name, const char *expression)
 
void setFunction (const char *name, double(*fun)())
 
void setFunction (const char *name, double(*fun)(double))
 
void setFunction (const char *name, double(*fun)(double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double, double))
 
void setFunction (const char *name, double(*fun)(double, double, double, double, double))
 
bool findVariable (const char *name) const
 
bool findFunction (const char *name, int npar) const
 
void removeVariable (const char *name)
 
void removeFunction (const char *name, int npar)
 
void clear ()
 
void setStdMath ()
 
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)
 

Detailed Description

Evaluator of arithmetic expressions with an extendable dictionary. Example:

#include "CLHEP/Evaluator/Evaluator.h"
eval.setStdMath();
double res = eval.evaluate("sin(30*degree)");
if (eval.status() != HepTool::Evaluator::OK) eval.print_error();
double eval(std::string expr, int &numbad, std::ofstream &os)
Definition: testBug66214.cc:11
Author
Evgeni Chernyaev Evgue.nosp@m.ni.T.nosp@m.chern.nosp@m.iaev.nosp@m.@cern.nosp@m..ch

Definition at line 26 of file Evaluator.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

List of possible statuses. Status of the last operation can be obtained with status(). In case if status() is an ERROR the corresponding error message can be printed with print_error().

See also
status
error_position
print_error
Enumerator
OK 

Everything OK

WARNING_EXISTING_VARIABLE 

Redefinition of existing variable

WARNING_EXISTING_FUNCTION 

Redefinition of existing function

WARNING_BLANK_STRING 

Empty input string

ERROR_NOT_A_NAME 

Not allowed sysmbol in the name of variable or function

ERROR_SYNTAX_ERROR 

Systax error

ERROR_UNPAIRED_PARENTHESIS 

Unpaired parenthesis

ERROR_UNEXPECTED_SYMBOL 

Unexpected sysbol

ERROR_UNKNOWN_VARIABLE 

Non-existing variable

ERROR_UNKNOWN_FUNCTION 

Non-existing function

ERROR_EMPTY_PARAMETER 

Function call has empty parameter

ERROR_CALCULATION_ERROR 

Error during calculation

Definition at line 39 of file Evaluator.h.

39 {
40 OK, /**< Everything OK */
41 WARNING_EXISTING_VARIABLE, /**< Redefinition of existing variable */
42 WARNING_EXISTING_FUNCTION, /**< Redefinition of existing function */
43 WARNING_BLANK_STRING, /**< Empty input string */
44 ERROR_NOT_A_NAME, /**< Not allowed sysmbol in the name of variable or function */
45 ERROR_SYNTAX_ERROR, /**< Systax error */
46 ERROR_UNPAIRED_PARENTHESIS, /**< Unpaired parenthesis */
47 ERROR_UNEXPECTED_SYMBOL, /**< Unexpected sysbol */
48 ERROR_UNKNOWN_VARIABLE, /**< Non-existing variable */
49 ERROR_UNKNOWN_FUNCTION, /**< Non-existing function */
50 ERROR_EMPTY_PARAMETER, /**< Function call has empty parameter */
51 ERROR_CALCULATION_ERROR /**< Error during calculation */
52 };
@ ERROR_UNPAIRED_PARENTHESIS
Definition: Evaluator.h:46

Constructor & Destructor Documentation

◆ Evaluator()

HepTool::Evaluator::Evaluator ( )

Constructor.

Definition at line 622 of file Evaluator.cc.

622 {
623 Struct * s = new Struct();
624 p = (void *) s;
625 s->theExpression = 0;
626 s->thePosition = 0;
627 s->theStatus = OK;
628 s->theResult = 0.0;
629}
pchar thePosition
Definition: Evaluator.cc:46
pchar theExpression
Definition: Evaluator.cc:45
int theStatus
Definition: Evaluator.cc:47
double theResult
Definition: Evaluator.cc:48

◆ ~Evaluator()

HepTool::Evaluator::~Evaluator ( )

Destructor.

Definition at line 632 of file Evaluator.cc.

632 {
633 delete (Struct *)(p);
634}

Member Function Documentation

◆ clear()

void HepTool::Evaluator::clear ( )

Clear all settings.

Definition at line 788 of file Evaluator.cc.

788 {
789 Struct * s = (Struct *) p;
790 s->theDictionary.clear();
791 s->theExpression = 0;
792 s->thePosition = 0;
793 s->theStatus = OK;
794 s->theResult = 0.0;
795}
dic_type theDictionary
Definition: Evaluator.cc:44

◆ error_name()

std::string HepTool::Evaluator::error_name ( ) const

get a string defining the error name

Definition at line 676 of file Evaluator.cc.

677{
678 char prefix[] = "Evaluator : ";
679 std::ostringstream errn;
680 Struct * s = (Struct *) p;
681 switch (s->theStatus) {
682 case ERROR_NOT_A_NAME:
683 errn << prefix << "invalid name";
684 break;
686 errn << prefix << "syntax error";
687 break;
689 errn << prefix << "unpaired parenthesis";
690 break;
692 errn << prefix << "unexpected symbol";
693 break;
695 errn << prefix << "unknown variable";
696 break;
698 errn << prefix << "unknown function";
699 break;
701 errn << prefix << "empty parameter in function call";
702 break;
704 errn << prefix << "calculation error";
705 break;
706 default:
707 errn << " ";
708 }
709 return errn.str();
710}

Referenced by eval(), and print_error().

◆ error_position()

int HepTool::Evaluator::error_position ( ) const

Returns position in the input string where the problem occured.

Definition at line 662 of file Evaluator.cc.

662 {
663 return int(((Struct *)(p))->thePosition - ((Struct *)(p))->theExpression);
664}

◆ evaluate()

double HepTool::Evaluator::evaluate ( const char *  expression)

Evaluates the arithmetic expression given as character string. The expression may consist of numbers, variables and functions separated by arithmetic (+, - , /, *, ^, **) and logical operators (==, !=, >, >=, <, <=, &&, ||).

Parameters
expressioninput expression.
Returns
result of the evaluation.
See also
status
error_position
print_error

Definition at line 637 of file Evaluator.cc.

637 {
638 Struct * s = (Struct *)(p);
639 if (s->theExpression != 0) { delete[] s->theExpression; }
640 s->theExpression = 0;
641 s->thePosition = 0;
643 s->theResult = 0.0;
644 if (expression != 0) {
645 s->theExpression = new char[strlen(expression)+1];
646 strcpy(s->theExpression, expression);
647 s->theStatus = engine(s->theExpression,
648 s->theExpression+strlen(expression)-1,
649 s->theResult,
650 s->thePosition,
651 s->theDictionary);
652 }
653 return s->theResult;
654}

Referenced by eval(), and MyEvaluator::evaluate().

◆ findFunction()

bool HepTool::Evaluator::findFunction ( const char *  name,
int  npar 
) const

Finds the function in the dictionary.

Parameters
namename of the function to be unset.
nparnumber of parameters of the function.
Returns
true if such a function exists, false otherwise.

Definition at line 758 of file Evaluator.cc.

758 {
759 if (name == 0 || *name == '\0') return false;
760 if (npar < 0 || npar > MAX_N_PAR) return false;
761 const char * pointer; int n; REMOVE_BLANKS;
762 if (n == 0) return false;
763 Struct * s = (Struct *)(p);
764 return ((s->theDictionary).find(sss[npar]+string(pointer,n)) ==
765 (s->theDictionary).end()) ? false : true;
766}
#define MAX_N_PAR
Definition: Evaluator.cc:65
#define REMOVE_BLANKS
Definition: Evaluator.cc:54

◆ findVariable()

bool HepTool::Evaluator::findVariable ( const char *  name) const

Finds the variable in the dictionary.

Parameters
namename of the variable.
Returns
true if such a variable exists, false otherwise.

Definition at line 747 of file Evaluator.cc.

747 {
748 if (name == 0 || *name == '\0') return false;
749 const char * pointer; int n; REMOVE_BLANKS;
750 if (n == 0) return false;
751 Struct * s = (Struct *)(p);
752 return
753 ((s->theDictionary).find(string(pointer,n)) == (s->theDictionary).end()) ?
754 false : true;
755}

◆ print_error()

void HepTool::Evaluator::print_error ( ) const

Prints error message if status() is an ERROR.

Definition at line 667 of file Evaluator.cc.

667 {
668 Struct * s = (Struct *) p;
669 if(s->theStatus != OK) {
670 std::cerr << error_name() << std::endl;
671 }
672 return;
673}
std::string error_name() const
Definition: Evaluator.cc:676

◆ removeFunction()

void HepTool::Evaluator::removeFunction ( const char *  name,
int  npar 
)

Removes the function from the dictionary.

Parameters
namename of the function to be unset.
nparnumber of parameters of the function.

Definition at line 778 of file Evaluator.cc.

778 {
779 if (name == 0 || *name == '\0') return;
780 if (npar < 0 || npar > MAX_N_PAR) return;
781 const char * pointer; int n; REMOVE_BLANKS;
782 if (n == 0) return;
783 Struct * s = (Struct *)(p);
784 (s->theDictionary).erase(sss[npar]+string(pointer,n));
785}

◆ removeVariable()

void HepTool::Evaluator::removeVariable ( const char *  name)

Removes the variable from the dictionary.

Parameters
namename of the variable.

Definition at line 769 of file Evaluator.cc.

769 {
770 if (name == 0 || *name == '\0') return;
771 const char * pointer; int n; REMOVE_BLANKS;
772 if (n == 0) return;
773 Struct * s = (Struct *)(p);
774 (s->theDictionary).erase(string(pointer,n));
775}

◆ setFunction() [1/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)()  fun 
)

Adds to the dictionary a function without parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 722 of file Evaluator.cc.

724{ setItem("0", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }
void(* voidfuncptr)()
Definition: Evaluator.cc:24

Referenced by setStdMath().

◆ setFunction() [2/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double fun 
)

Adds to the dictionary a function with one parameter. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 726 of file Evaluator.cc.

728{ setItem("1", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [3/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double fun 
)

Adds to the dictionary a function with two parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 730 of file Evaluator.cc.

732{ setItem("2", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [4/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double fun 
)

Adds to the dictionary a function with three parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 734 of file Evaluator.cc.

736{ setItem("3", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [5/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double, double fun 
)

Adds to the dictionary a function with four parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 738 of file Evaluator.cc.

740{ setItem("4", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setFunction() [6/6]

void HepTool::Evaluator::setFunction ( const char *  name,
double(*)(double, double, double, double, double fun 
)

Adds to the dictionary a function with five parameters. If such a function already exist in the dictionary, then status will be set to WARNING_EXISTING_FUNCTION.

Parameters
namefunction name.
funpointer to the real function in the user code.

Definition at line 742 of file Evaluator.cc.

744{ setItem("5", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); }

◆ setStdMath()

void HepTool::Evaluator::setStdMath ( )

Sets standard mathematical functions and constants.

Definition at line 31 of file setStdMath.cc.

31 {
32
33 // S E T S T A N D A R D C O N S T A N T S
34
35 setVariable("pi", 3.14159265358979323846);
36 setVariable("e", 2.7182818284590452354);
37 setVariable("gamma", 0.577215664901532861);
38 setVariable("radian", 1.0);
39 setVariable("rad", 1.0);
40 setVariable("degree", 3.14159265358979323846/180.);
41 setVariable("deg", 3.14159265358979323846/180.);
42
43 // S E T S T A N D A R D F U N C T I O N S
44
45 setFunction("abs", eval_abs);
46 setFunction("min", eval_min);
47 setFunction("max", eval_max);
48 setFunction("sqrt", eval_sqrt);
49 setFunction("pow", eval_pow);
50 setFunction("sin", eval_sin);
51 setFunction("cos", eval_cos);
52 setFunction("tan", eval_tan);
53 setFunction("asin", eval_asin);
54 setFunction("acos", eval_acos);
55 setFunction("atan", eval_atan);
56 setFunction("atan2", eval_atan2);
57 setFunction("sinh", eval_sinh);
58 setFunction("cosh", eval_cosh);
59 setFunction("tanh", eval_tanh);
60 setFunction("exp", eval_exp);
61 setFunction("log", eval_log);
62 setFunction("log10", eval_log10);
63}
void setFunction(const char *name, double(*fun)())
Definition: Evaluator.cc:722
void setVariable(const char *name, double value)
Definition: Evaluator.cc:713

Referenced by eval(), and MyEvaluator::MyEvaluator().

◆ setSystemOfUnits()

void HepTool::Evaluator::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 
)

Sets system of units. Default is the SI system of units. To set the CGS (Centimeter-Gram-Second) system of units one should call: setSystemOfUnits(100., 1000., 1.0, 1.0, 1.0, 1.0, 1.0);

To set system of units accepted in the GEANT4 simulation toolkit one should call:

setSystemOfUnits(1.e+3, 1./1.60217733e-25, 1.e+9, 1./1.60217733e-10,
1.0, 1.0, 1.0);
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)

The basic units in GEANT4 are:

millimeter (millimeter = 1.)
nanosecond (nanosecond = 1.)
Mega electron Volt (MeV = 1.)
positron charge (eplus = 1.)
degree Kelvin (kelvin = 1.)
the amount of substance (mole = 1.)
luminous intensity (candela = 1.)
radian (radian = 1.)
steradian (steradian = 1.)

Definition at line 9 of file setSystemOfUnits.cc.

16{
17 const double kilo_ = 1.e+03; // chilioi (Greek) "thousand"
18 const double mega_ = 1.e+06; // megas (Greek) "large"
19 const double giga_ = 1.e+09; // gigas (Greek) "giant"
20 const double tera_ = 1.e+12; // teras (Greek) "monster"
21 const double peta_ = 1.e+15; // pente (Greek) "five"
22
23 const double deci_ = 1.e-01; // decimus (Latin) "tenth"
24 const double centi_ = 1.e-02; // centum (Latin) "hundred"
25 const double milli_ = 1.e-03; // mille (Latin) "thousand"
26 const double micro_ = 1.e-06; // micro (Latin) or mikros (Greek) "small"
27 const double nano_ = 1.e-09; // nanus (Latin) or nanos (Greek) "dwarf"
28 const double pico_ = 1.e-12; // pico (Spanish) "bit"
29
30 // ======================================================================
31 //
32 // Base (default) SI units
33 // for the basic measurable quantities (dimensions):
34 //
35 // ======================================================================
36
37 // Length
38 // metrum (Latin) and metron (Greek) "measure"
39 const double m = meter;
40 setVariable("meter", m);
41 setVariable("metre", m);
42 setVariable("m", m);
43
44 // Mass
45 const double kg = kilogram;
46 setVariable("kilogram", kg);
47 setVariable("kg", kg);
48
49 // Time
50 // minuta secundam (Latin) "second small one"
51 const double s = second;
52 setVariable("second", s);
53 setVariable("s", s);
54
55 // Current
56 // --- honors Andre-Marie Ampere (1775-1836) of France
57 const double A = ampere;
58 setVariable("ampere", A);
59 setVariable("amp", A);
60 setVariable("A", A);
61
62 // Temperature
63 // --- honors William Thomson, 1st Baron Lord Kelvin (1824-1907) of England
64 const double K = kelvin;
65 setVariable("kelvin", K);
66 setVariable("K", K);
67
68 // Amount of substance
69 const double mol = mole;
70 setVariable("mole", mol);
71 setVariable("mol", mol);
72
73 // Luminous intensity
74 const double cd = candela;
75 setVariable("candela", cd);
76 setVariable("cd", cd);
77
78 // ======================================================================
79 //
80 // Supplementary SI units having special symbols:
81 //
82 // ======================================================================
83
84 // Plane angle
85 const double rad = 1.;
86 setVariable("radian", rad);
87 setVariable("rad", rad);
88 setVariable("milliradian", milli_ * rad);
89 setVariable("mrad", milli_ * rad);
90
91 const double pi = 3.14159265358979323846;
92 const double deg = rad*pi/180.;
93 setVariable("degree", deg);
94 setVariable("deg", deg);
95
96 // Solid angle
97 const double sr = 1.;
98 setVariable("steradian", sr);
99 setVariable("sr", sr);
100
101 // ======================================================================
102 //
103 // Derived SI units having special symbols:
104 //
105 // ======================================================================
106
107 // Frequency
108 // --- honors Heinrich Rudolf Hertz (1857-1894) of Germany
109 const double Hz = 1./s;
110 setVariable("hertz", Hz);
111 setVariable("Hz", Hz);
112
113 // Force
114 // --- honors Sir Isaac Newton (1642-1727) of England
115 const double N = m * kg / (s*s);
116 setVariable("newton", N);
117 setVariable("N", N);
118
119 // Pressure
120 // --- honors Blaise Pascal (1623-1662) of France
121 const double Pa = N / (m*m);
122 setVariable("pascal", Pa);
123 setVariable("Pa", Pa);
124
125 const double atm = 101325. * Pa;
126 setVariable("atmosphere", atm);
127 setVariable("atm", atm);
128
129 const double bar = 100000*Pa;
130 setVariable("bar", bar);
131
132 // Energy
133 // --- honors James Prescott Joule (1818-1889) of England
134 const double J = N * m;
135 setVariable("joule", J);
136 setVariable("J", J);
137
138 // Power
139 // --- honors James Watt (1736-1819) of Scotland
140 const double W = J / s;
141 setVariable("watt", W);
142 setVariable("W", W);
143
144 // Electric charge
145 // --- honors Charles-Augustin de Coulomb (1736-1806) of France
146 const double C = A * s;
147 setVariable("coulomb", C);
148 setVariable("C", C);
149
150 // Electric potential
151 // --- honors Count Alessandro Volta (1745-1827) of Italy
152 const double V = J / C;
153 setVariable("volt", V);
154 setVariable("V", V);
155
156 // Electric resistance
157 // --- honors Georg Simon Ohm (1787-1854) of Germany
158 const double ohm = V / A;
159 setVariable("ohm", ohm);
160
161 // Electric conductance
162 // --- honors Ernst Werner von Siemens (1816-1892) or
163 // his brother Sir William (Karl Wilhelm von) Siemens (1823-1883)
164 // of Germany (England)
165 const double S = 1./ ohm;
166 setVariable("siemens", S);
167 setVariable("S", S);
168
169 // Electric capacitance
170 // --- honors Michael Faraday (1791-1867) of England
171 const double F = C / V;
172 setVariable("farad", F);
173 setVariable("F", F);
174
175 // Magnetic flux density
176 // --- honors Nikola Tesla (1856-1943) of Croatia (United States)
177 const double T = V * s / (m*m);
178 setVariable("tesla", T);
179 setVariable("T", T);
180
181 // --- honors Karl Friedrich Gauss (1777-1855) of Germany
182 const double Gs = 1.e-4*T;
183 setVariable("gauss", Gs);
184 setVariable("Gs", Gs);
185
186 // Magnetic flux
187 // --- honors Wilhelm Eduard Weber (1804-1891) of Germany
188 const double Wb = V * s;
189 setVariable("weber", Wb);
190 setVariable("Wb", Wb);
191
192 // Inductance
193 // --- honors Joseph Henry (1797-1878) of the United States
194 const double H = Wb / A;
195 setVariable("henry", H);
196 setVariable("H", H);
197
198 // Luminous flux
199 const double lm = cd * sr;
200 setVariable("lumen", lm);
201 setVariable("lm", lm);
202
203 // Illuminace
204 const double lx = lm / (m*m);
205 setVariable("lux", lx);
206 setVariable("lx", lx);
207
208 // Radioactivity
209 // --- honors Antoine-Henri Becquerel (1852-1908) of France
210 const double Bq = 1./s;
211 setVariable("becquerel", Bq);
212 setVariable("Bq", Bq);
213 setVariable("kilobecquerel", kilo_ * Bq);
214 setVariable("kBq", kilo_ * Bq);
215 setVariable("megabecquerel", mega_ * Bq);
216 setVariable("MBq", mega_ * Bq);
217 setVariable("gigabecquerel", giga_ * Bq);
218 setVariable("GBq", giga_ * Bq);
219
220 // --- honors Pierre Curie (1859-1906) of France
221 // and Marie Sklodowska Curie (1867-1934) of Poland
222 setVariable("curie", 3.7e+10 * Bq);
223 setVariable("Ci", 3.7e+10 * Bq);
224 setVariable("millicurie", milli_ * 3.7e+10 * Bq);
225 setVariable("mCi", milli_ * 3.7e+10 * Bq);
226 setVariable("microcurie", micro_ * 3.7e+10 * Bq);
227 setVariable("uCi", micro_ * 3.7e+10 * Bq);
228
229 // Specific energy
230 // --- honors Louis Harold Gray, F.R.S. (1905-1965) of England
231 const double Gy = J / kg;
232 setVariable("gray", Gy);
233 setVariable("Gy", Gy);
234 setVariable("kilogray", kilo_ * Gy);
235 setVariable("milligray", milli_ * Gy);
236 setVariable("microgray", micro_ * Gy);
237
238 // Dose equivalent
239 const double Sv = J / kg;
240 setVariable("sievert", Sv);
241 setVariable("Sv", Sv);
242
243 // ======================================================================
244 //
245 // Selected units:
246 //
247 // ======================================================================
248
249 // Length
250
251 const double mm = milli_ * m;
252 setVariable("millimeter", mm);
253 setVariable("mm", mm);
254
255 const double cm = centi_ * m;
256 setVariable("centimeter", cm);
257 setVariable("cm", cm);
258
259 setVariable("decimeter", deci_ * m);
260
261 const double km = kilo_ * m;
262 setVariable("kilometer", km);
263 setVariable("km", km);
264
265 setVariable("micrometer", micro_ * m);
266 setVariable("micron", micro_ * m);
267 setVariable("um", micro_ * m);
268 setVariable("nanometer", nano_ * m);
269 setVariable("nm", nano_ * m);
270
271 const double parsec = 3.0856775807e+16 * m;
272 setVariable("parsec", parsec);
273 setVariable("pc", parsec);
274
275 // --- honors Anders Jonas Angstrom (1814-1874) of Sweden
276 setVariable("angstrom", 1.e-10 * m);
277
278 // --- honors Enrico Fermi (1901-1954) of Italy
279 setVariable("fermi", 1.e-15 * m);
280
281 // Length^2
282
283 setVariable("m2", m*m);
284 setVariable("mm2", mm*mm);
285 setVariable("cm2", cm*cm);
286 setVariable("km2", km*km);
287
288 const double barn = 1.e-28 * m*m;
289 setVariable("barn", barn);
290 setVariable("millibarn", milli_ * barn);
291 setVariable("mbarn", milli_ * barn);
292 setVariable("microbarn", micro_ * barn);
293 setVariable("nanobarn", nano_ * barn);
294 setVariable("picobarn", pico_ * barn);
295
296 // LengthL^3
297
298 setVariable("m3", m*m*m);
299 setVariable("mm3", mm*mm*mm);
300 setVariable("cm3", cm*cm*cm);
301 setVariable("cc", cm*cm*cm);
302 setVariable("km3", km*km*km);
303
304 const double L = 1.e-3*m*m*m;
305 setVariable("liter", L);
306 setVariable("litre", L);
307 setVariable("L", L);
308 setVariable("centiliter", centi_ * L);
309 setVariable("cL", centi_ * L);
310 setVariable("milliliter", milli_ * L);
311 setVariable("mL", milli_ * L);
312
313 // Length^-1
314
315 const double dpt = 1./m;
316 setVariable("diopter", dpt);
317 setVariable("dioptre", dpt);
318 setVariable("dpt", dpt);
319
320 // Mass
321
322 const double g = 0.001*kg;
323 setVariable("gram", g);
324 setVariable("g", g);
325 setVariable("milligram", milli_ * g);
326 setVariable("mg", milli_ * g);
327
328 // Time
329
330 setVariable("millisecond", milli_ * s);
331 setVariable("ms", milli_ * s);
332 setVariable("microsecond", micro_ * s);
333 setVariable("us", micro_ * s);
334 setVariable("nanosecond", nano_ * s);
335 setVariable("ns", nano_ * s);
336 setVariable("picosecond", pico_ * s);
337 setVariable("ps", pico_ * s);
338
339 const double minute = 60*s;
340 setVariable("minute", minute);
341 const double hour = 60*minute;
342 setVariable("hour", hour);
343 const double day = 24*hour;
344 setVariable("day", day);
345 const double year = 365*day;
346 setVariable("year", year);
347
348 // Current
349
350 setVariable("milliampere", milli_ * A);
351 setVariable("mA", milli_ * A);
352 setVariable("microampere", micro_ * A);
353 setVariable("nanoampere", nano_ * A);
354
355 // Frequency
356
357 setVariable("kilohertz", kilo_ * Hz);
358 setVariable("kHz", kilo_ * Hz);
359 setVariable("megahertz", mega_ * Hz);
360 setVariable("MHz", mega_ * Hz);
361
362 // Force
363 setVariable("kilonewton", kilo_ * N);
364 setVariable("kN", kilo_ * N);
365
366 // Pressure
367 setVariable("kilobar", kilo_ * bar);
368 setVariable("kbar", kilo_ * bar);
369 setVariable("millibar", milli_ * bar);
370 setVariable("mbar", milli_ * bar);
371
372 // Energy
373 setVariable("kilojoule", kilo_ * J);
374 setVariable("kJ", kilo_ * J);
375 setVariable("megajoule", mega_ * J);
376 setVariable("MJ", mega_ * J);
377 setVariable("gigajoule", giga_ * J);
378 setVariable("GJ", giga_ * J);
379
380 const double e_SI = 1.602176634e-19; // positron charge in coulomb
381 const double ePlus = e_SI * C; // positron charge
382 const double eV = ePlus * V;
383 setVariable("electronvolt", eV);
384 setVariable("eV", eV);
385 setVariable("millielectronvolt", milli_ * eV);
386 setVariable("kiloelectronvolt", kilo_ * eV);
387 setVariable("keV", kilo_ * eV);
388 setVariable("megaelectronvolt", mega_ * eV);
389 setVariable("MeV", mega_ * eV);
390 setVariable("gigaelectronvolt", giga_ * eV);
391 setVariable("GeV", giga_ * eV);
392 setVariable("teraelectronvolt", tera_ * eV);
393 setVariable("TeV", tera_ * eV);
394 setVariable("petaelectronvolt", peta_ * eV);
395 setVariable("PeV", peta_ * eV);
396
397 // Power
398 setVariable("kilowatt", kilo_ * W);
399 setVariable("kW", kilo_ * W);
400 setVariable("megawatt", mega_ * W);
401 setVariable("MW", mega_ * W);
402 setVariable("gigawatt", giga_ * W);
403 setVariable("GW", giga_ * W);
404
405 // Electric potential
406 setVariable("kilovolt", kilo_ * V);
407 setVariable("kV", kilo_ * V);
408 setVariable("megavolt", mega_ * V);
409 setVariable("MV", mega_ * V);
410
411 // Electric capacitance
412 setVariable("millifarad", milli_ * F);
413 setVariable("mF", milli_ * F);
414 setVariable("microfarad", micro_ * F);
415 setVariable("uF", micro_ * F);
416 setVariable("nanofarad", nano_ * F);
417 setVariable("nF", nano_ * F);
418 setVariable("picofarad", pico_ * F);
419 setVariable("pF", pico_ * F);
420
421 // Magnetic flux density
422 setVariable("kilogauss", kilo_ * Gs);
423 setVariable("kGs", kilo_ * Gs);
424}
int g(shared_ptr< X >)

Referenced by eval().

◆ setVariable() [1/2]

void HepTool::Evaluator::setVariable ( const char *  name,
const char *  expression 
)

Adds to the dictionary a variable with an arithmetic expression assigned to it. If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.

Parameters
namename of the variable.
expressionarithmetic expression.

Definition at line 716 of file Evaluator.cc.

717{ setItem("", name, Item(expression), (Struct *)p); }

◆ setVariable() [2/2]

void HepTool::Evaluator::setVariable ( const char *  name,
double  value 
)

Adds to the dictionary a variable with given value. If a variable with such a name already exist in the dictionary, then status will be set to WARNING_EXISTING_VARIABLE.

Parameters
namename of the variable.
valuevalue assigned to the variable.

Definition at line 713 of file Evaluator.cc.

714{ setItem("", name, Item(value), (Struct *)p); }

Referenced by main(), setStdMath(), and setSystemOfUnits().

◆ status()

int HepTool::Evaluator::status ( ) const

Returns status of the last operation with the evaluator.

Definition at line 657 of file Evaluator.cc.

657 {
658 return ((Struct *)(p))->theStatus;
659}

Referenced by eval(), MyEvaluator::evaluate(), and MyEvaluator::isOK().


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