REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestStringHelper.cxx
1 #include "TRestStringHelper.h"
2 
3 #include <Rtypes.h>
4 #include <TApplication.h>
5 #include <TSystem.h>
6 #include <TTimer.h>
7 
8 #if ROOT_VERSION_CODE < ROOT_VERSION(6, 0, 0)
9 #include <TFormula.h>
10 #else
11 #include <v5/TFormula.h>
12 #endif
13 
14 using namespace std;
15 
27 Int_t REST_StringHelper::isAExpression(const string& in) {
28  bool symbol = false;
29 
30  if (in.length() < 2) // minimum expression: 3%
31  return 0;
32 
33  vector<string> funcs{"sqrt", "log", "exp", "gaus", "cos", "sin", "tan", "atan", "acos", "asin"};
34  for (const auto& item : funcs) {
35  if (in.find(item) != string::npos) {
36  symbol = true;
37  break;
38  }
39  }
40 
41  if (!symbol) {
42  size_t pos = in.substr(1, in.length() - 2).find_first_of("+-*/e^%");
43  if (pos != string::npos) {
44  symbol = true;
45  }
46  }
47 
48  if (!symbol) {
49  size_t pos = in.find_first_of("%");
50  if (pos == in.size() - 1) {
51  symbol = true;
52  }
53  }
54 
55  if (symbol) {
56  string temp = in;
57  for (const auto& item : funcs) {
58  temp = Replace(temp, item, "0", 0);
59  }
60  if (temp.find_first_not_of("-0123456789e+*/.,)( ^%") == string::npos) {
61  if (temp.find("/") == 0 || temp.find("./") == 0 || temp.find("../") == 0)
62  return 0; // identify path
63  return 1;
64  }
65  } else {
66  return 0;
67  }
68 
69  return 0;
70 }
71 
78 string REST_StringHelper::CropWithPrecision(string in, Int_t precision) {
79  if (precision == 0) return in;
80  if (REST_StringHelper::isANumber(in) && in.find(".") != string::npos) {
81  string rootStr;
82  size_t newPrecision = precision;
83  if (in.find("e") != string::npos) {
84  rootStr = in.substr(in.find("e"), -1);
85  newPrecision = std::min((int)newPrecision, (int)in.find("e") - (int)in.find(".") - 1);
86  }
87  std::string rr = in.substr(0, in.find(".") + newPrecision + 1) + rootStr;
88  return rr;
89  }
90  return in;
91 }
92 
102 string REST_StringHelper::ReplaceMathematicalExpressions(string buffer, Int_t precision,
103  string errorMessage) {
104  buffer = Replace(buffer, " AND ", " && ");
105  buffer = Replace(buffer, " OR ", " || ");
106 
107  if (buffer.find("'") != string::npos && count(buffer.begin(), buffer.end(), '\'') % 2 == 0) {
108  size_t pos1 = buffer.find("'");
109  size_t pos2 = buffer.find("'", pos1 + 1);
110  string expr = buffer.substr(pos1 + 1, pos2 - pos1 - 1);
111 
112  if (!isAExpression(expr)) return buffer;
113 
114  string evalExpr = ReplaceMathematicalExpressions(expr, precision);
115  expr = "'" + expr + "'";
116  string newbuff = Replace(buffer, expr, evalExpr);
117 
118  return ReplaceMathematicalExpressions(newbuff, precision, errorMessage);
119  }
120 
121  // we spilt the unit part and the expresstion part
122  int pos = buffer.find_last_of("1234567890().");
123 
124  string unit = buffer.substr(pos + 1, -1);
125  string temp = buffer.substr(0, pos + 1);
126  string result = "";
127 
128  bool erased = false;
129 
130  vector<string> Expressions = Split(temp, ",");
131 
132  if (Expressions.size() > 1 && Expressions[0][0] == '(' &&
133  Expressions[Expressions.size() - 1][Expressions[Expressions.size() - 1].size() - 1] == ')') {
134  Expressions[0].erase(0, 1);
135  Expressions[Expressions.size() - 1].erase(Expressions[Expressions.size() - 1].size() - 1, 1);
136  erased = true;
137  }
138 
139  for (size_t i = 0; i < Expressions.size(); i++) {
140  if (!isAExpression(Expressions[i])) {
141  result += Expressions[i] + ",";
142  continue;
143  }
144  string evaluated = EvaluateExpression(Expressions[i]);
145  if (evaluated == "RESTerror") {
146  result += Expressions[i] + ",";
147  RESTError << "ReplaceMathematicalExpressions. Error on RML syntax!" << RESTendl;
148  if (errorMessage != "") RESTError << errorMessage << RESTendl;
149  } else
150  result += evaluated + ",";
151  }
152  if (Expressions.size() > 0) result.erase(result.size() - 1, 1);
153 
154  if (erased) {
155  result = "(" + result + ")";
156  }
157  result = CropWithPrecision(result, precision);
158 
159  return result + unit;
160 }
161 
167  if (!isAExpression(exp)) {
168  return exp;
169  }
170 
171 // NOTE!!! In root6 the expression like "1/2" will be computed using the input
172 // as int number, which will return 0, and cause problem. we roll back to
173 // TFormula of version 5
174 #if ROOT_VERSION_CODE < ROOT_VERSION(6, 0, 0)
175  TFormula formula("tmp", exp.c_str());
176 #else
177  ROOT::v5::TFormula formula("tmp", exp.c_str());
178 #endif
179 
180  ostringstream sss;
181  Double_t number = formula.EvalPar(0);
182  if (number > 0 && number < 1.e-300) {
183  RESTWarning << "REST_StringHelper::EvaluateExpresssion. Expression not recognized --> " << exp
184  << RESTendl;
185  return (string) "RESTerror";
186  }
187 
188  sss << number;
189  string out = sss.str();
190 
191  return out;
192 }
193 
198 Int_t REST_StringHelper::GetChar(string hint) {
199  cout << hint << endl;
200  int result = -1;
201  if (gApplication != nullptr && !gApplication->IsRunning()) {
202  auto timer = std::make_unique<TTimer>("gSystem->ProcessEvents();", 50, kFALSE);
203  bool done = false;
204  do {
205  timer->TurnOn();
206  timer->Reset();
207  result = REST_Display_CompatibilityMode ? 1 : getchar();
208  timer->TurnOff();
209  done = true;
210  } while (!done);
211  } else {
212  result = REST_Display_CompatibilityMode ? 1 : getchar();
213  }
214  return result;
215 }
216 
222  std::string inTrim = Trim(in);
223  return (inTrim.find_first_not_of("-+0123456789.eE") == string::npos && !inTrim.empty());
224 }
225 
236 vector<string> REST_StringHelper::Split(string in, string separator, bool allowBlankString,
237  bool removeWhiteSpaces, int startPos) {
238  vector<string> result;
239 
240  int pos = startPos;
241  int front = 0;
242  while (1) {
243  pos = in.find(separator.c_str(), pos + 1);
244  string sub = in.substr(front, pos - front);
245  if (removeWhiteSpaces) sub = RemoveWhiteSpaces(sub);
246  if (allowBlankString || sub != "") {
247  result.push_back(sub);
248  }
249  front = pos + separator.size();
250  if (pos == -1) break;
251  }
252 
253  return result;
254 }
255 
263 vector<double> REST_StringHelper::StringToElements(string in, string separator) {
264  vector<double> result;
265  vector<string> vec_str = REST_StringHelper::Split(RemoveDelimiters(in), separator);
266  for (unsigned int i = 0; i < vec_str.size(); i++) {
267  double temp = REST_StringHelper::StringToDouble(vec_str[i]);
268  result.push_back(temp);
269  }
270 
271  return result;
272 }
273 
281 vector<double> REST_StringHelper::StringToElements(string in, string headChar, string separator,
282  string tailChar) {
283  vector<double> result;
284  size_t startPos = in.find(headChar);
285  size_t endPos = in.find(tailChar);
286  if (startPos == string::npos || endPos == string::npos) {
287  return result;
288  }
289  vector<string> values = Split(in.substr(startPos + 1, endPos - startPos - 1), ",");
290 
291  for (unsigned int i = 0; i < values.size(); i++) {
292  double temp = REST_StringHelper::StringToDouble(values[i]);
293  result.push_back(temp);
294  }
295 
296  return result;
297 }
298 
303  string out = in;
304  size_t pos = out.find_first_of("+-*/e^%");
305  while ((pos = out.find_first_of("({[]})")) != string::npos) {
306  out.erase(pos, 1);
307  }
308 
309  return out;
310 }
311 
316  string out = in;
317  size_t pos = 0;
318  while ((pos = out.find(" ", pos)) != string::npos) {
319  out.erase(pos, 1);
320  }
321 
322  return out;
323 }
324 
325 ULong64_t REST_StringHelper::ToHash(string str) {
326  ULong64_t prime = 0x100000001B3ull;
327  ULong64_t basis = 0xCBF29CE484222325ull;
328  ULong64_t ret{basis};
329 
330  for (unsigned int i = 0; i < str.size(); i++) {
331  ret ^= str[i];
332  ret *= prime;
333  }
334 
335  return ret;
336 }
337 
342 Int_t REST_StringHelper::Count(string in, string substring) {
343  int count = 0;
344  size_t nPos = in.find(substring, 0); // First occurrence
345  while (nPos != string::npos) {
346  count++;
347  nPos = in.find(substring, nPos + 1);
348  }
349 
350  return count;
351 }
352 
356 Int_t REST_StringHelper::FindNthStringPosition(const string& in, size_t pos, const string& strToFind,
357  size_t nth) {
358  size_t found_pos = in.find(strToFind, pos);
359  if (nth == 0 || string::npos == found_pos) return found_pos;
360  return FindNthStringPosition(in, found_pos + 1, strToFind, nth - 1);
361 }
362 
381 Bool_t REST_StringHelper::MatchString(string str, string matcher) {
382  if (str.size() > 256 || matcher.size() > 256) {
383  RESTError << "REST_StringHelper::MatchString(): string size too large" << RESTendl;
384  return false;
385  }
386 
387  vector<vector<bool>> dp(256, vector<bool>(256));
388  int n2 = str.size();
389  int n1 = matcher.size();
390  dp[0][0] = true;
391  int i = 0, j = 0;
392  for (int i = 0; i < n1; i++) {
393  if (matcher[i] != '*') {
394  break;
395  }
396  if (i == n1 - 1 && matcher[i] == '*') {
397  return true;
398  }
399  }
400  for (i = 1; matcher.at(i - 1) == '*'; i++) {
401  dp[i][0] = true;
402  }
403  for (i = 1; i <= n1; i++) {
404  for (j = 1; j <= n2; j++) {
405  if (matcher.at(i - 1) == '*' && (dp[i - 1][j - 1] || dp[i][j - 1] || dp[i - 1][j])) {
406  dp[i][j] = true;
407  } else if (matcher.at(i - 1) == '?' && dp[i - 1][j - 1]) {
408  dp[i][j] = true;
409  } else if (matcher.at(i - 1) == str.at(j - 1) && dp[i - 1][j - 1]) {
410  dp[i][j] = true;
411  }
412  }
413  }
414  if (dp[n1][n2]) {
415  return true;
416  } else {
417  return false;
418  }
419 
420  return false;
421 }
422 
443 Int_t REST_StringHelper::DiffString(const string& source, const string& target) {
444  int n = source.length();
445  int m = target.length();
446  if (m == 0) return n;
447  if (n == 0) return m;
448  // Construct a matrix
449  typedef vector<vector<int>> Tmatrix;
450  Tmatrix matrix(n + 1);
451  for (int i = 0; i <= n; i++) matrix[i].resize(m + 1);
452 
453  // step 2 Initialize
454 
455  for (int i = 1; i <= n; i++) matrix[i][0] = i;
456  for (int i = 1; i <= m; i++) matrix[0][i] = i;
457 
458  // step 3
459  for (int i = 1; i <= n; i++) {
460  const char si = source[i - 1];
461  // step 4
462  for (int j = 1; j <= m; j++) {
463  const char dj = target[j - 1];
464  // step 5
465  int cost;
466  if (si == dj) {
467  cost = 0;
468  } else {
469  cost = 1;
470  }
471  // step 6
472  const int above = matrix[i - 1][j] + 1;
473  const int left = matrix[i][j - 1] + 1;
474  const int diag = matrix[i - 1][j - 1] + cost;
475  matrix[i][j] = min(above, min(left, diag));
476  }
477  } // step7
478  return matrix[n][m];
479 }
480 
485 string REST_StringHelper::Replace(string in, string thisString, string byThisString, size_t fromPosition,
486  Int_t N) {
487  string out = in;
488  size_t pos = fromPosition;
489  Int_t cont = 0;
490  while ((pos = out.find(thisString, pos)) != string::npos) {
491  out.replace(pos, thisString.length(), byThisString);
492  pos = pos + byThisString.length();
493  cont++;
494 
495  if (N > 0 && cont == N) return out;
496  }
497 
498  return out;
499 }
500 
501 string REST_StringHelper::EscapeSpecialLetters(string in) {
502  string result = Replace(in, "(", "\\(", 0);
503  result = Replace(result, ")", "\\)", 0);
504  result = Replace(result, "$", "\\$", 0);
505  result = Replace(result, "#", "\\#", 0);
506  result = Replace(result, "{", "\\{", 0);
507  result = Replace(result, "}", "\\}", 0);
508  result = Replace(result, "<", "\\<", 0);
509  result = Replace(result, ">", "\\>", 0);
510  return result;
511 }
512 
524  tm* tm_ = localtime(&time);
525  int year, month, day, hour, minute, second;
526  year = tm_->tm_year + 1900;
527  month = tm_->tm_mon + 1;
528  day = tm_->tm_mday;
529  hour = tm_->tm_hour;
530  minute = tm_->tm_min;
531  second = tm_->tm_sec;
532 
533  string yearStr = IntegerToString(year);
534  std::string monthStr = IntegerToString(month, "%02d");
535  std::string dayStr = IntegerToString(day, "%02d");
536  std::string hourStr = IntegerToString(hour, "%02d");
537  std::string minuteStr = IntegerToString(minute, "%02d");
538  std::string secondStr = IntegerToString(second, "%02d");
539 
540  std::string date =
541  yearStr + "/" + monthStr + "/" + dayStr + " " + hourStr + ":" + minuteStr + ":" + secondStr;
542  return date;
543 }
544 
561  struct tm tm1;
562  tm1.tm_hour = 0;
563  tm1.tm_min = 0;
564  tm1.tm_sec = 0;
565  time_t time1;
566  if (time.find(":") != string::npos) {
567  if (time.find("/") != string::npos)
568  sscanf(time.c_str(), "%d/%d/%d %d:%d:%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday),
569  &(tm1.tm_hour), &(tm1.tm_min), &(tm1.tm_sec));
570  else
571  sscanf(time.c_str(), "%d-%d-%d %d:%d:%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday),
572  &(tm1.tm_hour), &(tm1.tm_min), &(tm1.tm_sec));
573  } else {
574  if (time.find("/") != string::npos)
575  sscanf(time.c_str(), "%d/%d/%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday));
576  else
577  sscanf(time.c_str(), "%d-%d-%d", &(tm1.tm_year), &(tm1.tm_mon), &(tm1.tm_mday));
578  }
579 
580  tm1.tm_year -= 1900;
581  tm1.tm_mon--;
582  tm1.tm_isdst = -1;
583  time1 = mktime(&tm1);
584 
585  return time1;
586 }
587 
588 TRestStringOutput::REST_Verbose_Level REST_StringHelper::StringToVerboseLevel(string in) {
589  if (ToUpper(in) == "SILENT" || in == "0") return TRestStringOutput::REST_Verbose_Level::REST_Silent;
590  if (ToUpper(in) == "ESSENTIAL" || ToUpper(in) == "WARNING" || in == "1")
592  if (ToUpper(in) == "INFO" || in == "2") return TRestStringOutput::REST_Verbose_Level::REST_Info;
593  if (ToUpper(in) == "DEBUG" || in == "3") return TRestStringOutput::REST_Verbose_Level::REST_Debug;
594  if (ToUpper(in) == "EXTREME" || in == "4") return TRestStringOutput::REST_Verbose_Level::REST_Extreme;
595 
597 }
598 
603  if (isANumber(in)) {
604  return stod(in);
605  } else {
606  return -1;
607  }
608 }
609 
614  if (isANumber(in)) {
615  return stof(in);
616  } else {
617  return -1;
618  }
619 }
620 
625  // If we find a hexadecimal number
626  if (in.find("0x") != string::npos) return (Int_t)stoul(in, nullptr, 16);
627 
628  return (Int_t)StringToDouble(in);
629 }
630 
634 string REST_StringHelper::IntegerToString(Int_t n, string format) { return Form(format.c_str(), n); }
635 
646 std::vector<int> REST_StringHelper::IntegerToBinary(int number, size_t dimension) {
647  std::vector<int> binaryNumber;
648 
649  if (number == 0) {
650  binaryNumber.insert(binaryNumber.begin(), dimension, 0);
651  if (binaryNumber.empty()) binaryNumber.push_back(0);
652  return binaryNumber;
653  }
654 
655  while (number > 0) {
656  int digit = number % 2;
657  binaryNumber.insert(binaryNumber.begin(), digit);
658  number /= 2;
659  }
660 
661  if (dimension > binaryNumber.size())
662  binaryNumber.insert(binaryNumber.begin(), dimension - binaryNumber.size(), 0);
663 
664  return binaryNumber;
665 }
666 
670 string REST_StringHelper::DoubleToString(Double_t d, string format) { return Form(format.c_str(), d); }
671 
672 Bool_t REST_StringHelper::StringToBool(string booleanString) {
673  const auto booleanStringUpper = ToUpper(booleanString);
674  return booleanStringUpper == "TRUE" || booleanStringUpper == "ON" ||
675  booleanStringUpper == to_string(true);
676 }
677 
678 Long64_t REST_StringHelper::StringToLong(string in) {
679  if (in.find_first_of("eE") != string::npos) {
680  // in case for scientific numbers
681  return (Long64_t)StringToDouble(in);
682  }
683  stringstream strIn;
684  strIn << in;
685  long long llNum;
686  strIn >> llNum;
687  return llNum;
688 }
689 
694  TVector3 a;
695 
696  size_t startVector = in.find_first_of("(");
697  if (startVector == string::npos) return a;
698 
699  size_t endVector = in.find_first_of(")");
700  if (endVector == string::npos) return a;
701 
702  size_t n = count(in.begin(), in.end(), ',');
703  if (n != 2) return a;
704 
705  size_t firstComma = in.find_first_of(",");
706  size_t secondComma = in.find(",", firstComma + 1);
707 
708  if (firstComma >= endVector || firstComma <= startVector) return a;
709  if (secondComma >= endVector || secondComma <= startVector) return a;
710 
711  string X = in.substr(startVector + 1, firstComma - startVector - 1);
712  string Y = in.substr(firstComma + 1, secondComma - firstComma - 1);
713  string Z = in.substr(secondComma + 1, endVector - secondComma - 1);
714 
715  a.SetXYZ(StringToDouble(X), StringToDouble(Y), StringToDouble(Z));
716 
717  return a;
718 }
719 
724  TVector2 a(-1, -1);
725 
726  size_t startVector = in.find_first_of("(");
727  if (startVector == string::npos) return a;
728 
729  size_t endVector = in.find_first_of(")");
730  if (endVector == string::npos) return a;
731 
732  size_t n = count(in.begin(), in.end(), ',');
733  if (n != 1) return a;
734 
735  size_t firstComma = in.find_first_of(",");
736 
737  if (firstComma >= endVector || firstComma <= startVector) return a;
738 
739  string X = in.substr(startVector + 1, firstComma - startVector - 1);
740  string Y = in.substr(firstComma + 1, endVector - firstComma - 1);
741 
742  a.Set(StringToDouble(X), StringToDouble(Y));
743 
744  return a;
745 }
746 
750 string REST_StringHelper::ToUpper(string s) {
751  transform(s.begin(), s.end(), s.begin(), (int (*)(int))toupper);
752  return s;
753 }
754 
759  if (s.length() == 0) return s;
760  s[0] = *REST_StringHelper::ToUpper(string(&s[0], 1)).c_str();
761  return s;
762 }
763 
767 string REST_StringHelper::ToLower(string s) {
768  transform(s.begin(), s.end(), s.begin(), (int (*)(int))tolower);
769  return s;
770 }
771 
776 string REST_StringHelper::RightTrim(string s, const char* t) {
777  s.erase(s.find_last_not_of(t) + 1);
778  return s;
779 }
780 
785 string REST_StringHelper::LeftTrim(string s, const char* t) {
786  s.erase(0, s.find_first_not_of(t));
787  return s;
788 }
789 
794 string REST_StringHelper::Trim(string s, const char* t) { return LeftTrim(RightTrim(s, t), t); }
795 
800  s = Trim(s);
801  s = ToUpper(s);
802  return s;
803 }
804 
809  s = Trim(s);
810  s = ToLower(s);
811  return s;
812 }
813 
822  if (name == "") {
823  return "";
824  }
825  if (name[0] == 'f' && name.size() > 1 && (name[1] >= 65 && name[1] <= 90)) {
826  return string(1, tolower(name[1])) + name.substr(2, -1);
827  } else {
828  return "";
829  }
830 }
831 
840  if (name == "") {
841  return "";
842  }
843  if (islower(name[0])) {
844  return "f" + string(1, toupper(name[0])) + name.substr(1, -1);
845  } else {
846  return "";
847  }
848 }
849 
882 TF1* REST_StringHelper::CreateTF1FromString(string func, double init, double end) {
883  string tf1 = func;
884  // Number of parameters
885  size_t n = count(func.begin(), func.end(), '[');
886  // Reading options
887  int a = 0;
888  vector<int> optPos(n);
889  vector<string> options(n); // Vector of strings of any size.
890  for (unsigned int i = 0; i < n; i++) {
891  optPos[i] = func.find("[", a);
892  options[i] =
893  func.substr(func.find("[", a) + 1, func.find("]", func.find("[", a)) - func.find("[", a) - 1);
894  a = func.find("[", a) + 1;
895  }
896  // Removing options from function string
897  for (unsigned int i = 0; i < n; i++) {
898  tf1.replace(optPos[n - 1 - i] + 1, (func.find("]", optPos[n - 1 - i]) - optPos[n - 1 - i] - 1),
899  string(1, func[optPos[n - 1 - i] + 1]));
900  }
901 
902  // Function
903  const char* tf1c = tf1.c_str();
904  TF1* f = new TF1("f", tf1c, init, end);
905 
906  // Initial conditions
907  for (unsigned int i = 0; i < n; i++) {
908  if (options[i].find("=") != string::npos) {
909  string op = options[i].substr(options[i].find_last_of("=") + 1,
910  options[i].find("(") - options[i].find_last_of("=") - 1);
911  if (isANumber(op)) {
912  f->SetParameter(i, stod(op));
913  } else {
914  cout << "Initial condition for parameter " << i << " is not a number: " << op << endl;
915  }
916  } else {
917  cout << "No initial condition given for parameter " << i << "!" << endl;
918  }
919  }
920 
921  // Fixed values
922  for (unsigned int i = 0; i < n; i++) {
923  if (count(options[i].begin(), options[i].end(), '=') == 2) {
924  string op = options[i].substr(options[i].find_last_of("=") + 1,
925  options[i].find("(") - options[i].find_last_of("=") - 1);
926  if (isANumber(op)) {
927  f->FixParameter(i, stod(op));
928  }
929  // cout << "Parameter " << i << " fixed with value " << op << endl;
930  }
931  }
932 
933  // Ranges
934  for (unsigned int i = 0; i < n; i++) {
935  if (options[i].find("(") != string::npos) {
936  string op =
937  options[i].substr(options[i].find("(") + 1, options[i].find(")") - options[i].find("(") - 1);
938  f->SetParLimits(i, stod(op.substr(0, op.find(","))),
939  stod(op.substr(op.find(",") + 1, op.size() - 1 - op.find(","))));
940  // cout << "Parameter " << i << " range " << "(" << stod(op.substr(0, op.find(","))) << "," <<
941  // stod(op.substr(op.find(",")+1, op.size()-1-op.find(",") )) << ")" << endl;
942  }
943  }
944 
945  return f;
946 }
REST_Verbose_Level
Enumerate of verbose level, containing five levels.
@ REST_Essential
+show some essential information, as well as warnings
@ REST_Info
+show most of the information for each steps
@ REST_Debug
+show the defined debug messages
@ REST_Silent
show minimum information of the software, as well as error messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
std::string IntegerToString(Int_t n, std::string format="%d")
Gets a string from an integer.
std::string FirstToUpper(std::string s)
Convert the first character of a string to upper case.
time_t StringToTimeStamp(std::string time)
A method to convert a date/time formatted string to a timestamp.
Float_t StringToFloat(std::string in)
Gets a float from a string.
std::vector< std::string > Split(std::string in, std::string separator, bool allowBlankString=false, bool removeWhiteSpaces=false, int startPos=-1)
Split the input string according to the given separator. Returning a vector of fragments.
Bool_t MatchString(std::string str, std::string matcher)
This method matches a string with certain matcher. Returns true if matched. Supports wildcard charact...
std::string RightTrim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the end of the string (https://stackoverflow.com/questions/216823/w...
Double_t StringToDouble(std::string in)
Gets a double from a string.
TF1 * CreateTF1FromString(std::string func, double init, double end)
Reads a function with parameter options from string and returns it as TF1*.
std::string ToUpper(std::string in)
Convert string to its upper case. Alternative of TString::ToUpper.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
Int_t isAExpression(const std::string &in)
Returns 1 only if valid mathematical expression keywords (or numbers) are found in the string in....
std::string DoubleToString(Double_t d, std::string format="%8.6e")
Gets a string from a double.
std::string TrimAndUpper(std::string s)
It trims and uppers the string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.
std::string LeftTrim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the beginning of the string (https://stackoverflow....
std::string EvaluateExpression(std::string exp)
Evaluates a complex numerical expression and returns the resulting value using TFormula.
std::vector< int > IntegerToBinary(int number, size_t dimension=0)
It returns an integer vector with the binary digits decomposed.
std::string TrimAndLower(std::string s)
It trims and lowers the string.
Int_t Count(std::string s, std::string sbstring)
Counts the number of occurences of substring inside the input string in.
Int_t DiffString(const std::string &source, const std::string &target)
Returns the number of different characters between two strings.
std::string Trim(std::string s, const char *t=" \t\n\r\f\v")
Removes all white spaces found at the beginning and the end of the string (https://stackoverflow....
std::string ParameterNameToDataMemberName(std::string name)
Convert parameter name to datamember name, following REST parameter naming convention.
std::string RemoveDelimiters(std::string in)
Returns the input string removing any delimiters ({[]})
std::string ToLower(std::string in)
Convert string to its lower case. Alternative of TString::ToLower.
std::string DataMemberNameToParameterName(std::string name)
Convert data member name to parameter name, following REST parameter naming convention.
Int_t isANumber(std::string in)
Returns 1 only if a valid number is found in the string in. If not it returns 0.
TVector3 StringTo3DVector(std::string in)
Gets a 3D-vector from a string. Format should be : (X,Y,Z).
Int_t FindNthStringPosition(const std::string &in, size_t pos, const std::string &strToFind, size_t nth)
Returns the position of the nth occurence of the string strToFind inside the string in.
std::string RemoveWhiteSpaces(std::string in)
Returns the input string removing all white spaces.
std::string CropWithPrecision(std::string in, Int_t precision)
It crops a floating number given inside the string in with the given precision. I....
std::vector< double > StringToElements(std::string in, std::string separator)
Convert the input string into a vector of double elements.
std::string ToDateTimeString(time_t time)
Format time_t into string.
std::string Replace(std::string in, std::string thisString, std::string byThisString, size_t fromPosition=0, Int_t N=0)
Replace any occurences of thisSring by byThisString inside string in.
std::string ReplaceMathematicalExpressions(std::string buffer, Int_t precision=0, std::string errorMessage="")
Evaluates and replaces valid mathematical expressions found in the input string buffer.