27#include <initializer_list>
35#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
36#define __DBGMSG__ __FILENAME__ << ": " << __LINE__ << "\t"
44 inline double getGamma(ippl::Vector<double, 3> p) {
46 for (
unsigned i = 0; i < 3; i++)
48 return std::sqrt(dotP + 1.0);
51 inline ippl::Vector<double, 3>
getBeta(ippl::Vector<double, 3> p) {
60 double value = std::sqrt(std::pow(Ekin / mass + 1.0, 2) - 1.0);
61 if (value < std::numeric_limits<double>::epsilon())
62 value = std::sqrt(2 * Ekin / mass);
70 inline std::string
getTimeString(
double time,
unsigned int precision = 3) {
71 std::string timeUnit(
" [ps]");
74 if (std::abs(time) > 1000) {
76 timeUnit = std::string(
" [ns]");
78 if (std::abs(time) > 1000) {
80 timeUnit = std::string(
" [ms]");
82 }
else if (std::abs(time) < 1.0) {
84 timeUnit = std::string(
" [fs]");
87 std::stringstream timeOutput;
88 timeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << time
90 return timeOutput.str();
94 std::string sposUnit(
" [m]");
96 if (std::abs(spos) < 1.0) {
98 sposUnit = std::string(
" [mm]");
101 if (std::abs(spos) < 1.0) {
103 sposUnit = std::string(
" [um]");
106 std::stringstream positionOutput;
107 positionOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
109 return positionOutput.str();
112 inline std::string
getLengthString(ippl::Vector<double, 3> spos,
unsigned int precision = 3) {
113 std::string sposUnit(
" [m]");
114 double maxPos = std::abs(spos(0));
115 for (
unsigned int i = 1; i < 3u; ++i) {
116 maxPos = std::max(maxPos, std::abs(spos(i)));
119 std::stringstream positionOutput;
123 spos = spos * 1000.0;
124 sposUnit = std::string(
" [mm]");
129 spos = spos * 1000.0;
130 sposUnit = std::string(
" [um]");
133 positionOutput << std::fixed << std::setprecision(precision) <<
"( "
134 << std::setw(precision + 7) << spos(0) <<
" , " << std::setw(precision + 7)
135 << spos(1) <<
" , " << std::setw(precision + 7) << spos(2) <<
" )"
137 return positionOutput.str();
141 std::string energyUnit(
" [MeV]");
142 double energy = energyInMeV;
144 if (energy > 1000.0) {
146 energyUnit = std::string(
" [GeV]");
147 }
else if (energy < 1.0) {
149 energyUnit = std::string(
" [keV]");
152 energyUnit = std::string(
" [eV]");
156 std::stringstream energyOutput;
157 energyOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
158 << energy << energyUnit;
160 return energyOutput.str();
164 std::string chargeUnit(
" [fC]");
168 if (std::abs(charge) > 1000.0) {
170 chargeUnit = std::string(
" [pC]");
173 if (std::abs(charge) > 1000.0) {
175 chargeUnit = std::string(
" [nC]");
178 if (std::abs(charge) > 1000.0) {
180 chargeUnit = std::string(
" [uC]");
183 std::stringstream chargeOutput;
184 chargeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision)
185 << charge << chargeUnit;
187 return chargeOutput.str();
191 Quaternion rotation,
const std::string& elementName =
"");
193 std::string
toUpper(
const std::string& str);
203 template <
class IteratorIn,
class IteratorOut>
204 void toString(IteratorIn first, IteratorIn last, IteratorOut out);
206 template <
typename T>
218 const std::string& fileName,
double maxSPos,
bool checkForTime =
true);
221 const std::string& string_to_encode);
224 template <
typename T,
typename A>
226 return v.empty() ?
static_cast<T*
>(0) : &(v[0]);
229 template <
typename T,
typename A>
231 return v.empty() ?
static_cast<T const*
>(0) : &(v[0]);
238 std::is_integral<T>::value,
"Util::toStringWithThousandSep: T must be of integer type");
240 unsigned int powers =
241 std::floor(std::max(0.0, std::log(std::abs((
double)value)) / std::log(10.0)));
242 powers -= powers % 3u;
244 std::ostringstream ret;
246 while (powers >= 3u) {
247 T multiplicator = std::pow(
T(10), powers);
248 T pre = value / multiplicator;
250 ret << std::setw(3) << std::setfill(
'0') << pre << sep;
254 value -= pre * multiplicator;
261 ret << std::setw(3) << std::setfill(
'0') << value;
269template <
class IteratorIn,
class IteratorOut>
271 std::transform(first, last, out, [](
auto d) {
272 std::ostringstream stm;
std::string combineFilePath(std::initializer_list< std::string > ilist)
std::string doubleVectorToString(const std::vector< double > &v)
std::string getChargeString(double charge, unsigned int precision=3)
std::string boolVectorToUpperString(const std::vector< bool > &b)
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
double convertMomentumEVoverCToBetaGamma(double p, double mass)
double getBetaGamma(double Ekin, double mass)
double getGamma(ippl::Vector< double, 3 > p)
std::string toUpper(const std::string &str)
T * c_data(std::vector< T, A > &v)
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
double getKineticEnergy(ippl::Vector< double, 3 > p, double mass)
std::string getEnergyString(double energyInMeV, unsigned int precision=3)
std::string getTimeString(double time, unsigned int precision=3)
std::string getGitRevision()
std::string base64_encode(const std::string &string_to_encode)
ippl::Vector< double, 3 > getBeta(ippl::Vector< double, 3 > p)
std::string boolToUpperString(const bool &b)
std::string getLengthString(double spos, unsigned int precision=3)
std::string toStringWithThousandSep(T value, char sep='\'')
Vector_t< double, 3 > getTaitBryantAngles(Quaternion rotation, const std::string &)
KahanAccumulation & operator+=(double value)