OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
Classes | Functions
Util Namespace Reference

Classes

struct  KahanAccumulation
 

Functions

std::string getGitRevision ()
 
double erfinv (double x)
 
Vector_t getTaitBryantAngles (Quaternion rotation, const std::string &)
 
std::string toUpper (const std::string &str)
 
std::string boolToUpperString (const bool &b)
 
std::string boolVectorToUpperString (const std::vector< bool > &b)
 
std::string doubleVectorToString (const std::vector< double > &v)
 
std::string combineFilePath (std::initializer_list< std::string > ilist)
 
void checkInt (double real, const std::string &name, double tolerance)
 
bool isAllDigits (const std::string &str)
 
std::string replaceAll (const std::string &str, const std::string &from, const std::string &to)
 
std::vector< std::string > split_any_of (const std::string &s, const std::string &delims, bool compress)
 
std::string compressString (const std::string &str)
 
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 base64_encode (const std::string &string_to_encode)
 
std::string base64_decode (std::string const &encoded_string)
 
double getGamma (Vector_t p)
 
Vector_t getBeta (Vector_t p)
 
double getKineticEnergy (Vector_t p, double mass)
 
double getBetaGamma (double Ekin, double mass)
 
double convertMomentumEVoverCToBetaGamma (double p, double mass)
 
std::string getTimeString (double time, unsigned int precision=3)
 
std::string getLengthString (double spos, unsigned int precision=3)
 
std::string getLengthString (Vector_t spos, unsigned int precision=3)
 
std::string getEnergyString (double energyInMeV, unsigned int precision=3)
 
std::string getChargeString (double charge, unsigned int precision=3)
 
double angle_0to2pi (double angle)
 convert angle (in rad) to [0,2pi) range, from https://stackoverflow.com/a/29721295
 
bool angleBetweenAngles (const double angle, const double min, const double max)
 check if angle (in rad and in range [0,2pi]) is within [min, max]
 
template<class IteratorIn , class IteratorOut >
void toString (IteratorIn first, IteratorIn last, IteratorOut out)
 
std::string trim_chars (const std::string &s, const std::string &chars)
 
template<typename T >
std::string toStringWithThousandSep (T value, char sep='\'')
 
template<typename Enum , std::size_t N>
constexpr Enum stringToEnum (std::string_view str, const std::array< std::pair< Enum, std::string_view >, N > &map, Enum defaultEnum) noexcept
 
template<typename Enum , std::size_t N>
constexpr std::string_view enumToString (Enum e, const std::array< std::pair< Enum, std::string_view >, N > &map, std::string_view defaultStr) noexcept
 
template<typename It >
std::string join (It begin, It end, const std::string &delimiter)
 
template<typename Container >
std::string join (const Container &container, const std::string &delimiter)
 
template<typename T , typename A >
T * c_data (std::vector< T, A > &v)
 
template<typename T , typename A >
T const * c_data (std::vector< T, A > const &v)
 

Function Documentation

◆ angle_0to2pi()

double Util::angle_0to2pi ( double  angle)
inline

convert angle (in rad) to [0,2pi) range, from https://stackoverflow.com/a/29721295

Definition at line 202 of file Util.h.

References Physics::two_pi.

Referenced by TrimCoil::applyField(), and TrimCoil::setAzimuth().

◆ angleBetweenAngles()

bool Util::angleBetweenAngles ( const double  angle,
const double  min,
const double  max 
)
inline

check if angle (in rad and in range [0,2pi]) is within [min, max]

Definition at line 209 of file Util.h.

References max(), and min().

Referenced by TrimCoil::applyField(), Cyclotron::checkInitialReferenceParticle(), and ParallelCyclotronTracker::visitRing().

Here is the call graph for this function:

◆ base64_decode()

std::string Util::base64_decode ( std::string const &  encoded_string)

Definition at line 493 of file Util.cpp.

◆ base64_encode()

std::string Util::base64_encode ( const std::string &  string_to_encode)

Definition at line 449 of file Util.cpp.

Referenced by MeshGenerator::write().

◆ boolToUpperString()

std::string Util::boolToUpperString ( const bool &  b)

Definition at line 161 of file Util.cpp.

References toUpper().

Referenced by boolVectorToUpperString(), and ParticleMatterInteraction::print().

Here is the call graph for this function:

◆ boolVectorToUpperString()

std::string Util::boolVectorToUpperString ( const std::vector< bool > &  b)

Definition at line 168 of file Util.cpp.

References boolToUpperString().

Referenced by ParallelCyclotronTracker::visitCyclotron().

Here is the call graph for this function:

◆ c_data() [1/2]

template<typename T , typename A >
T * Util::c_data ( std::vector< T, A > &  v)

◆ c_data() [2/2]

template<typename T , typename A >
T const * Util::c_data ( std::vector< T, A > const &  v)

Definition at line 320 of file Util.h.

◆ checkInt()

void Util::checkInt ( double  real,
const std::string &  name,
double  tolerance 
)

Definition at line 212 of file Util.cpp.

References name, and real().

Referenced by DumpEMFields::buildGrid(), and DumpFields::buildGrid().

Here is the call graph for this function:

◆ combineFilePath()

