Thermal-FIST 1.6
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
Utility.cpp
Go to the documentation of this file.
1/*
2 * Thermal-FIST package
3 *
4 * Copyright (c) 2019-2026 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#include <fstream>
13#include <limits>
14
15#include "ThermalFISTConfig.h"
16
17
18// For time keeping
19// Windows
20#ifdef _WIN32
21#include <Windows.h>
22#else
23#include <time.h>
24#include <sys/time.h>
25#endif
26
27using namespace std;
28
29namespace thermalfist {
30
31 namespace {
32 string NumberToString(int num) {
33 stringstream strs;
34 strs << num;
35 return strs.str();
36 }
37
38 string OutputString(const string &strin) {
39 string ret = "";
40 ret += "# ";
41 ret += strin;
42 while (ret.size() < 78)
43 ret += " ";
44 ret += "#";
45 return ret;
46 }
47 }
48
50 {
52 return true;
53
54 cout << string(79, '#') << endl;
55
56 cout << "#" << string(77, ' ') << "#" << endl;
57
58 string tmpstr = "";
59
60 tmpstr += "This is Thermal-FIST version ";
61 tmpstr += NumberToString(ThermalFIST_VERSION_MAJOR);
62 tmpstr += ".";
63 tmpstr += NumberToString(ThermalFIST_VERSION_MINOR);
64
65 if (ThermalFIST_VERSION_DEVEL != 0) {
66 tmpstr += ".";
67 tmpstr += NumberToString(ThermalFIST_VERSION_DEVEL);
68 }
69
70 tmpstr = OutputString(tmpstr);
71
72 cout << tmpstr << endl;
73
74 cout << "#" << string(77, ' ') << "#" << endl;
75
76 // e-mail obfuscation (just in case)
77 string email = "";
78 email += 'v';
79 email += 'v';
80 email += char(email[0] - 7);
81 email += email[0];
82 email += char('a' + 2);
83 email += char(email[email.size() - 1] + 5);
84 email += "enk";
85 email += "@";
86 email += "o";
87 char ch1 = email[email.size() - 2], ch2 = email[email.size() - 1];
88 email[email.size() - 1] = ch1;
89 email[email.size() - 2] = ch2;
90// email += "fias";
91// email += ".";
92// email += "uni-frankfurt.de";
93 email += "uh";
94 email += ".";
95 email += "edu";
96
97 tmpstr = "Copyright (c) 2026 Volodymyr Vovchenko <" + email + ">";
98
99 tmpstr = OutputString(tmpstr);
100
101 cout << tmpstr << endl;
102
103 cout << "#" << string(77, ' ') << "#" << endl;
104
105 tmpstr = "Distributed under the GNU General Public License 3.0 (GPLv3 or later)";
106
107 tmpstr = OutputString(tmpstr);
108
109 cout << tmpstr << endl;
110
111 cout << "#" << string(77, ' ') << "#" << endl;
112
113 tmpstr = "Please cite when using this code:";
114 tmpstr = OutputString(tmpstr);
115 cout << tmpstr << endl;
116
117 tmpstr = "V. Vovchenko, H. Stoecker, Comput. Phys. Commun. 244, 295 (2019)";
118 tmpstr = OutputString(tmpstr);
119 cout << tmpstr << endl;
120
121 //tmpstr = "V. Vovchenko, H. Stoecker, arXiv:1901.05249 [nucl-th]";
122 //tmpstr = OutputString(tmpstr);
123 //cout << tmpstr << endl;
124
125 cout << "#" << string(77, ' ') << "#" << endl;
126
127
128 tmpstr = "The latest version is available at https://github.com/vlvovch/Thermal-FIST";
129
130 tmpstr = OutputString(tmpstr);
131
132 cout << tmpstr << endl;
133
134 cout << "#" << string(77, ' ') << "#" << endl;
135
136 cout << string(79, '#') << endl;
137
138 cout << endl;
139
140 return Disclaimer::DisclaimerPrinted = true;
141 }
142
143 bool Disclaimer::DisclaimerPrinted = PrintDisclaimer();
144
145 long long stringToLongLong(const string &str) {
146 long long ret = 0;
147 int ist = 0, mn = 1;
148 if (str.size() > 0 && str[0] == '-') {
149 mn = -1;
150 ist = 1;
151 }
152 for (size_t i = ist; i < str.size(); ++i) {
153 if (str[i] >= '0' && str[i] <= '9') {
154 ret *= 10;
155 ret += static_cast<long long>(str[i] - '0');
156 }
157 }
158 return ret * mn;
159 }
160
161 std::map<std::string, std::string> ReadParametersFromFile(const std::string& filename, const std::map<std::string, std::string>& params) {
162 std::map<std::string, std::string> ret = params;
163 std::ifstream fin(filename);
164
165 if (!fin.is_open()) {
166 std::cout << "Cannot open parameters file!" << "\n";
167 return ret;
168 }
169
170 std::string var;
171 std::cout << "Reading input parameters from file " << filename << "\n";
172 while (fin >> var) {
173 if (var.size() == 0 || var[0] == '#') {
174 fin.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
175 continue;
176 }
177
178 std::cout << "Reading input parameter " << var << " = ";
179 std::string val;
180 fin >> val;
181 std::cout << val << std::endl;
182 ret[var] = val;
183 }
184 fin.close();
185 return ret;
186 }
187
188
189 void ParametersFromArgs(int argc, char *argv[], std::map<std::string, std::string> &params)
190 {
191 for(int i = 1; i < argc - 1; i++) {
192 std::string arg = argv[i];
193 if (arg.size() <= 2 || arg[0] != '-' || arg[1] != '-') {
194 continue;
195 }
196 std::string var = arg.substr(2);
197 std::string val = argv[i + 1];
198 params[var] = val;
199 i++;
200 }
201 }
202
203 // Time keeping
204 // Windows
205 #ifdef _WIN32
206 double get_wall_time(){
207 LARGE_INTEGER time,freq;
208 if (!QueryPerformanceFrequency(&freq)){
209 // Handle error
210 return 0;
211 }
212 if (!QueryPerformanceCounter(&time)){
213 // Handle error
214 return 0;
215 }
216 return (double)time.QuadPart / freq.QuadPart;
217 }
218
219 double get_cpu_time(){
220 FILETIME a,b,c,d;
221 if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0){
222 // Returns total user time.
223 // Can be tweaked to include kernel times as well.
224 return
225 (double)(d.dwLowDateTime |
226 ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001;
227 }else{
228 // Handle error
229 return 0;
230 }
231 }
232
233 // Posix/Linux
234 #else
236 struct timeval time;
237 if (gettimeofday(&time,NULL)){
238 // Handle error
239 return 0;
240 }
241 return (double)time.tv_sec + (double)time.tv_usec * .000001;
242 }
243 double get_cpu_time(){
244 return (double)clock() / CLOCKS_PER_SEC;
245 }
246 #endif
247
248} // namespace thermalfist
map< string, double > params
Contains some helper functions.
static bool PrintDisclaimer()
Definition Utility.cpp:49
static bool DisclaimerPrinted
Definition Utility.h:28
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9
double get_cpu_time()
Definition Utility.cpp:243
long long stringToLongLong(const std::string &str)
std::map< std::string, std::string > ReadParametersFromFile(const std::string &filename, const std::map< std::string, std::string > &params={})
Definition Utility.cpp:161
double get_wall_time()
Definition Utility.cpp:235
void ParametersFromArgs(int argc, char *argv[], std::map< std::string, std::string > &params)
Definition Utility.cpp:189