18#ifndef USEFULFUNCTIONS
19#define USEFULFUNCTIONS
28#include <initializer_list>
35#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
36#define __DBGMSG__ __FILENAME__ << ": " << __LINE__ << "\t"
62 if (value < std::numeric_limits<double>::epsilon())
74 std::string timeUnit(
" [ps]");
79 timeUnit = std::string(
" [ns]");
83 timeUnit = std::string(
" [ms]");
87 timeUnit = std::string(
" [fs]");
90 std::stringstream timeOutput;
91 timeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << time << timeUnit;
92 return timeOutput.str();
97 std::string sposUnit(
" [m]");
101 sposUnit = std::string(
" [mm]");
106 sposUnit = std::string(
" [um]");
109 std::stringstream positionOutput;
110 positionOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << spos << sposUnit;
111 return positionOutput.str();
116 std::string sposUnit(
" [m]");
118 for (
unsigned int i = 1; i < 3u; ++ i) {
122 std::stringstream positionOutput;
127 sposUnit = std::string(
" [mm]");
133 sposUnit = std::string(
" [um]");
136 positionOutput << std::fixed << std::setprecision(precision)
138 << std::setw(precision + 7) << spos(0) <<
" , "
139 << std::setw(precision + 7) << spos(1) <<
" , "
140 << std::setw(precision + 7) << spos(2)
142 return positionOutput.str();
147 std::string energyUnit(
" [MeV]");
148 double energy = energyInMeV;
150 if (energy > 1000.0) {
152 energyUnit = std::string(
" [GeV]");
153 }
else if (energy < 1.0) {
155 energyUnit = std::string(
" [keV]");
158 energyUnit = std::string(
" [eV]");
162 std::stringstream energyOutput;
163 energyOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << energy << energyUnit;
165 return energyOutput.str();
170 std::string chargeUnit(
" [fC]");
176 chargeUnit = std::string(
" [pC]");
181 chargeUnit = std::string(
" [nC]");
186 chargeUnit = std::string(
" [uC]");
189 std::stringstream chargeOutput;
190 chargeOutput << std::fixed << std::setw(precision + 2) << std::setprecision(precision) << charge << chargeUnit;
192 return chargeOutput.str();
197 std::string
toUpper(
const std::string& str);
207 template<
class IteratorIn,
class IteratorOut>
208 void toString(IteratorIn first, IteratorIn last, IteratorOut out);
210 template <
typename T>
221 unsigned int rewindLinesSDDS(
const std::string& fileName,
double maxSPos,
bool checkForTime =
true);
223 std::string
base64_encode(
const std::string& string_to_encode);
226 template<
typename T,
typename A>
227 T*
c_data(std::vector<T,A>& v) {
return v.empty() ?
static_cast<T*
>(0) : &(v[0]); }
229 template<
typename T,
typename A>
230 T const*
c_data(std::vector<T,A>
const& v) {
return v.empty() ?
static_cast<T const*
>(0) : &(v[0]); }
235 static_assert(std::is_integral<T>::value,
"Util::toStringWithThousandSep: T must be of integer type");
240 powers -= powers % 3u;
242 std::ostringstream ret;
244 while (powers >= 3u) {
246 T pre = value / multiplicator;
248 ret << std::setw(3) << std::setfill(
'0') << pre << sep;
252 value -= pre * multiplicator;
259 ret << std::setw(3) << std::setfill(
'0') << value;
267template<
class IteratorIn,
class IteratorOut>
269 std::transform(first, last, out, [](
auto d) {
270 std::ostringstream stm;
double dot(const Vector3D &lhs, const Vector3D &rhs)
Vector dot product.
Tps< T > log(const Tps< T > &x)
Natural logarithm.
Tps< T > pow(const Tps< T > &x, int y)
Integer power.
Tps< T > sqrt(const Tps< T > &x)
Square root.
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
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)
Vector_t getTaitBryantAngles(Quaternion rotation, const std::string &)
std::string boolVectorToUpperString(const std::vector< bool > &b)
double getKineticEnergy(Vector_t p, double mass)
void toString(IteratorIn first, IteratorIn last, IteratorOut out)
double convertMomentumEVoverCToBetaGamma(double p, double mass)
double getBetaGamma(double Ekin, double mass)
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
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)
Vector_t getBeta(Vector_t p)
double getGamma(Vector_t p)
std::string boolToUpperString(const bool &b)
std::string getLengthString(double spos, unsigned int precision=3)
std::string toStringWithThousandSep(T value, char sep='\'')
KahanAccumulation & operator+=(double value)