std::string Util::combineFilePath ( std::initializer_list< std::string >  ilist)

◆ compressString()

std::string Util::compressString ( const std::string &  str)

Definition at line 271 of file Util.cpp.

Referenced by MeshGenerator::write().

◆ convertMomentumEVoverCToBetaGamma()

double Util::convertMomentumEVoverCToBetaGamma ( double  p,
double  mass 
)
inline

◆ doubleVectorToString()

std::string Util::doubleVectorToString ( const std::vector< double > &  v)

Definition at line 183 of file Util.cpp.

References toString().

Referenced by ParallelCyclotronTracker::visitCyclotron().

Here is the call graph for this function:

◆ enumToString()

template<typename Enum , std::size_t N>
constexpr std::string_view Util::enumToString ( Enum  e,
const std::array< std::pair< Enum, std::string_view >, N > &  map,
std::string_view  defaultStr 
)
constexprnoexcept

◆ erfinv()

double Util::erfinv ( double  x)

◆ getBeta()

Vector_t Util::getBeta ( Vector_t  p)
inline

◆ getBetaGamma()

double Util::getBetaGamma ( double  Ekin,
double  mass 
)
inline

◆ getChargeString()

std::string Util::getChargeString ( double  charge,
unsigned int  precision = 3 
)
inline

Definition at line 173 of file Util.h.

Referenced by PartBunchBase< T, Dim >::print().

◆ getEnergyString()

std::string Util::getEnergyString ( double  energyInMeV,
unsigned int  precision = 3 
)
inline

Definition at line 150 of file Util.h.

Referenced by ParallelTTracker::dumpStats(), and PartBunchBase< T, Dim >::print().

◆ getGamma()

double Util::getGamma ( Vector_t  p)
inline

◆ getGitRevision()

std::string Util::getGitRevision ( )

◆ getKineticEnergy()

double Util::getKineticEnergy ( Vector_t  p,
double  mass 
)
inline

◆ getLengthString() [1/2]

std::string Util::getLengthString ( double  spos,
unsigned int  precision = 3 
)
inline

◆ getLengthString() [2/2]

std::string Util::getLengthString ( Vector_t  spos,
unsigned int  precision = 3 
)
inline

Definition at line 119 of file Util.h.

◆ getTaitBryantAngles()

Vector_t Util::getTaitBryantAngles ( Quaternion  rotation,
const std::string &   
)

Definition at line 122 of file Util.cpp.

References Quaternion::conjugate(), euclidean_norm(), Quaternion::rotate(), and Physics::two_pi.

Referenced by OpalBeamline::save3DInput(), and H5PartWrapperForPT::writeStepHeader().

Here is the call graph for this function:

◆ getTimeString()

std::string Util::getTimeString ( double  time,
unsigned int  precision = 3 
)
inline

◆ isAllDigits()

bool Util::isAllDigits ( const std::string &  str)

Check if there are only digits in a string from https://stackoverflow.com/questions/19678572/how-to-validate-that-there-are-only-digits-in-a-string

Definition at line 225 of file Util.cpp.

Referenced by FieldSolver::getTagging_m().

◆ join() [1/2]

template<typename Container >
std::string Util::join ( const Container &  container,
const std::string &  delimiter 
)

Definition at line 299 of file Util.h.

References join().

Here is the call graph for this function:

◆ join() [2/2]

template<typename It >
std::string Util::join ( It  begin,
It  end,
const std::string &  delimiter 
)

Definition at line 281 of file Util.h.

References begin(), and end().

Referenced by join(), and AttributeHandler::setPredefinedValues().

Here is the call graph for this function:

◆ replaceAll()

std::string Util::replaceAll ( const std::string &  str,
const std::string &  from,
const std::string &  to 
)

Definition at line 231 of file Util.cpp.

Referenced by OpalParser::readStatement().

◆ rewindLinesSDDS()

unsigned int Util::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

Definition at line 305 of file Util.cpp.

References Physics::c, end(), endl(), INFOMSG, level2(), IpplInfo::myNode(), and name.

Referenced by StatBaseWriter::rewindToSpos(), and Monitor::writeStatistics().

Here is the call graph for this function:

◆ split_any_of()

std::vector< std::string > Util::split_any_of ( const std::string &  s,
const std::string &  delims,
bool  compress 
)

◆ stringToEnum()

template<typename Enum , std::size_t N>
constexpr Enum Util::stringToEnum ( std::string_view  str,
const std::array< std::pair< Enum, std::string_view >, N > &  map,
Enum  defaultEnum 
)
constexprnoexcept

◆ toString()

template<class IteratorIn , class IteratorOut >
void Util::toString ( IteratorIn  first,
IteratorIn  last,
IteratorOut  out 
)

Definition at line 358 of file Util.h.

Referenced by doubleVectorToString().

◆ toStringWithThousandSep()

template<typename T >
std::string Util::toStringWithThousandSep ( T  value,
char  sep = '\'' 
)

Definition at line 324 of file Util.h.

Referenced by BeamStrippingPhysics::print(), and ScatteringPhysics::print().

◆ toUpper()

std::string Util::toUpper ( const std::string &  str)

◆ trim_chars()

std::string Util::trim_chars ( const std::string &  s,
const std::string &  chars 
)
inline