OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
GlobalFunctions.h
Go to the documentation of this file.
1 #ifndef __GLOBAL_FUNCTIONS_H__
2 #define __GLOBAL_FUNCTIONS_H__
3 
4 #include <string>
5 #include <cmath>
6 
7 #include "boost/tuple/tuple.hpp"
8 #include "boost/variant/get.hpp"
9 #include "boost/variant/variant.hpp"
10 
11 #include "Util/Types.h"
12 #include "Util/SDDSReader.h"
13 #include "Util/OptPilotException.h"
14 #include "Expression/Expression.h"
16 
17 namespace GlobalFunctions {
18 
19 //FIXME
20 /*
21 struct _stat_sum {
22 
23  double operator()(client::function::arguments_t args) const {
24 
25  // get all arguments
26  double start = boost::get<double>(args[0]);
27  double end = boost::get<double>(args[1]);
28  double step = boost::get<double>(args[2]);
29  std::string name = boost::get<std::string>(args[3]);
30 
31  boost::scoped_ptr<SDDSReader> sim_stats(new SDDSReader(stat_filename_));
32  try {
33  sim_stats->parseFile();
34  } catch (OptPilotException &ex) {
35  std::cout << "Caught exception: " << ex.what() << std::endl;
36  }
37 
38  double sum = 0.0;
39  bool is_valid = true;
40  for(size_t i = static_cast<size_t>(start);
41  i < static_cast<size_t>(end); i++) {
42 
43  double sim_value;
44  try {
45  sim_stats->getInterpolatedValue(i, name, sim_value);
46  } catch(OptPilotException &e) {
47  std::cout << "Exception while getting value "
48  << "from SDDS file: " << e.what()
49  << std::endl;
50  is_valid = false;
51  }
52 
53  sum += sim_value;
54  }
55 
56  return boost::make_tuple(value, is_valid);
57  }
58 };
59 */
60 
61 struct _sqrt {
63  if (args.size() != 1) {
64  throw OptPilotException("_sqrt::operator()",
65  "sqrt expects 1 arguments, " + std::to_string(args.size()) + " given");
66  }
67 
68  double value = boost::get<double>(args[0]);
69  return boost::make_tuple(sqrt(value), true);
70  }
71 };
72 
73 struct _sq {
75  if (args.size() != 1) {
76  throw OptPilotException("_sq::operator()",
77  "sq expects 1 arguments, " + std::to_string(args.size()) + " given");
78  }
79 
80  double value = boost::get<double>(args[0]);
81  return boost::make_tuple(value * value, true);
82  }
83 };
84 
85 struct _pow {
87  if (args.size() != 2) {
88  throw OptPilotException("_pow::operator()",
89  "pow expects 2 arguments, " + std::to_string(args.size()) + " given");
90  }
91 
92  double value = boost::get<double>(args[0]);
93  double exp = boost::get<double>(args[1]);
94  return boost::make_tuple(pow(value, exp), true);
95  }
96 };
97 
98 struct _exp {
100  if (args.size() != 1) {
101  throw OptPilotException("_exp::operator()",
102  "exp expects 1 arguments, " + std::to_string(args.size()) + " given");
103  }
104 
105  double value = boost::get<double>(args[0]);
106  return boost::make_tuple(exp(value), true);
107  }
108 };
109 
110 struct _log {
112  if (args.size() != 1) {
113  throw OptPilotException("_log::operator()",
114  "log expects 1 arguments, " + std::to_string(args.size()) + " given");
115  }
116 
117  double value = boost::get<double>(args[0]);
118  return boost::make_tuple(log(value), true);
119  }
120 };
121 
122 
123 
124 struct _ceil {
126  if (args.size() != 1) {
127  throw OptPilotException("_ceil::operator()",
128  "ceil expects 1 arguments, " + std::to_string(args.size()) + " given");
129  }
130 
131  double value = boost::get<double>(args[0]);
132  return boost::make_tuple(ceil(value), true);
133  }
134 };
135 
136 struct _fabs {
138  if (args.size() != 1) {
139  throw OptPilotException("_fabs::operator()",
140  "fabs expects 1 arguments, " + std::to_string(args.size()) + " given");
141  }
142 
143  double value = boost::get<double>(args[0]);
144  return boost::make_tuple(fabs(value), true);
145  }
146 };
147 
148 struct _floor {
150  if (args.size() != 1) {
151  throw OptPilotException("_floor::operator()",
152  "floor expects 1 arguments, " + std::to_string(args.size()) + " given");
153  }
154 
155  double value = boost::get<double>(args[0]);
156  return boost::make_tuple(floor(value), true);
157  }
158 };
159 
160 struct _fmod {
162  if (args.size() != 2) {
163  throw OptPilotException("_fmod::operator()",
164  "fmod expects 2 arguments, " + std::to_string(args.size()) + " given");
165  }
166 
167  double value = boost::get<double>(args[0]);
168  double val2 = boost::get<double>(args[1]);
169  return boost::make_tuple(fmod(value, val2), true);
170  }
171 };
172 
173 
174 
175 struct _sin {
177  if (args.size() != 1) {
178  throw OptPilotException("_sin::operator()",
179  "sin expects 1 arguments, " + std::to_string(args.size()) + " given");
180  }
181 
182  double value = boost::get<double>(args[0]);
183  return boost::make_tuple(sin(value), true);
184  }
185 };
186 
187 struct _asin {
189  if (args.size() != 1) {
190  throw OptPilotException("_asin::operator()",
191  "asin expects 1 arguments, " + std::to_string(args.size()) + " given");
192  }
193 
194  double value = boost::get<double>(args[0]);
195  return boost::make_tuple(asin(value), true);
196  }
197 };
198 
199 struct _cos {
201  if (args.size() != 1) {
202  throw OptPilotException("_cos::operator()",
203  "cos expects 1 arguments, " + std::to_string(args.size()) + " given");
204  }
205 
206  double value = boost::get<double>(args[0]);
207  return boost::make_tuple(cos(value), true);
208  }
209 };
210 
211 struct _acos {
213  if (args.size() != 1) {
214  throw OptPilotException("_acos::operator()",
215  "acos expects 1 arguments, " + std::to_string(args.size()) + " given");
216  }
217 
218  double value = boost::get<double>(args[0]);
219  return boost::make_tuple(acos(value), true);
220  }
221 };
222 
223 struct _tan {
225  if (args.size() != 1) {
226  throw OptPilotException("_tan::operator()",
227  "tan expects 1 arguments, " + std::to_string(args.size()) + " given");
228  }
229 
230  double value = boost::get<double>(args[0]);
231  return boost::make_tuple(tan(value), true);
232  }
233 };
234 
235 struct _atan {
237  if (args.size() != 1) {
238  throw OptPilotException("_atan::operator()",
239  "atan expects 1 arguments, " + std::to_string(args.size()) + " given");
240  }
241 
242  double value = boost::get<double>(args[0]);
243  return boost::make_tuple(atan(value), true);
244  }
245 };
246 
247 
248 static functionDictionary_t get() {
249 
250  typedef std::pair<std::string, client::function::type> funcEntry_t;
251  functionDictionary_t funcs;
252 
253  client::function::type sqrt_; sqrt_ = _sqrt();
254  funcs.insert(funcEntry_t("sqrt", sqrt_));
255  client::function::type sq_; sq_ = _sq();
256  funcs.insert(funcEntry_t("sq", sq_));
257  client::function::type pow_; pow_ = _pow();
258  funcs.insert(funcEntry_t("pow", pow_));
259  client::function::type exp_; exp_ = _exp();
260  funcs.insert(funcEntry_t("exp", exp_));
261  client::function::type log_; log_ = _log();
262  funcs.insert(funcEntry_t("log", log_));
263 
264 
265  client::function::type ceil_; ceil_ = _ceil();
266  funcs.insert(funcEntry_t("ceil", ceil_));
267  client::function::type fabs_; fabs_ = _fabs();
268  funcs.insert(funcEntry_t("fabs", fabs_));
269  client::function::type floor_; floor_ = _floor();
270  funcs.insert(funcEntry_t("floor", floor_));
271  client::function::type fmod_; fmod_ = _fmod();
272  funcs.insert(funcEntry_t("fmod", fmod_));
273 
274 
275  client::function::type sin_; sin_ = _sin();
276  funcs.insert(funcEntry_t("sin", sin_));
277  client::function::type asin_; asin_ = _asin();
278  funcs.insert(funcEntry_t("asin", asin_));
279  client::function::type cos_; cos_ = _cos();
280  funcs.insert(funcEntry_t("cos", cos_));
281  client::function::type acos_; acos_ = _acos();
282  funcs.insert(funcEntry_t("acos", acos_));
283  client::function::type tan_; tan_ = _tan();
284  funcs.insert(funcEntry_t("tan", tan_));
285  client::function::type atan_; atan_ = _atan();
286  funcs.insert(funcEntry_t("atan", atan_));
287 
288  return funcs;
289 }
290 
291 }
292 
293 #endif
PETE_TUTree< FnArcCos, typename T::PETE_Expr_t > acos(const PETE_Expr< T > &l)
Definition: PETE.h:808
Expressions::Result_t operator()(client::function::arguments_t args)
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
Definition: PETE.h:815
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
PETE_TUTree< FnCeil, typename T::PETE_Expr_t > ceil(const PETE_Expr< T > &l)
Definition: PETE.h:811
Tps< T > exp(const Tps< T > &x)
Exponential.
Definition: TpsMath.h:165
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)
Tps< T > tan(const Tps< T > &x)
Tangent.
Definition: TpsMath.h:147
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Definition: TpsMath.h:182
Expressions::Result_t operator()(client::function::arguments_t args)
boost::tuple< double, bool > Result_t
Definition: Expression.h:37
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)
PETE_TUTree< FnArcTan, typename T::PETE_Expr_t > atan(const PETE_Expr< T > &l)
Definition: PETE.h:810
std::vector< argument_t > arguments_t
Definition: function.hpp:19
Expressions::Result_t operator()(client::function::arguments_t args)
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Definition: TpsMath.h:76
PETE_TBTree< FnFmod, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > fmod(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
Tps< T > cos(const Tps< T > &x)
Cosine.
Definition: TpsMath.h:129
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
PETE_TUTree< FnArcSin, typename T::PETE_Expr_t > asin(const PETE_Expr< T > &l)
Definition: PETE.h:809
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:27
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Definition: PETE.h:816
Expressions::Result_t operator()(client::function::arguments_t args)
Expressions::Result_t operator()(client::function::arguments_t args)