70 namespace Expressions {
76 bool Or(
bool a,
bool b) {
return a || b; }
77 static const TFunction2<bool, bool> logOr = {
"||", 1,
Or };
79 bool And(
bool a,
bool b) {
return a && b; }
80 static const TFunction2<bool, bool> logAnd = {
"&&", 2,
And };
82 bool Le(
double a,
double b) {
return a <= b; }
83 static const TFunction2<bool, double> lessEqual = {
"<=", 3,
Le } ;
85 bool Lt(
double a,
double b) {
return a < b; }
86 static const TFunction2<bool, double> less = {
"<", 3,
Lt } ;
88 bool Ge(
double a,
double b) {
return a >= b; }
89 static const TFunction2<bool, double> greaterEqual = {
">=", 3,
Ge } ;
91 bool Gt(
double a,
double b) {
return a > b; }
92 static const TFunction2<bool, double> greater = {
">", 3,
Gt } ;
94 bool Eq(
double a,
double b) {
return a == b; }
95 static const TFunction2<bool, double> equal = {
"==", 3,
Eq } ;
97 bool Ne(
double a,
double b) {
return a != b; }
98 static const TFunction2<bool, double> notEqual = {
"!=", 3,
Ne } ;
107 static const TFunction1<double, double> negate = {
"-", 5,
Neg };
110 return (a > 0.) ? 1. : (a < 0.) ? -1. : 0.;
120 double Add(
double a,
double b) {
124 static const TFunction2<double, double> plus = {
"+", 4,
Add };
126 double Sub(
double a,
double b) {
130 static const TFunction2<double, double> minus = {
"-", 4,
Sub };
132 double Mpy(
double a,
double b) {
136 static TFunction2<double, double> times = {
"*", 5,
Mpy };
138 double Div(
double a,
double b) {
147 static TFunction2<double, double> divide = {
"/", 5,
Div };
172 static const TFunction0<double> table0[] = {
175 {
"GAUSS", -2,
gauss },
185 static const TFunction1<double, double> table1[] = {
187 {
"ROUND", -1,
Round },
190 {
"SIGN", -1,
Sign },
209 double Max(
double a,
double b) {
213 double Min(
double a,
double b) {
217 double Mod(
double a,
double b) {
218 if(b <= 0.0) errno = EDOM;
222 static TFunction2<double, double> power = {
"^", 6,
pow };
224 static const TFunction2<double, double> table2[] = {
225 {
"ATAN2", -1,
atan2 },
237 double Mina(
const std::vector<double> &array) {
239 double result = array[0];
240 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
241 result =
Min(array[i], result);
245 std::cerr <<
"\n### Warning ### \"VMIN\" function of empty array.\n"
251 double Maxa(
const std::vector<double> &array) {
253 double result = array[0];
254 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
255 result =
std::max(array[i], result);
259 std::cerr <<
"\n### Warning ### \"VMAX\" function of empty array.\n"
265 double Rmsa(
const std::vector<double> &array) {
268 for(std::vector<double>::size_type i = 0; i < array.size(); ++i) {
269 result += array[i] * array[i];
271 return sqrt(result /
double(array.size()));
273 std::cerr <<
"\n### Warning ### \"VRMS\" function of empty array.\n"
279 double AbsMax(
const std::vector<double> &array) {
282 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
287 std::cerr <<
"\n### Warning ### \"VABSMAX\" function of empty array.\n"
295 {
"VMIN", -1,
Mina },
296 {
"VMAX", -1,
Maxa },
297 {
"VRMS", -1,
Rmsa },
298 {
"VABSMAX", -1,
AbsMax },
326 (
Statement &stat,
char close, std::list<Token> &result);
399 return expr->evaluate();
404 std::string result = std::string(
"");
407 while(stat.
word(temp) || stat.
str(temp)) {
408 if(temp ==
"STRING") {
412 std::ostringstream os;
413 os << value << std::ends;
423 throw ParseError(
"Expressions::parseString()", msg);
485 std::vector<double> value = arg->
evaluate();
497 std::vector<std::string> array;
502 array.push_back(
parseString(stat,
"String value expected."));
508 array.push_back(
parseString(stat,
"String value expected."));
517 throw ParseError(
"Expressions::parseDelimiter()",
518 std::string(
"Delimiter '") + delim +
"' expected.");
525 throw ParseError(
"Expressions::parseDelimiter()",
526 std::string(
"Delimiter '") + delim +
"' expected.");
539 static char msg[] =
"Expected 'S' or 'E' after '#'.";
545 throw ParseError(
"Expression::parsePlace()", msg);
555 if(occurrence <= 0) {
557 "Occurrence counter must be positive.");
560 pos.
append(name, occurrence);
582 std::string objName =
parseString(stat,
"Object name expected.");
585 std::string attrName;
589 attrName =
parseString(stat,
"Attribute name expected.");
600 throw ParseError(
"Expressions::parseReference()",
601 "Index must be positive.");
611 std::string tabName =
parseString(stat,
"Table name expected.");
630 std::list<Token> result;
632 while(!stat.
atEnd()) {
645 result.push_back(token);
647 if(token.
isDel(
'(')) {
649 }
else if(token.
isDel(
'[')) {
651 }
else if(token.
isDel(
'{')) {
661 std::vector<std::list<Token> > array;
720 }
else if(stat.
keyword(
"COLUMN")) {
722 }
else if(stat.
keyword(
"ROW")) {
724 }
else if(stat.
keyword(
"TABLE")) {
726 }
else if(stat.
real(value)) {
731 std::string frstName =
parseString(stat,
"Object name expected.");
742 find(table1, frstName)) {
745 }
else if(frstName ==
"EVAL") {
751 }
else if(
const ArrayFun *fun =
find(tablea, frstName)) {
758 "Invalid array function name \"" + frstName +
763 std::string scndName =
parseString(stat,
"Attribute name expected.");
770 result =
new ARow(frstName, row, cols);
773 "Expected a column name.");
807 throw ParseError(
"Expressions::parseBracketList()",
808 "Parentheses, brackets or braces do not nest.");
812 result.push_back(token);
814 if(token.
isDel(
'(')) {
816 }
else if(token.
isDel(
'[')) {
818 }
else if(token.
isDel(
'{')) {
820 }
else if(token.
isDel(close)) {
850 }
else if(stat.
real(value)) {
858 std::string frstName =
parseString(stat,
"Real primary expected.");
868 find(table1, frstName)) {
871 }
else if(frstName ==
"EVAL") {
875 }
else if(
const ArrayFun *fun =
find(tablea, frstName)) {
880 "Unknown function name \"" + frstName +
"\".");
885 std::string scndName =
886 parseString(stat,
"Attribute or element name expected.");
902 std::string col =
parseString(stat,
"Column name expected.");
903 result =
new SCell(frstName, row, col);
906 "Expected a column name.");
943 }
else if(stat.
boolean(value)) {
948 if(stat.
word(name) &&
961 code = &greaterEqual;
970 "Invalid boolean expression.");
1006 std::string tabName =
parseString(stat,
"Table name expected.");
1010 std::string colName =
parseString(stat,
"Column name expected.");
1019 return new AColumn(tabName, colName, range);
1029 std::string tabName =
parseString(stat,
"Table name expected.");
1036 std::vector<std::string> columns;
1042 return new ARow(tabName, row, columns);
1068 throw ParseError(
"Expressions::parseTableGenerator()",
1069 "Index set incorrect or missing.");
1073 if(frst <= 0 || last <= 0 || step <= 0) {
1074 throw ParseError(
"Expressions::parseTableGenerator()",
1075 "Invalid array index set.");
double AbsMax(const std::vector< double > &array)
An expression defined as a reference to a scalar.
double Round(double value)
Round the double argument.
PtrToScalar< bool > parseRelation(Statement &stat)
void parseBracketList(Statement &stat, char close, std::list< Token > &result)
An array expression generated from a TABLE() function.
PartBunchBase< double, 3 > * getPartBunch()
A scalar expression without operands.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
PETE_TUTree< FnArcCos, typename T::PETE_Expr_t > acos(const PETE_Expr< T > &l)
double parseRealConst(Statement &)
Parse real constant.
PtrToArray< double > parseArrayTerm(Statement &stat)
bool keyword(const char *s)
Test for keyword.
bool Ge(double a, double b)
PlaceRep parsePlace(Statement &)
Parse place specification.
A scalar constant expression.
A scalar expression to retrieve an indexed component from an array.
static Scalar< T > * make(const TFunction0< T > &function)
Make expression.
void mark()
Mark position in command.
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
FTps< T, N > erf(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Error function.
A pointer to a scalar expression.
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
static double arcIn()
Return arc length at entrance SI().
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Tps< T > sin(const Tps< T > &x)
Sine.
RangeRep parseRange(Statement &)
Parse range specification.
bool Gt(double a, double b)
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
static double arcOut()
Return arc length at exit SO().
Tps< T > exp(const Tps< T > &x)
Exponential.
bool atEnd() const
Test for end of command.
double get_meanKineticEnergy() const
TFunction1< double, const std::vector< double > & > ArrayFun
double Add(double a, double b)
double Rmsa(const std::vector< double > &array)
A function of two U's returning a T.
Tps< T > tan(const Tps< T > &x)
Tangent.
PtrToArray< double > parseRowGenerator(Statement &stat)
A pointer which owns the object pointed at.
void gauss(double &gr1, double &gr2)
Gaussian distribution.
void restore()
Return to marked position.
Representation of a table row reference.
Tps< T > log(const Tps< T > &x)
Natural logarithm.
bool real(double &value)
Return real value.
double Sub(double a, double b)
SRefAttr< double > * parseReference(Statement &)
Parse variable reference.
bool Eq(double a, double b)
double Truncate(double value)
Truncate.
An attribute defined as a reference to a scalar.
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
static double arcCtr()
Return arc length at center SC().
bool word(std::string &value)
Return word value.
Representation of a place within a beam line or sequence.
static Scalar< T > * make(const TFunction1< T, U > &function, PtrToScalar< U > operand)
Make a new expression.
static OpalData * getInstance()
PtrToScalar< bool > parseBool(Statement &)
Parse boolean expression.
double Mina(const std::vector< double > &array)
bool boolean(bool &value)
Return boolean value.
A scalar expression referring to a table cell.
PtrToScalar< double > parseTerm(Statement &stat)
PtrToScalar< double > parseFactor(Statement &stat)
virtual bool getBool() const
Return value.
Random rangen
Random generator.
double Max(double a, double b)
A function of one U, returning a T.
Interface for statements.
void append(const std::string &, int occur)
Add a name/occurrence pair.
PtrToArray< double > parseColumnGenerator(Statement &stat)
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
An array expression defined as a table column.
Representation of a single input token.
double Mod(double a, double b)
double uniform()
Uniform distribution.
TableRowRep parseTableRow(Statement &)
Parse a token list (for macro argument and the like).
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
An array expression with two array operands.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
bool isValid() const
Test for validity.
Representation of a range within a beam line or sequence.
PETE_TBTree< FnFmod, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > fmod(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
bool Lt(double a, double b)
std::vector< std::string > parseStringArray(Statement &)
Parse string array.
const T * find(const T table[], const std::string &name)
Look up name.
Tps< T > sqrt(const Tps< T > &x)
Square root.
double Maxa(const std::vector< double > &array)
double Min(double a, double b)
PtrToArray< double > parseRealArray(Statement &)
Parse real array expression.
PtrToScalar< double > parseTableExpression(Statement &, const Table *)
Parse table expression (depends on a table's rows).
An array of pointers to scalar expressions.
bool Ne(double a, double b)
Object * find(const std::string &name)
Find entry.
Tps< T > cos(const Tps< T > &x)
Cosine.
const Table * currentTable
The BOOL CONSTANT definition.
An array expression with one array operand.
std::list< Token > parseTokenList(Statement &)
Parse a token list (for macro argument and the like).
bool str(std::string &value)
Return string value.
virtual std::vector< T > evaluate() const =0
Evaluate.
An expression defined as a reference to an array.
PtrToArray< double > parseTableGenerator(Statement &stat)
double Mpy(double a, double b)
Token & getCurrent()
Return current token and skip it.
PtrToArray< double > parseArrayPrimary(Statement &stat)
PETE_TUTree< FnArcSin, typename T::PETE_Expr_t > asin(const PETE_Expr< T > &l)
An operand-less function returning a T.
An array expression defined as a table row.
bool isDel(char del) const
Test for delimiter.
bool Le(double a, double b)
OwnPtr< ATable > currentArray
std::string parseString(Statement &, const char msg[])
Parse string value.
PtrToArray< double > parseRealConstArray(Statement &)
Parse real array constant.
The base class for all OPAL tables.
bool delimiter(char c)
Test for delimiter.
PtrToArray< bool > parseBoolArray(Statement &)
Parse boolean array expression.
static Scalar< T > * make(const TFunction2< T, U > &, PtrToScalar< U > left, PtrToScalar< U > right)
Make a new expression.
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
PtrToScalar< double > parsePrimary(Statement &stat)
A pointer to an array expression.
std::vector< std::list< Token > > parseTokenListArray(Statement &)
Parse a token list array (for LIST commands).
PtrToArray< double > parseArrayFactor(Statement &stat)
double Div(double a, double b)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
A scalar expression with one array operand.
PtrToScalar< bool > parseAnd(Statement &stat)
An array expression defined by a list of scalar expressions.