Thermal-FIST  1.3
Package for hadron resonance gas model applications
Utility.cpp
Go to the documentation of this file.
1 /*
2  * Thermal-FIST package
3  *
4  * Copyright (c) 2019 Volodymyr Vovchenko
5  *
6  * GNU General Public License (GPLv3 or later)
7  */
8 #include "HRGBase/Utility.h"
9 
10 #include <iostream>
11 #include <sstream>
12 
13 #include "ThermalFISTConfig.h"
14 
15 
16 // For time keeping
17 // Windows
18 #ifdef _WIN32
19 #include <Windows.h>
20 #else
21 #include <time.h>
22 #include <sys/time.h>
23 #endif
24 
25 using namespace std;
26 
27 namespace thermalfist {
28 
29  namespace {
30  string NumberToString(int num) {
31  stringstream strs;
32  strs << num;
33  return strs.str();
34  }
35 
36  string OutputString(const string &strin) {
37  string ret = "";
38  ret += "# ";
39  ret += strin;
40  while (ret.size() < 78)
41  ret += " ";
42  ret += "#";
43  return ret;
44  }
45  }
46 
47  bool Disclaimer::PrintDisclaimer()
48  {
49  if (Disclaimer::DisclaimerPrinted)
50  return true;
51 
52  cout << string(79, '#') << endl;
53 
54  cout << "#" << string(77, ' ') << "#" << endl;
55 
56  string tmpstr = "";
57 
58  tmpstr += "This is Thermal-FIST version ";
59  tmpstr += NumberToString(ThermalFIST_VERSION_MAJOR);
60  tmpstr += ".";
61  tmpstr += NumberToString(ThermalFIST_VERSION_MINOR);
62 
63  if (ThermalFIST_VERSION_DEVEL != 0) {
64  tmpstr += ".";
65  tmpstr += NumberToString(ThermalFIST_VERSION_DEVEL);
66  }
67 
68  tmpstr = OutputString(tmpstr);
69 
70  cout << tmpstr << endl;
71 
72  cout << "#" << string(77, ' ') << "#" << endl;
73 
74  // e-mail obfuscation (just in case)
75  string email = "";
76  email += 'v';
77  email += char(email[0] - 7);
78  email += email[0];
79  email += char('a' + 2);
80  email += char(email[email.size() - 1] + 5);
81  email += "enk";
82  email += "@";
83  email += "o";
84  char ch1 = email[email.size() - 2], ch2 = email[email.size() - 1];
85  email[email.size() - 1] = ch1;
86  email[email.size() - 2] = ch2;
87  email += "fias";
88  email += ".";
89  email += "uni-frankfurt.de";
90 
91  tmpstr = "Copyright (c) 2020 Volodymyr Vovchenko <" + email + ">";
92 
93  tmpstr = OutputString(tmpstr);
94 
95  cout << tmpstr << endl;
96 
97  cout << "#" << string(77, ' ') << "#" << endl;
98 
99  tmpstr = "Distributed under the GNU General Public License 3.0 (GPLv3 or later)";
100 
101  tmpstr = OutputString(tmpstr);
102 
103  cout << tmpstr << endl;
104 
105  cout << "#" << string(77, ' ') << "#" << endl;
106 
107  tmpstr = "Please cite when using this code:";
108  tmpstr = OutputString(tmpstr);
109  cout << tmpstr << endl;
110 
111  tmpstr = "V. Vovchenko, H. Stoecker, Comput. Phys. Commun. 244, 295 (2019)";
112  tmpstr = OutputString(tmpstr);
113  cout << tmpstr << endl;
114 
115  //tmpstr = "V. Vovchenko, H. Stoecker, arXiv:1901.05249 [nucl-th]";
116  //tmpstr = OutputString(tmpstr);
117  //cout << tmpstr << endl;
118 
119  cout << "#" << string(77, ' ') << "#" << endl;
120 
121 
122  tmpstr = "The latest version is available at https://github.com/vlvovch/Thermal-FIST";
123 
124  tmpstr = OutputString(tmpstr);
125 
126  cout << tmpstr << endl;
127 
128  cout << "#" << string(77, ' ') << "#" << endl;
129 
130  cout << string(79, '#') << endl;
131 
132  cout << endl;
133 
134  return Disclaimer::DisclaimerPrinted = true;
135  }
136 
137  bool Disclaimer::DisclaimerPrinted = PrintDisclaimer();
138 
139  long long stringToLongLong(const string &str) {
140  long long ret = 0;
141  int ist = 0, mn = 1;
142  if (str.size() > 0 && str[0] == '-') {
143  mn = -1;
144  ist = 1;
145  }
146  for (size_t i = ist; i < str.size(); ++i) {
147  if (str[i] >= '0' && str[i] <= '9') {
148  ret *= 10;
149  ret += static_cast<long long>(str[i] - '0');
150  }
151  }
152  return ret * mn;
153  }
154 
155  // Time keeping
156  // Windows
157  #ifdef _WIN32
158  double get_wall_time(){
159  LARGE_INTEGER time,freq;
160  if (!QueryPerformanceFrequency(&freq)){
161  // Handle error
162  return 0;
163  }
164  if (!QueryPerformanceCounter(&time)){
165  // Handle error
166  return 0;
167  }
168  return (double)time.QuadPart / freq.QuadPart;
169  }
170 
171  double get_cpu_time(){
172  FILETIME a,b,c,d;
173  if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0){
174  // Returns total user time.
175  // Can be tweaked to include kernel times as well.
176  return
177  (double)(d.dwLowDateTime |
178  ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001;
179  }else{
180  // Handle error
181  return 0;
182  }
183  }
184 
185  // Posix/Linux
186  #else
187  double get_wall_time(){
188  struct timeval time;
189  if (gettimeofday(&time,NULL)){
190  // Handle error
191  return 0;
192  }
193  return (double)time.tv_sec + (double)time.tv_usec * .000001;
194  }
195  double get_cpu_time(){
196  return (double)clock() / CLOCKS_PER_SEC;
197  }
198  #endif
199 
200 } // namespace thermalfist
Contains some helper functions.
long long stringToLongLong(const string &str)
Definition: Utility.cpp:139
double get_wall_time()
Definition: Utility.cpp:187
double get_cpu_time()
Definition: Utility.cpp:195
The main namespace where all classes and functions of the Thermal-FIST library reside.