BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnUtils.h
Go to the documentation of this file.
1#ifndef BMNUTILS_H_
2#define BMNUTILS_H_
3
4class TCanvas;
5
6#include <iostream>
7#include <sstream>
8#include <string>
9#include <vector>
10
11using std::string;
12using std::vector;
13
14namespace lit
15{
16
17template<class T>
18string ToString(const T& value)
19{
20 std::stringstream ss;
21 ss << (T)value;
22 return ss.str();
23}
24
25template<class T>
26string NumberToString(const T& value, int precision = 1)
27{
28 // First determine number of digits in float
29 string digis = ToString<int>(value);
30 int ndigis = digis.size();
31
32 std::stringstream ss;
33 ss.precision(ndigis + precision);
34 ss << value;
35 return ss.str();
36}
37
38/* Returns -1 if x<0, +1 if x>0, 0 if x==0 */
39template<class T>
40int Sign(const T& x)
41{
42 static const T ZERO = 0;
43 return (x > ZERO) ? 1 : ((x < ZERO) ? -1 : 0);
44}
45
46void SaveCanvasAsImage(TCanvas* c, const std::string& dir);
47
48string FindAndReplace(const string& name, const string& oldSubstr, const string& newSubstr);
49
50vector<string> Split(const string& name, char delimiter);
51} // namespace lit
52
53#endif /* BmnUTILS_H_ */
string FindAndReplace(const string &name, const string &oldSubstr, const string &newSubstr)
Definition BmnUtils.cxx:19
int Sign(const T &x)
Definition BmnUtils.h:40
void SaveCanvasAsImage(TCanvas *c, const std::string &dir)
Definition BmnUtils.cxx:9
string ToString(const T &value)
Definition BmnUtils.h:18
vector< string > Split(const string &name, char delimiter)
Definition BmnUtils.cxx:27
string NumberToString(const T &value, int precision=1)
Definition BmnUtils.h:26