74 bool Or(
bool a,
bool b) {
return a || b; }
75 static const TFunction2<bool, bool> logOr = {
"||", 1,
Or };
77 bool And(
bool a,
bool b) {
return a && b; }
78 static const TFunction2<bool, bool> logAnd = {
"&&", 2,
And };
80 bool Le(
double a,
double b) {
return a <= b; }
81 static const TFunction2<bool, double> lessEqual = {
"<=", 3,
Le } ;
83 bool Lt(
double a,
double b) {
return a < b; }
84 static const TFunction2<bool, double> less = {
"<", 3,
Lt } ;
86 bool Ge(
double a,
double b) {
return a >= b; }
87 static const TFunction2<bool, double> greaterEqual = {
">=", 3,
Ge } ;
89 bool Gt(
double a,
double b) {
return a > b; }
90 static const TFunction2<bool, double> greater = {
">", 3,
Gt } ;
92 bool Eq(
double a,
double b) {
return a == b; }
93 static const TFunction2<bool, double> equal = {
"==", 3,
Eq } ;
95 bool Ne(
double a,
double b) {
return a != b; }
96 static const TFunction2<bool, double> notEqual = {
"!=", 3,
Ne } ;
105 static const TFunction1<double, double> negate = {
"-", 5,
Neg };
108 return (
a > 0.) ? 1. : (
a < 0.) ? -1. : 0.;
114 while(std::abs(x) >
a);
118 double Add(
double a,
double b) {
122 static const TFunction2<double, double> plus = {
"+", 4,
Add };
124 double Sub(
double a,
double b) {
128 static const TFunction2<double, double> minus = {
"-", 4,
Sub };
130 double Mpy(
double a,
double b) {
134 static TFunction2<double, double> times = {
"*", 5,
Mpy };
136 double Div(
double a,
double b) {
145 static TFunction2<double, double> divide = {
"/", 5,
Div };
170 static const TFunction0<double> table0[] = {
173 {
"GAUSS", -2,
gauss },
184 {
"TRUNC", -1, std::trunc },
185 {
"ROUND", -1, std::round },
186 {
"FLOOR", -1, std::floor },
187 {
"CEIL", -1, std::ceil },
188 {
"SIGN", -1,
Sign },
189 {
"SQRT", -1, std::sqrt },
190 {
"LOG", -1, std::log },
191 {
"EXP", -1, std::exp },
192 {
"SIN", -1, std::sin },
193 {
"COS", -1, std::cos },
194 {
"ABS", -1, std::abs },
195 {
"TAN", -1, std::tan },
196 {
"ASIN", -1, std::asin },
197 {
"ACOS", -1, std::acos },
198 {
"ATAN", -1, std::atan },
200 {
"ERF", -1, std::erf },
207 double Max(
double a,
double b) {
208 return std::max(
a, b);
211 double Min(
double a,
double b) {
212 return std::min(
a, b);
215 double Mod(
double a,
double b) {
216 if(b <= 0.0) errno = EDOM;
220 static TFunction2<double, double> power = {
"^", 6,
pow };
223 {
"ATAN2", -1,
atan2 },
235 double Mina(
const std::vector<double> &array) {
237 double result = array[0];
238 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
239 result =
Min(array[i], result);
243 std::cerr <<
"\n### Warning ### \"VMIN\" function of empty array.\n"
249 double Maxa(
const std::vector<double> &array) {
251 double result = array[0];
252 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
253 result = std::max(array[i], result);
257 std::cerr <<
"\n### Warning ### \"VMAX\" function of empty array.\n"
263 double Rmsa(
const std::vector<double> &array) {
266 for(std::vector<double>::size_type i = 0; i < array.size(); ++i) {
267 result += array[i] * array[i];
269 return sqrt(result /
double(array.size()));
271 std::cerr <<
"\n### Warning ### \"VRMS\" function of empty array.\n"
277 double AbsMax(
const std::vector<double> &array) {
279 double result = std::abs(array[0]);
280 for(std::vector<double>::size_type i = 1; i < array.size(); ++i) {
281 result = std::max(std::abs(array[i]), result);
285 std::cerr <<
"\n### Warning ### \"VABSMAX\" function of empty array.\n"
293 {
"VMIN", -1,
Mina },
294 {
"VMAX", -1,
Maxa },
295 {
"VRMS", -1,
Rmsa },
296 {
"VABSMAX", -1,
AbsMax },
324 (
Statement &stat,
char close, std::list<Token> &result);
397 return expr->evaluate();
402 std::string result = std::string(
"");
404 bool isWord = stat.
word(temp);
406 while(isWord || stat.
str(temp)) {
407 if(isWord && temp ==
"TO_STRING") {
411 std::ostringstream os;
419 isWord = stat.
word(temp);
423 std::string errorMsg(msg);
424 errorMsg = stat.
str() +
"\n" + errorMsg;
425 throw ParseError(
"Expressions::parseString()", errorMsg);
435 bool isWord = stat.
word(temp);
437 bool isConversion = isWord && temp ==
"TO_STRING";
439 while(stat.
str(temp) || isValidObject || isConversion) {
448 }
else if (isConversion) {
452 std::ostringstream os;
464 isWord = stat.
word(temp);
466 isConversion = isWord && temp ==
"TO_STRING";
470 std::string errorMsg(msg);
471 errorMsg = stat.
str() +
"\n" + errorMsg;
472 throw ParseError(
"Expressions::parseStringValue()", errorMsg);
533 std::vector<double> value =
arg->evaluate();
545 std::vector<std::string> array;
565 throw ParseError(
"Expressions::parseDelimiter()",
566 std::string(
"Delimiter '") + delim +
"' expected.");
573 throw ParseError(
"Expressions::parseDelimiter()",
574 std::string(
"Delimiter '") + delim +
"' expected.");
587 static char msg[] =
"Expected 'S' or 'E' after '#'.";
593 throw ParseError(
"Expression::parsePlace()", msg);
603 if(occurrence <= 0) {
605 "Occurrence counter must be positive.");
630 std::string objName =
parseString(stat,
"Object name expected.");
633 std::string attrName;
637 attrName =
parseString(stat,
"Attribute name expected.");
648 throw ParseError(
"Expressions::parseReference()",
649 "Index must be positive.");
659 std::string tabName =
parseString(stat,
"Table name expected.");
678 std::list<Token> result;
680 while(!stat.
atEnd()) {
693 result.push_back(token);
695 if(token.
isDel(
'(')) {
697 }
else if(token.
isDel(
'[')) {
699 }
else if(token.
isDel(
'{')) {
709 std::vector<std::list<Token> > array;
768 }
else if(stat.
keyword(
"COLUMN")) {
770 }
else if(stat.
keyword(
"ROW")) {
772 }
else if(stat.
keyword(
"TABLE")) {
774 }
else if(stat.
real(value)) {
779 std::string frstName =
parseString(stat,
"Object name expected.");
790 find(table1, frstName)) {
793 }
else if(frstName ==
"EVAL") {
799 }
else if(
const ArrayFun *fun =
find(tablea, frstName)) {
806 "Invalid array function name \"" + frstName +
811 std::string scndName =
parseString(stat,
"Attribute name expected.");
818 result =
new ARow(frstName, row, cols);
821 "Expected a column name.");
855 throw ParseError(
"Expressions::parseBracketList()",
856 "Parentheses, brackets or braces do not nest.");
860 result.push_back(token);
862 if(token.
isDel(
'(')) {
864 }
else if(token.
isDel(
'[')) {
866 }
else if(token.
isDel(
'{')) {
868 }
else if(token.
isDel(close)) {
898 }
else if(stat.
real(value)) {
906 std::string frstName =
parseString(stat,
"Real primary expected.");
916 find(table1, frstName)) {
919 }
else if(frstName ==
"EVAL") {
923 }
else if(
const ArrayFun *fun =
find(tablea, frstName)) {
928 "Unknown function name \"" + frstName +
"\".");
933 std::string scndName =
934 parseString(stat,
"Attribute or element name expected.");
950 std::string col =
parseString(stat,
"Column name expected.");
951 result =
new SCell(frstName, row, col);
954 "Expected a column name.");
991 }
else if(stat.
boolean(value)) {
1009 code = &greaterEqual;
1018 "Invalid boolean expression.");
1054 std::string tabName =
parseString(stat,
"Table name expected.");
1058 std::string colName =
parseString(stat,
"Column name expected.");
1067 return new AColumn(tabName, colName, range);
1077 std::string tabName =
parseString(stat,
"Table name expected.");
1084 std::vector<std::string> columns;
1090 return new ARow(tabName, row, columns);
1116 throw ParseError(
"Expressions::parseTableGenerator()",
1117 "Index set incorrect or missing.");
1121 if(frst <= 0 || last <= 0 || step <= 0) {
1122 throw ParseError(
"Expressions::parseTableGenerator()",
1123 "Invalid array index set.");
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
Field< T, 1U, Cartesian< 1U, MFLOAT >, Cell > & Div(Field< Vektor< T, 1U >, 1U, Cartesian< 1U, MFLOAT >, Vert > &x, Field< T, 1U, Cartesian< 1U, MFLOAT >, Cell > &r)
PETE_TBTree< FnFmod, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > fmod(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Representation objects and parsers for attribute expressions.
std::string parseStringValue(Statement &, const char msg[])
double Add(double a, double b)
PtrToScalar< bool > parseBool(Statement &)
Parse boolean expression.
bool Ge(double a, double b)
TFunction1< double, const std::vector< double > & > ArrayFun
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
OwnPtr< ATable > currentArray
bool Lt(double a, double b)
double Min(double a, double b)
PtrToArray< double > parseArrayTerm(Statement &stat)
double Max(double a, double b)
PtrToScalar< bool > parseAnd(Statement &stat)
double Div(double a, double b)
PtrToScalar< double > parseTerm(Statement &stat)
bool Eq(double a, double b)
PtrToArray< double > parseRealConstArray(Statement &)
Parse real array constant.
double Rmsa(const std::vector< double > &array)
PtrToArray< double > parseRowGenerator(Statement &stat)
double Mod(double a, double b)
std::vector< std::string > parseStringArray(Statement &)
Parse string array.
RangeRep parseRange(Statement &)
Parse range specification.
PlaceRep parsePlace(Statement &)
Parse place specification.
const T * find(const T table[], const std::string &name)
Look up name.
double Maxa(const std::vector< double > &array)
bool Ne(double a, double b)
SRefAttr< double > * parseReference(Statement &)
Parse variable reference.
std::vector< std::list< Token > > parseTokenListArray(Statement &)
Parse a token list array (for LIST commands).
PtrToArray< double > parseRealArray(Statement &)
Parse real array expression.
PtrToArray< double > parseArrayFactor(Statement &stat)
PtrToArray< double > parseTableGenerator(Statement &stat)
PtrToScalar< double > parseTableExpression(Statement &, const Table *)
Parse table expression (depends on a table's rows).
std::list< Token > parseTokenList(Statement &)
Parse a token list (for macro argument and the like).
double Mpy(double a, double b)
double AbsMax(const std::vector< double > &array)
TableRowRep parseTableRow(Statement &)
Parse a token list (for macro argument and the like).
std::string parseString(Statement &, const char msg[])
Parse string value.
PtrToScalar< bool > parseRelation(Statement &stat)
void parseBracketList(Statement &stat, char close, std::list< Token > &result)
PtrToArray< double > parseArrayPrimary(Statement &stat)
const Table * currentTable
double Mina(const std::vector< double > &array)
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
PtrToScalar< double > parsePrimary(Statement &stat)
double Sub(double a, double b)
double parseRealConst(Statement &)
Parse real constant.
PtrToArray< bool > parseBoolArray(Statement &)
Parse boolean array expression.
PtrToArray< double > parseColumnGenerator(Statement &stat)
bool Gt(double a, double b)
bool Le(double a, double b)
PtrToScalar< double > parseFactor(Statement &stat)
A function of two U's returning a T.
A function of one U, returning a T.
An operand-less function returning a T.
A pointer to a scalar expression.
An array of pointers to scalar expressions.
A pointer to an array expression.
An attribute defined as a reference to a scalar.
The base class for all OPAL objects.
double get_meanKineticEnergy() const
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
PartBunchBase< double, 3 > * getPartBunch()
Representation of a place within a beam line or sequence.
void append(const std::string &, int occur)
Add a name/occurrence pair.
Representation of a range within a beam line or sequence.
The base class for all OPAL tables.
Representation of a table row reference.
A pointer which owns the object pointed at.
bool isValid() const
Test for validity.
Interface for statements.
Token & getCurrent()
Return current token and skip it.
bool str(std::string &value)
Return string value.
void restore()
Return to marked position.
bool keyword(const char *s)
Test for keyword.
void mark()
Mark position in command.
bool word(std::string &value)
Return word value.
bool boolean(bool &value)
Return boolean value.
bool real(double &value)
Return real value.
bool atEnd() const
Test for end of command.
bool delimiter(char c)
Test for delimiter.
Representation of a single input token.
bool isDel(char del) const
Test for delimiter.
An array expression with two array operands.
An array expression defined as a table column.
An array expression defined by a list of scalar expressions.
An expression defined as a reference to an array.
An array expression defined as a table row.
A scalar expression with one array operand.
An array expression generated from a TABLE() function.
An array expression with one array operand.
A scalar expression to retrieve an indexed component from an array.
static Scalar< T > * make(const TFunction2< T, U > &, PtrToScalar< U > left, PtrToScalar< U > right)
Make a new expression.
A scalar expression referring to a table cell.
A scalar constant expression.
static double arcIn()
Return arc length at entrance SI().
static double arcOut()
Return arc length at exit SO().
static double arcCtr()
Return arc length at center SC().
static Scalar< T > * make(const TFunction0< T > &function)
Make expression.
An expression defined as a reference to a scalar.
static Scalar< T > * make(const TFunction1< T, U > &function, PtrToScalar< U > operand)
Make a new expression.
virtual bool getBool() const
Return value.
virtual std::string getString() const
Return value.