20 #include "OPALrevision.h"
23 #include <boost/regex.hpp>
34 return std::string(GIT_VERSION);
37 #define erfinv_a3 -0.140543331
38 #define erfinv_a2 0.914624893
39 #define erfinv_a1 -1.645349621
40 #define erfinv_a0 0.886226899
42 #define erfinv_b4 0.012229801
43 #define erfinv_b3 -0.329097515
44 #define erfinv_b2 1.442710462
45 #define erfinv_b1 -2.118377725
48 #define erfinv_c3 1.641345311
49 #define erfinv_c2 3.429567803
50 #define erfinv_c1 -1.62490649
51 #define erfinv_c0 -1.970840454
53 #define erfinv_d2 1.637067800
54 #define erfinv_d1 3.543889200
127 rotation = rotTheta.
conjugate() * rotation;
136 rotation = rotPhi.
conjugate() * rotation;
148 std::string output = str;
149 std::transform(output.begin(), output.end(), output.begin(), [](
const char c) {
return std::toupper(
c);});
155 std::ostringstream valueStream;
156 valueStream << std::boolalpha << b;
162 std::ostringstream output;
166 for (
size_t i = 0; i < b.size(); ++i) {
169 (i < (b.size()-1)) ? (output <<
", ") : (output <<
")");
177 std::vector<std::string> stringVec;
178 stringVec.reserve(v.size());
181 std::ostringstream output;
186 for (
auto& s: stringVec) {
190 (i < stringVec.size()) ? (output <<
", ") : (output <<
")");
198 std::filesystem::path path;
199 for (
auto entry : ilist) {
202 return path.string();
209 "Value for " + name +
210 " should be an integer but a real value was found");
214 "Value for " + name +
" should be 1 or more");
219 return std::all_of(str.begin(),
221 [](
char c) {
return std::isdigit(
c); });
231 long double t = this->
sum + y;
232 this->correction = (t - this->
sum) - y;
240 unsigned int rewindLinesSDDS(
const std::string& fileName,
double maxSPos,
bool checkForTime) {
243 std::fstream
fs(fileName.c_str(), std::fstream::in);
244 if (!
fs.is_open())
return 0;
247 std::queue<std::string> allLines;
248 unsigned int numParameters = 0;
249 unsigned int numColumns = 0;
250 unsigned int sposColumnNr = 0;
251 unsigned int timeColumnNr = 0;
252 double spos, time = 0.0;
253 double lastTime = -1.0;
256 boost::regex column(
"&column");
257 boost::regex data(
"&data");
258 boost::regex
end(
"&end");
259 boost::regex
name(
"name=([a-zA-Z0-9\\$_]+)");
262 std::istringstream linestream;
264 while (std::getline(
fs, line)) {
269 fs.open (fileName.c_str(), std::fstream::out);
271 if (!
fs.is_open())
return 0;
274 line = allLines.front();
277 if (boost::regex_search(line, match, parameters)) {
279 while (!boost::regex_search(line, match, end)) {
280 line = allLines.front();
284 }
else if (boost::regex_search(line, match, column)) {
286 while (!boost::regex_search(line, match, name)) {
287 line = allLines.front();
291 if (match[1] ==
"s") {
292 sposColumnNr = numColumns;
294 if (match[1] ==
"t") {
295 timeColumnNr = numColumns;
297 while (!boost::regex_search(line, match, end)) {
298 line = allLines.front();
303 }
while (!boost::regex_search(line, match, data));
305 while (!boost::regex_search(line, match, end)) {
306 line = allLines.front();
311 for (
unsigned int i = 0; i < numParameters; ++ i) {
312 fs << allLines.front() <<
"\n";
316 while (!allLines.empty()) {
317 line = allLines.front();
319 linestream.str(line);
321 for (
unsigned int i = 0; i < timeColumnNr; ++ i) {
326 linestream.str(line);
327 for (
unsigned int i = 0; i < sposColumnNr; ++ i) {
335 if (!checkForTime || (time - lastTime) > 1
e-20)
343 if (!allLines.empty())
344 INFOMSG(
level2 <<
"rewind " + fileName +
" to " + std::to_string(maxSPos) <<
" m" <<
endl);
346 return allLines.size();
376 static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
377 "abcdefghijklmnopqrstuvwxyz"
380 static inline bool is_base64(
unsigned char c) {
381 return (std::isalnum(c) || (c ==
'+') || (c ==
'/'));
385 const char* bytes_to_encode = string_to_encode.c_str();
386 unsigned int in_len = string_to_encode.size();
390 unsigned char char_array_3[3];
391 unsigned char char_array_4[4];
394 char_array_3[i++] = *(bytes_to_encode++);
396 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
397 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
398 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
399 char_array_4[3] = char_array_3[2] & 0x3f;
401 for (i = 0; (i <4) ; i++)
402 ret += base64_chars[char_array_4[i]];
409 for (j = i; j < 3; j++)
410 char_array_3[j] =
'\0';
412 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
413 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
414 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
415 char_array_4[3] = char_array_3[2] & 0x3f;
417 for (j = 0; (j < i + 1); j++)
418 ret += base64_chars[char_array_4[j]];
429 int in_len = encoded_string.size();
433 unsigned char char_array_4[4], char_array_3[3];
436 while (in_len-- && ( encoded_string[in_] !=
'=') && is_base64(encoded_string[in_])) {
437 char_array_4[i++] = encoded_string[in_]; in_++;
439 for (i = 0; i <4; i++)
440 char_array_4[i] = base64_chars.find(char_array_4[i]);
442 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
443 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
444 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
446 for (i = 0; (i < 3); i++)
447 ret += char_array_3[i];
453 for (j = i; j <4; j++)
456 for (j = 0; j <4; j++)
457 char_array_4[j] = base64_chars.find(char_array_4[j]);
459 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
460 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
461 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
463 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
Tps< T > sqrt(const Tps< T > &x)
Square root.
constexpr double c
The velocity of light in m/s.
std::string boolVectorToUpperString(const std::vector< bool > &b)
Quaternion conjugate() const
Vector_t rotate(const Vector_t &) const
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &)
constexpr double two_pi
The value of .
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
FTps< T, N > erf(const FTps< T, N > &x, int trunc=(FTps< T, N >::EXACT))
Error function.
std::string boolToUpperString(const bool &b)
std::string getGitRevision()
Vektor< double, 3 > Vector_t
unsigned int rewindLinesSDDS(const std::string &fileName, double maxSPos, bool checkForTime)
rewind the SDDS file such that the spos of the last step is less or equal to maxSPos ...
Tps< T > exp(const Tps< T > &x)
Exponential.
std::string base64_encode(const std::string &string_to_encode)
clearpage the user may choose between constant or variable radius This model includes fringe fields begin
std::string toUpper(const std::string &str)
Inform & endl(Inform &inf)
PETE_TBTree< FnArcTan2, PETE_Scalar< Vektor< T1, Dim > >, typename T2::PETE_Expr_t > atan2(const Vektor< T1, Dim > &l, const PETE_Expr< T2 > &r)
T euclidean_norm(const Vector< T > &)
Euclidean norm.
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
The base class for all OPAL exceptions.
bool isAllDigits(const std::string &str)
having only three parameters(the centre length $s_0 $and the fringe field lengths $\lambda_{left}$,$\lambda_{right}$)
Tps< T > cos(const Tps< T > &x)
Cosine.
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 > log(const Tps< T > &x)
Natural logarithm.
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string doubleVectorToString(const std::vector< double > &v)
constexpr double e
The value of .
Inform & level2(Inform &inf)
Tps< T > sin(const Tps< T > &x)
Sine.
void checkInt(double real, std::string name, double tolerance)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
std::string base64_decode(std::string const &encoded_string)
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
KahanAccumulation & operator+=(double value)