Thermal-FIST 1.5
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-2025 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
25using namespace std;
26
27namespace 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
48 {
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 += 'v';
78 email += char(email[0] - 7);
79 email += email[0];
80 email += char('a' + 2);
81 email += char(email[email.size() - 1] + 5);
82 email += "enk";
83 email += "@";
84 email += "o";
85 char ch1 = email[email.size() - 2], ch2 = email[email.size() - 1];
86 email[email.size() - 1] = ch1;
87 email[email.size() - 2] = ch2;
88// email += "fias";
89// email += ".";
90// email += "uni-frankfurt.de";
91 email += "uh";
92 email += ".";
93 email += "edu";
94
95 tmpstr = "Copyright (c) 2023 Volodymyr Vovchenko <" + email + ">";
96
97 tmpstr = OutputString(tmpstr);
98
99 cout << tmpstr << endl;
100
101 cout << "#" << string(77, ' ') << "#" << endl;
102
103 tmpstr = "Distributed under the GNU General Public License 3.0 (GPLv3 or later)";
104
105 tmpstr = OutputString(tmpstr);
106
107 cout << tmpstr << endl;
108
109 cout << "#" << string(77, ' ') << "#" << endl;
110
111 tmpstr = "Please cite when using this code:";
112 tmpstr = OutputString(tmpstr);
113 cout << tmpstr << endl;
114
115 tmpstr = "V. Vovchenko, H. Stoecker, Comput. Phys. Commun. 244, 295 (2019)";
116 tmpstr = OutputString(tmpstr);
117 cout << tmpstr << endl;
118
119 //tmpstr = "V. Vovchenko, H. Stoecker, arXiv:1901.05249 [nucl-th]";
120 //tmpstr = OutputString(tmpstr);
121 //cout << tmpstr << endl;
122
123 cout << "#" << string(77, ' ') << "#" << endl;
124
125
126 tmpstr = "The latest version is available at https://github.com/vlvovch/Thermal-FIST";
127
128 tmpstr = OutputString(tmpstr);
129
130 cout << tmpstr << endl;
131
132 cout << "#" << string(77, ' ') << "#" << endl;
133
134 cout << string(79, '#') << endl;
135
136 cout << endl;
137
138 return Disclaimer::DisclaimerPrinted = true;
139 }
140
141 bool Disclaimer::DisclaimerPrinted = PrintDisclaimer();
142
143 long long stringToLongLong(const string &str) {
144 long long ret = 0;
145 int ist = 0, mn = 1;
146 if (str.size() > 0 && str[0] == '-') {
147 mn = -1;
148 ist = 1;
149 }
150 for (size_t i = ist; i < str.size(); ++i) {
151 if (str[i] >= '0' && str[i] <= '9') {
152 ret *= 10;
153 ret += static_cast<long long>(str[i] - '0');
154 }
155 }
156 return ret * mn;
157 }
158
159 // Time keeping
160 // Windows
161 #ifdef _WIN32
162 double get_wall_time(){
163 LARGE_INTEGER time,freq;
164 if (!QueryPerformanceFrequency(&freq)){
165 // Handle error
166 return 0;
167 }
168 if (!QueryPerformanceCounter(&time)){
169 // Handle error
170 return 0;
171 }
172 return (double)time.QuadPart / freq.QuadPart;
173 }
174
175 double get_cpu_time(){
176 FILETIME a,b,c,d;
177 if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0){
178 // Returns total user time.
179 // Can be tweaked to include kernel times as well.
180 return
181 (double)(d.dwLowDateTime |
182 ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001;
183 }else{
184 // Handle error
185 return 0;
186 }
187 }
188
189 // Posix/Linux
190 #else
192 struct timeval time;
193 if (gettimeofday(&time,NULL)){
194 // Handle error
195 return 0;
196 }
197 return (double)time.tv_sec + (double)time.tv_usec * .000001;
198 }
199 double get_cpu_time(){
200 return (double)clock() / CLOCKS_PER_SEC;
201 }
202 #endif
203
204} // namespace thermalfist
Contains some helper functions.
static bool PrintDisclaimer()
Definition Utility.cpp:47
static bool DisclaimerPrinted
Definition Utility.h:27
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:199
long long stringToLongLong(const std::string &str)
double get_wall_time()
Definition Utility.cpp:191