19#include "OPALrevision.h"
22#include <boost/filesystem.hpp>
23#include <boost/regex.hpp>
33 return std::string(GIT_VERSION);
36#define erfinv_a3 -0.140543331
37#define erfinv_a2 0.914624893
38#define erfinv_a1 -1.645349621
39#define erfinv_a0 0.886226899
41#define erfinv_b4 0.012229801
42#define erfinv_b3 -0.329097515
43#define erfinv_b2 1.442710462
44#define erfinv_b1 -2.118377725
47#define erfinv_c3 1.641345311
48#define erfinv_c2 3.429567803
49#define erfinv_c1 -1.62490649
50#define erfinv_c0 -1.970840454
52#define erfinv_d2 1.637067800
53#define erfinv_d1 3.543889200
80 double y = std::sqrt(-std::log((1 - x) / 2));
88 r -= (std::erf(r) - x) / (2 / std::sqrt(M_PI) * std::exp(-r * r));
89 r -= (std::erf(r) - x) / (2 / std::sqrt(M_PI) * std::exp(-r * r));
124 Quaternion rotTheta(std::cos(0.5 * theta), 0, std::sin(0.5 * theta), 0);
125 rotation = rotTheta.
conjugate() * rotation;
133 Quaternion rotPhi(std::cos(0.5 * phi), std::sin(0.5 * phi), 0, 0);
134 rotation = rotPhi.
conjugate() * rotation;
146 std::string output = str;
147 std::transform(output.begin(), output.end(), output.begin(), [](
const char c) {
148 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 boost::filesystem::path path;
199 for (
auto entry : ilist) {
202 return path.string();
210 long double t = this->
sum + y;
211 this->correction = (t - this->
sum) - y;
219 unsigned int rewindLinesSDDS(
const std::string& fileName,
double maxSPos,
bool checkForTime) {
223 std::fstream fs(fileName.c_str(), std::fstream::in);
228 std::queue<std::string> allLines;
229 unsigned int numParameters = 0;
230 unsigned int numColumns = 0;
231 unsigned int sposColumnNr = 0;
232 unsigned int timeColumnNr = 0;
233 double spos, time = 0.0;
234 double lastTime = -1.0;
236 boost::regex parameters(
"¶meter");
237 boost::regex column(
"&column");
238 boost::regex data(
"&data");
239 boost::regex
end(
"&end");
240 boost::regex name(
"name=([a-zA-Z0-9\\$_]+)");
243 std::istringstream linestream;
245 while (std::getline(fs, line)) {
250 fs.open(fileName.c_str(), std::fstream::out);
256 line = allLines.front();
259 if (boost::regex_search(line, match, parameters)) {
261 while (!boost::regex_search(line, match,
end)) {
262 line = allLines.front();
266 }
else if (boost::regex_search(line, match, column)) {
268 while (!boost::regex_search(line, match, name)) {
269 line = allLines.front();
273 if (match[1] ==
"s") {
274 sposColumnNr = numColumns;
276 if (match[1] ==
"t") {
277 timeColumnNr = numColumns;
279 while (!boost::regex_search(line, match,
end)) {
280 line = allLines.front();
285 }
while (!boost::regex_search(line, match, data));
287 while (!boost::regex_search(line, match,
end)) {
288 line = allLines.front();
293 for (
unsigned int i = 0; i < numParameters; ++i) {
294 fs << allLines.front() <<
"\n";
298 while (!allLines.empty()) {
299 line = allLines.front();
301 linestream.str(line);
303 for (
unsigned int i = 0; i < timeColumnNr; ++i) {
308 linestream.str(line);
309 for (
unsigned int i = 0; i < sposColumnNr; ++i) {
318 if (!checkForTime || (time - lastTime) > 1
e-20)
326 if (!allLines.empty())
327 *
ippl::Info <<
level2 <<
"rewind " + fileName +
" to " + std::to_string(maxSPos) <<
" m"
330 return allLines.size();
361 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
362 "abcdefghijklmnopqrstuvwxyz"
366 return (std::isalnum(
c) || (
c ==
'+') || (
c ==
'/'));
370 const char* bytes_to_encode = string_to_encode.c_str();
371 unsigned int in_len = string_to_encode.size();
375 unsigned char char_array_3[3];
376 unsigned char char_array_4[4];
379 char_array_3[i++] = *(bytes_to_encode++);
381 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
382 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
383 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
384 char_array_4[3] = char_array_3[2] & 0x3f;
386 for (i = 0; (i < 4); i++)
393 for (j = i; j < 3; j++)
394 char_array_3[j] =
'\0';
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 (j = 0; (j < i + 1); j++)
412 int in_len = encoded_string.size();
416 unsigned char char_array_4[4], char_array_3[3];
419 while (in_len-- && (encoded_string[in_] !=
'=') &&
is_base64(encoded_string[in_])) {
420 char_array_4[i++] = encoded_string[in_];
423 for (i = 0; i < 4; i++)
426 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
427 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
428 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
430 for (i = 0; (i < 3); i++)
431 ret += char_array_3[i];
437 for (j = i; j < 4; j++)
440 for (j = 0; j < 4; j++)
443 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
444 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
445 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
447 for (j = 0; (j < i - 1); j++)
448 ret += char_array_3[j];
PartBunch< T, Dim >::ConstIterator end(PartBunch< T, Dim > const &bunch)
PartBunch< T, Dim >::ConstIterator begin(PartBunch< T, Dim > const &bunch)
KOKKOS_INLINE_FUNCTION double euclidean_norm(const Vector_t< T, D > &v)
Inform & level2(Inform &inf)
Inform & endl(Inform &inf)
constexpr double two_pi
The value of.
constexpr double e
The value of.
constexpr double c
The velocity of light in m/s.
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string doubleVectorToString(const std::vector< double > &v)
std::string boolVectorToUpperString(const std::vector< bool > &b)
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
static const std::string base64_chars
static bool is_base64(unsigned char c)
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
std::string getGitRevision()
std::string base64_encode(const std::string &string_to_encode)
std::string boolToUpperString(const bool &b)
Vector_t< double, 3 > getTaitBryantAngles(Quaternion rotation, const std::string &)
std::unique_ptr< Inform > Info
std::unique_ptr< mpi::Communicator > Comm
Quaternion conjugate() const
ippl::Vector< double, 3 > rotate(const ippl::Vector< double, 3 > &) const
KahanAccumulation & operator+=(double value)