20#include "OPALrevision.h"
37 return std::string(GIT_VERSION);
40#define erfinv_a3 -0.140543331
41#define erfinv_a2 0.914624893
42#define erfinv_a1 -1.645349621
43#define erfinv_a0 0.886226899
45#define erfinv_b4 0.012229801
46#define erfinv_b3 -0.329097515
47#define erfinv_b2 1.442710462
48#define erfinv_b1 -2.118377725
51#define erfinv_c3 1.641345311
52#define erfinv_c2 3.429567803
53#define erfinv_c1 -1.62490649
54#define erfinv_c0 -1.970840454
56#define erfinv_d2 1.637067800
57#define erfinv_d1 3.543889200
86 double y = std::sqrt (-std::log ((1 - x) / 2));
94 r -= (std::erf (r) - x) / (2 / std::sqrt (
Physics::pi) * std::exp (-r * r));
95 r -= (std::erf (r) - x) / (2 / std::sqrt (
Physics::pi) * std::exp (-r * r));
129 Quaternion rotTheta(std::cos(0.5 * theta), 0, std::sin(0.5 * theta), 0);
130 rotation = rotTheta.
conjugate() * rotation;
138 Quaternion rotPhi(std::cos(0.5 * phi), std::sin(0.5 * phi), 0, 0);
139 rotation = rotPhi.
conjugate() * rotation;
151 std::string output = str;
152 std::transform(output.begin(), output.end(), output.begin(), [](
const char c) { return std::toupper(c);});
158 std::ostringstream valueStream;
159 valueStream << std::boolalpha << b;
165 std::ostringstream output;
169 for (
size_t i = 0; i < b.size(); ++i) {
172 (i < (b.size()-1)) ? (output <<
", ") : (output <<
")");
180 std::vector<std::string> stringVec;
181 stringVec.reserve(v.size());
182 Util::toString(std::begin(v), std::end(v), std::back_inserter(stringVec));
184 std::ostringstream output;
189 for (
auto& s: stringVec) {
193 (i < stringVec.size()) ? (output <<
", ") : (output <<
")");
201 std::filesystem::path path;
202 for (
auto entry : ilist) {
205 return path.string();
210 if (std::abs(std::floor(
real) -
real) > 2*tolerance) {
212 "Value for " +
name +
213 " should be an integer but a real value was found");
215 if (std::floor(
real) < 0.5) {
217 "Value for " +
name +
" should be 1 or more");
222 return std::all_of(str.begin(),
224 [](
char c) { return std::isdigit(c); });
234 long double t = this->
sum + y;
235 this->correction = (t - this->
sum) - y;
243 unsigned int rewindLinesSDDS(
const std::string& fileName,
double maxSPos,
bool checkForTime) {
246 std::fstream fs(fileName.c_str(), std::fstream::in);
247 if (!fs.is_open())
return 0;
250 std::queue<std::string> allLines;
251 unsigned int numParameters = 0;
252 unsigned int numColumns = 0;
253 unsigned int sposColumnNr = 0;
254 unsigned int timeColumnNr = 0;
255 double spos, time = 0.0;
256 double lastTime = -1.0;
258 std::regex parameters(
"¶meter");
259 std::regex column(
"&column");
260 std::regex data(
"&data");
261 std::regex
end(
"&end");
262 std::regex
name(
"name=([a-zA-Z0-9\\$_]+)");
265 std::istringstream linestream;
267 while (std::getline(fs, line)) {
272 fs.open (fileName.c_str(), std::fstream::out);
274 if (!fs.is_open())
return 0;
277 line = allLines.front();
280 if (std::regex_search(line, match, parameters)) {
282 while (!std::regex_search(line, match,
end)) {
283 line = allLines.front();
287 }
else if (std::regex_search(line, match, column)) {
289 while (!std::regex_search(line, match,
name)) {
290 line = allLines.front();
294 if (match[1] ==
"s") {
295 sposColumnNr = numColumns;
297 if (match[1] ==
"t") {
298 timeColumnNr = numColumns;
300 while (!std::regex_search(line, match,
end)) {
301 line = allLines.front();
306 }
while (!std::regex_search(line, match, data));
308 while (!std::regex_search(line, match,
end)) {
309 line = allLines.front();
314 for (
unsigned int i = 0; i < numParameters; ++ i) {
315 fs << allLines.front() <<
"\n";
319 while (!allLines.empty()) {
320 line = allLines.front();
322 linestream.str(line);
324 for (
unsigned int i = 0; i < timeColumnNr; ++ i) {
329 linestream.str(line);
330 for (
unsigned int i = 0; i < sposColumnNr; ++ i) {
334 if ((spos - maxSPos) > 1e-20 *
Physics::c)
break;
338 if (!checkForTime || (time - lastTime) > 1e-20)
346 if (!allLines.empty())
347 INFOMSG(
level2 <<
"rewind " + fileName +
" to " + std::to_string(maxSPos) <<
" m" <<
endl);
349 return allLines.size();
379 static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
380 "abcdefghijklmnopqrstuvwxyz"
383 static inline bool is_base64(
unsigned char c) {
384 return (std::isalnum(c) || (c ==
'+') || (c ==
'/'));
388 const char* bytes_to_encode = string_to_encode.c_str();
389 unsigned int in_len = string_to_encode.size();
393 unsigned char char_array_3[3];
394 unsigned char char_array_4[4];
397 char_array_3[i++] = *(bytes_to_encode++);
399 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
400 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
401 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
402 char_array_4[3] = char_array_3[2] & 0x3f;
404 for (i = 0; (i <4) ; i++)
405 ret += base64_chars[char_array_4[i]];
412 for (j = i; j < 3; j++)
413 char_array_3[j] =
'\0';
415 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
416 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
417 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
418 char_array_4[3] = char_array_3[2] & 0x3f;
420 for (j = 0; (j < i + 1); j++)
421 ret += base64_chars[char_array_4[j]];
432 int in_len = encoded_string.size();
436 unsigned char char_array_4[4], char_array_3[3];
439 while (in_len-- && ( encoded_string[in_] !=
'=') && is_base64(encoded_string[in_])) {
440 char_array_4[i++] = encoded_string[in_]; in_++;
442 for (i = 0; i <4; i++)
443 char_array_4[i] = base64_chars.find(char_array_4[i]);
445 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
446 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
447 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
449 for (i = 0; (i < 3); i++)
450 ret += char_array_3[i];
456 for (j = i; j <4; j++)
459 for (j = 0; j <4; j++)
460 char_array_4[j] = base64_chars.find(char_array_4[j]);
462 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
463 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
464 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
466 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
T euclidean_norm(const Vector< T > &)
Euclidean norm.
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
Inform & level2(Inform &inf)
Inform & endl(Inform &inf)
constexpr double two_pi
The value of.
constexpr double c
The velocity of light in m/s.
constexpr double pi
The value of.
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string doubleVectorToString(const std::vector< double > &v)
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &)
std::string boolVectorToUpperString(const std::vector< bool > &b)
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
std::string toUpper(const std::string &str)
std::string base64_decode(std::string const &encoded_string)
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
void checkInt(double real, std::string name, double tolerance)
std::string getGitRevision()
std::string base64_encode(const std::string &string_to_encode)
std::string boolToUpperString(const bool &b)
bool isAllDigits(const std::string &str)
Vector_t rotate(const Vector_t &) const
Quaternion conjugate() const
KahanAccumulation & operator+=(double value)
The base class for all OPAL exceptions.
Vektor< double, 3 > Vector_t