ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepTool::Evaluator Class Reference

#include <geant4/tree/geant4-10.6-release/source/externals/clhep/include/CLHEP/Evaluator/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)
 

Private Member Functions

 Evaluator (const Evaluator &)
 
Evaluatoroperator= (const Evaluator &)
 

Private Attributes

voidp
 

Detailed Description

Evaluator of arithmetic expressions with an extendable dictionary. Example:

eval.setStdMath();
double res = eval.evaluate("sin(30*degree)");
Author
Evgeni Chernyaev Evgue.nosp@m.ni.T.nosp@m.chern.nosp@m.iaev.nosp@m.@cern.nosp@m..ch

Definition at line 25 of file Evaluator.h.

View newest version in sPHENIX GitHub at line 25 of file Evaluator.h

Member Enumeration Documentation

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 38 of file Evaluator.h.

View newest version in sPHENIX GitHub at line 38 of file Evaluator.h

Constructor & Destructor Documentation

HepTool::Evaluator::Evaluator ( )

Constructor.

Definition at line 598 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 598 of file Evaluator.cc

References OK, Struct::theExpression, Struct::thePosition, Struct::theResult, and Struct::theStatus.

HepTool::Evaluator::~Evaluator ( )

Destructor.

Definition at line 608 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 608 of file Evaluator.cc

HepTool::Evaluator::Evaluator ( const Evaluator )
private

Member Function Documentation

void HepTool::Evaluator::clear ( void  )

Clear all settings.

Definition at line 764 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 764 of file Evaluator.cc

References OK, Struct::theDictionary, Struct::theExpression, Struct::thePosition, Struct::theResult, and Struct::theStatus.

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

+ Here is the caller graph for this function:

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

get a string defining the error name

Definition at line 652 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 652 of file Evaluator.cc

References ERROR_CALCULATION_ERROR, ERROR_EMPTY_PARAMETER, ERROR_NOT_A_NAME, ERROR_SYNTAX_ERROR, ERROR_UNEXPECTED_SYMBOL, ERROR_UNKNOWN_FUNCTION, ERROR_UNKNOWN_VARIABLE, ERROR_UNPAIRED_PARENTHESIS, and Struct::theStatus.

Referenced by print_error().

+ Here is the caller graph for this function:

int HepTool::Evaluator::error_position ( ) const

Returns position in the input string where the problem occured.

Definition at line 638 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 638 of file Evaluator.cc

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 613 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 613 of file Evaluator.cc

References engine, Struct::theDictionary, Struct::theExpression, Struct::thePosition, Struct::theResult, Struct::theStatus, and WARNING_BLANK_STRING.

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrUtils::GetDouble().

+ Here is the caller graph for this function:

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 734 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 734 of file Evaluator.cc

References MAX_N_PAR, n, REMOVE_BLANKS, sss, and Struct::theDictionary.

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 723 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 723 of file Evaluator.cc

References n, REMOVE_BLANKS, and Struct::theDictionary.

Referenced by G4GDMLEvaluator::DefineConstant(), G4GDMLEvaluator::DefineVariable(), and G4GDMLEvaluator::GetConstant().

+ Here is the caller graph for this function:

Evaluator& HepTool::Evaluator::operator= ( const Evaluator )
private
void HepTool::Evaluator::print_error ( ) const

Prints error message if status() is an ERROR.

Definition at line 643 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 643 of file Evaluator.cc

References error_name(), OK, and Struct::theStatus.

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrEvaluator::print_error().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 754 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 754 of file Evaluator.cc

References MAX_N_PAR, n, REMOVE_BLANKS, sss, and Struct::theDictionary.

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

Removes the variable from the dictionary.

Parameters
namename of the variable.

Definition at line 745 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 745 of file Evaluator.cc

References n, REMOVE_BLANKS, and Struct::theDictionary.

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 698 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 698 of file Evaluator.cc

References setItem().

Referenced by G4tgrEvaluator::AddCommonFunctions(), and setStdMath().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 702 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 702 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

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 706 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 706 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

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 710 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 710 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

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 714 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 714 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

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 718 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 718 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

void HepTool::Evaluator::setStdMath ( )

Sets standard mathematical functions and constants.

Definition at line 29 of file setStdMath.cc.

View newest version in sPHENIX GitHub at line 29 of file setStdMath.cc

References eval_abs(), eval_acos(), eval_asin(), eval_atan(), eval_atan2(), eval_cos(), eval_cosh(), eval_exp(), eval_log(), eval_log10(), eval_max(), eval_min(), eval_pow(), eval_sin(), eval_sinh(), eval_sqrt(), eval_tan(), eval_tanh(), setFunction(), and setVariable().

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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);

The basic units in GEANT4 are:

Mega electron Volt (MeV = 1.)
degree Kelvin (kelvin = 1.)
the amount of substance (mole = 1.)
luminous intensity (candela = 1.)
radian (radian = 1.)

Definition at line 8 of file setSystemOfUnits.cc.

View newest version in sPHENIX GitHub at line 8 of file setSystemOfUnits.cc

References A(), ampere, bar, barn, Bq, C(), candela, cd, cm, deg, e, e_SI, eV, F, Acts::UnitConstants::g, H, kelvin, kg, kilogram, km, L, m, meter, mm, mole, N, ohm, pi, rad, S(), second, setVariable(), sr, and T.

Referenced by G4GDMLEvaluator::Clear(), and G4GDMLEvaluator::G4GDMLEvaluator().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 689 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 689 of file Evaluator.cc

References setItem().

Referenced by G4GDMLEvaluator::DefineConstant(), G4GDMLEvaluator::DefineVariable(), setStdMath(), setSystemOfUnits(), and G4GDMLEvaluator::SetVariable().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 692 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 692 of file Evaluator.cc

References setItem().

+ Here is the call graph for this function:

int HepTool::Evaluator::status ( ) const

Returns status of the last operation with the evaluator.

Definition at line 633 of file Evaluator.cc.

View newest version in sPHENIX GitHub at line 633 of file Evaluator.cc

Referenced by G4GDMLEvaluator::Evaluate(), and G4tgrUtils::GetDouble().

+ Here is the caller graph for this function:

Member Data Documentation

void* HepTool::Evaluator::p
private

Definition at line 256 of file Evaluator.h.

View newest version in sPHENIX GitHub at line 256 of file Evaluator.h


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