72 bool Or(
bool a,
bool b) {
77 bool And(
bool a,
bool b) {
82 bool Le(
double a,
double b) {
87 bool Lt(
double a,
double b) {
92 bool Ge(
double a,
double b) {
97 bool Gt(
double a,
double b) {
102 bool Eq(
double a,
double b) {
107 bool Ne(
double a,
double b) {
122 return (a > 0.) ? 1. : (a < 0.) ? -1. : 0.;
129 }
while (std::abs(x) > a);
133 double Add(
double a,
double b) {
139 double Sub(
double a,
double b) {
145 double Mpy(
double a,
double b) {
151 double Div(
double a,
double b) {
169 std::cout <<
"PartBuch valid" <<
std::endl;
171 std::cout <<
"PartBuch not valid" <<
std::endl;
193 {
"GAUSS", -2,
gauss},
203 {
"TRUNC", -1, std::trunc}, {
"ROUND", -1, std::round}, {
"FLOOR", -1, std::floor},
204 {
"CEIL", -1, std::ceil}, {
"SIGN", -1,
Sign}, {
"SQRT", -1, std::sqrt},
205 {
"LOG", -1, std::log}, {
"EXP", -1, std::exp}, {
"SIN", -1, std::sin},
206 {
"COS", -1, std::cos}, {
"ABS", -1, std::abs}, {
"TAN", -1, std::tan},
207 {
"ASIN", -1, std::asin}, {
"ACOS", -1, std::acos}, {
"ATAN", -1, std::atan},
208 {
"TGAUSS", -2,
Tgauss}, {
"ERF", -1, std::erf}, {0, -1, 0}};
213 double Max(
double a,
double b) {
217 double Min(
double a,
double b) {
221 double Mod(
double a,
double b) {
230 {
"MIN", -1,
Min}, {
"MOD", -1,
Mod},
231 {
"POW", -2, pow}, {0, -1, 0}};
236 double Mina(
const std::vector<double>& array) {
238 double result = array[0];
240 result =
Min(array[i], result);
244 std::cerr <<
"\n### Warning ### \"VMIN\" function of empty array.\n" <<
std::endl;
249 double Maxa(
const std::vector<double>& array) {
251 double result = array[0];
253 result =
std::max(array[i], result);
257 std::cerr <<
"\n### Warning ### \"VMAX\" function of empty array.\n" <<
std::endl;
262 double Rmsa(
const std::vector<double>& array) {
266 result += array[i] * array[i];
268 return sqrt(result /
double(array.size()));
270 std::cerr <<
"\n### Warning ### \"VRMS\" function of empty array.\n" <<
std::endl;
275 double AbsMax(
const std::vector<double>& array) {
277 double result = std::abs(array[0]);
279 result =
std::max(std::abs(array[i]), result);
283 std::cerr <<
"\n### Warning ### \"VABSMAX\" function of empty array.\n" <<
std::endl;
391 std::string result = std::string(
"");
393 bool isWord = stat.
word(temp);
395 while (isWord || stat.
str(temp)) {
396 if (isWord && temp ==
"TO_STRING") {
400 std::ostringstream os;
409 isWord = stat.
word(temp);
412 if (result.empty()) {
413 std::string errorMsg(msg);
414 errorMsg = stat.
str() +
"\n" + errorMsg;
415 throw ParseError(
"Expressions::parseString()", errorMsg);
425 bool isWord = stat.
word(temp);
427 bool isConversion = isWord && temp ==
"TO_STRING";
429 while (stat.
str(temp) || isValidObject || isConversion) {
438 }
else if (isConversion) {
442 std::ostringstream os;
454 isWord = stat.
word(temp);
456 isConversion = isWord && temp ==
"TO_STRING";
459 if (result.empty()) {
460 std::string errorMsg(msg);
461 errorMsg = stat.
str() +
"\n" + errorMsg;
462 throw ParseError(
"Expressions::parseStringValue()", errorMsg);
521 std::vector<double> value = arg->evaluate();
532 std::vector<std::string> array;
552 "Expressions::parseDelimiter()",
553 std::string(
"Delimiter '") + delim +
"' expected.");
560 "Expressions::parseDelimiter()",
561 std::string(
"Delimiter '") + delim +
"' expected.");
566 if (stat.
keyword(
"SELECTED")) {
573 static char msg[] =
"Expected 'S' or 'E' after '#'.";
576 }
else if (stat.
keyword(
"E")) {
579 throw ParseError(
"Expression::parsePlace()", msg);
583 std::string name =
parseString(stat,
"Expected <name> or '#'.");
589 if (occurrence <= 0) {
591 "Expressions::parsePlace()",
592 "Occurrence counter must be positive.");
595 pos.
append(name, occurrence);
616 std::string objName =
parseString(stat,
"Object name expected.");
619 std::string attrName;
623 attrName =
parseString(stat,
"Attribute name expected.");
634 throw ParseError(
"Expressions::parseReference()",
"Index must be positive.");
643 std::string tabName =
parseString(stat,
"Table name expected.");
659 std::list<Token> result;
661 while (!stat.
atEnd()) {
668 || token.
isDel(
'}')) {
674 result.push_back(token);
676 if (token.
isDel(
'(')) {
678 }
else if (token.
isDel(
'[')) {
680 }
else if (token.
isDel(
'{')) {
689 std::vector<std::list<Token> > array;
745 }
else if (stat.
keyword(
"COLUMN")) {
747 }
else if (stat.
keyword(
"ROW")) {
749 }
else if (stat.
keyword(
"TABLE")) {
751 }
else if (stat.
real(value)) {
756 std::string frstName =
parseString(stat,
"Object name expected.");
769 }
else if (frstName ==
"EVAL") {
782 "parseArrayPrimary()",
"Invalid array function name \"" + frstName +
"\".");
786 std::string scndName =
parseString(stat,
"Attribute name expected.");
793 result =
new ARow(frstName, row, cols);
795 throw ParseError(
"Expressions::parseReal()",
"Expected a column name.");
828 "Expressions::parseBracketList()",
829 "Parentheses, brackets or braces do not nest.");
833 result.push_back(token);
835 if (token.
isDel(
'(')) {
837 }
else if (token.
isDel(
'[')) {
839 }
else if (token.
isDel(
'{')) {
841 }
else if (token.
isDel(close)) {
869 }
else if (stat.
real(value)) {
877 std::string frstName =
parseString(stat,
"Real primary expected.");
889 }
else if (frstName ==
"EVAL") {
898 "parsePrimary()",
"Unknown function name \"" + frstName +
"\".");
903 std::string scndName =
parseString(stat,
"Attribute or element name expected.");
918 std::string col =
parseString(stat,
"Column name expected.");
919 result =
new SCell(frstName, row, col);
921 throw ParseError(
"Expressions::parseReal()",
"Expected a column name.");
957 }
else if (stat.
boolean(value)) {
983 throw ParseError(
"parseRelation()",
"Invalid boolean expression.");
1017 std::string tabName =
parseString(stat,
"Table name expected.");
1021 std::string colName =
parseString(stat,
"Column name expected.");
1030 return new AColumn(tabName, colName, range);
1039 std::string tabName =
parseString(stat,
"Table name expected.");
1046 std::vector<std::string> columns;
1052 return new ARow(tabName, row, columns);
1079 "Expressions::parseTableGenerator()",
"Index set incorrect or missing.");
1083 if (frst <= 0 || last <= 0 || step <= 0) {
1084 throw ParseError(
"Expressions::parseTableGenerator()",
"Invalid array index set.");
ippl::detail::size_type size_type
constexpr KOKKOS_INLINE_FUNCTION auto second()
constexpr KOKKOS_INLINE_FUNCTION auto first()
Inform & endl(Inform &inf)
Representation objects and parsers for attribute expressions.
std::string parseStringValue(Statement &, const char msg[])
static const TFunction2< bool, double > notEqual
static const TFunction2< double, double > minus
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)
static const TFunction2< double, double > plus
double Max(double a, double b)
static TFunction0< double > table0[]
static const TFunction2< bool, double > lessEqual
static const TFunction1< double, double > negate
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.
static const TFunction2< bool, double > equal
static const TFunction2< bool, double > greaterEqual
double Maxa(const std::vector< double > &array)
static const TFunction2< bool, double > greater
static const ArrayFun tablea[]
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)
static const TFunction2< bool, bool > logOr
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.
static const TFunction2< bool, bool > logAnd
static TFunction2< double, double > divide
PtrToScalar< double > parsePrimary(Statement &stat)
double Sub(double a, double b)
double parseRealConst(Statement &)
Parse real constant.
static const TFunction2< bool, double > less
static TFunction2< double, double > times
PtrToArray< bool > parseBoolArray(Statement &)
Parse boolean array expression.
static const TFunction2< double, double > table2[]
PtrToArray< double > parseColumnGenerator(Statement &stat)
bool Gt(double a, double b)
bool Le(double a, double b)
static const TFunction1< double, double > table1[]
PtrToScalar< double > parseFactor(Statement &stat)
static TFunction2< double, double > power
KOKKOS_INLINE_FUNCTION Vector< T, Dim > max(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
KOKKOS_INLINE_FUNCTION Vector< T, Dim > min(const Vector< T, Dim > &a, const Vector< T, Dim > &b)
virtual T evaluate() const =0
Evaluate.
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.
PartBunch_t * getPartBunch()
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
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.
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
Representation of a table row reference.
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().
A scalar expression without operands.
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.
An operand-less function returning a T.
A function of one U, returning a T.
A function of two U's returning a T.
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.
void gauss(double &gr1, double &gr2)
Gaussian distribution.
double uniform()
Uniform distribution.
virtual bool getBool() const
Return value.
virtual std::string getString() const
Return value.