BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
show_simulation_files.cxx
Go to the documentation of this file.
1
//============================================================================
2
// Name : show_simulation_files.cpp
3
// Author : Konstantin Gertsenberger
4
// Copyright : JINR
5
// Description : Get list of simulation files
6
//============================================================================
7
8
// own headers
9
#include "
uni_db_settings.h
"
10
11
// ROOT includes
12
#include "
TSQLResult.h
"
13
#include "
TSQLRow.h
"
14
#include "
TSQLServer.h
"
15
#include "
TString.h
"
16
17
// C++ includes
18
#include <algorithm>
19
#include <iostream>
20
#include <sstream>
21
#include <string>
22
23
using namespace
std
;
24
25
int
main
(
int
argc,
char
** argv)
26
{
27
// help information
28
if
(argc > 1) {
29
string
first_par = argv[1];
30
if
((first_par ==
"/?"
) || (first_par ==
"--help"
) || (first_par ==
"-h"
)) {
31
cout <<
"Get list of simulation files satisfying the given parameters."
<< endl
32
<<
"Parameters separated by comma:"
<< endl
33
<<
"gen - generator name"
<< endl
34
<<
"energy - collision energy (range is supported by '-' symbol)"
<< endl
35
<<
"beam - first particle in collision (first beam)"
<< endl
36
<<
"target - second particle in collision (second beam) OR target"
<< endl
37
<<
"desc - text in description"
<< endl
38
<<
"path - part of the file path"
<< endl
39
<< endl
40
<<
"Examples:"
<< endl
41
<<
"show_simulation_files gen=QGSM,energy=9,beam=Au,target=Au"
<< endl
42
<<
"show_simulation_files gen=urqmd,energy=5-9,desc=50K"
<< endl;
43
44
return
0;
45
}
46
}
47
48
// parse parameter for DB searching
49
bool
isGen =
false
, isEnergy =
false
, isMinEnergy =
false
, isMaxEnergy =
false
, isBeam =
false
, isDesc =
false
,
50
isTarget =
false
, isPath =
false
;
51
string
strGen, strBeam, strDesc, strTarget, strPath;
52
double
fEnergy, fMaxEnergy;
53
for
(
int
i
= 1;
i
< argc;
i
++) {
54
// TString strParameter(argv[i]);
55
// TObjArray* arrSplit = strParameter.Tokenize(",");
56
57
string
input = argv[
i
];
58
istringstream ss(input);
59
string
token;
60
61
// parse tokens by comma separated
62
while
(getline(ss, token,
','
)) {
63
// to lowercase
64
transform(token.begin(), token.end(), token.begin(), ::tolower);
65
66
// generator name parsing
67
if
((token.length() > 4) && (token.substr(0, 4) ==
"gen="
)) {
68
isGen =
true
;
69
strGen = token.substr(4);
70
}
else
{
71
// energy parsing
72
if
((token.length() > 7) && (token.substr(0, 7) ==
"energy="
)) {
73
token = token.substr(7);
74
75
size_t
indDash = token.find_first_of(
'-'
);
76
if
(indDash != string::npos) {
77
stringstream stream;
78
stream << token.substr(0, indDash);
79
double
dVal;
80
if
(stream >> dVal) {
81
isEnergy =
true
;
82
isMinEnergy =
true
;
83
fEnergy = dVal;
84
}
85
if
(token.length() > indDash) {
86
stringstream stream2;
87
stream2 << token.substr(indDash + 1);
88
if
(stream2 >> dVal) {
89
isEnergy =
true
;
90
isMaxEnergy =
true
;
91
fMaxEnergy = dVal;
92
}
93
}
94
}
// if (indDash > -1)
95
// if exact energy value
96
else
97
{
98
stringstream stream;
99
stream << token;
100
double
dVal;
101
if
(stream >> dVal) {
102
isEnergy =
true
;
103
fEnergy = dVal;
104
}
105
}
// else
106
}
// if ((token.length() > 7) && (token.substr(0,7) == "energy="))
107
// beam particle's name in collision parsing
108
else
109
{
110
if
((token.length() > 5) && (token.substr(0, 5) ==
"beam="
)) {
111
isBeam =
true
;
112
strBeam = token.substr(5);
113
}
else
{
114
// search text in description string
115
if
((token.length() > 5) && (token.substr(0, 5) ==
"desc="
)) {
116
isDesc =
true
;
117
strDesc = token.substr(5);
118
}
else
{
119
// target particle's name in collision parsing
120
if
((token.length() > 7) && (token.substr(0, 7) ==
"target="
)) {
121
isTarget =
true
;
122
strTarget = token.substr(7);
123
}
else
{
124
// path parsing
125
if
((token.length() > 5) && (token.substr(0, 5) ==
"path="
)) {
126
isPath =
true
;
127
strPath = token.substr(5);
128
}
129
}
// else TYPE of data
130
}
// else DESC
131
}
// else PARTICLE
132
}
// else ENERGY
133
}
// else GEN
134
}
// while(getline(ss, token, ','))
135
}
// for (int i = 1; i < argc; i++)
136
137
// generate query
138
TString
strConnection =
"pgsql://"
+
TString
(
UNI_DB_HOST
) +
"/"
+ (
TString
)
UNI_DB_NAME
;
139
TSQLServer
* pSQLServer =
TSQLServer::Connect
(strConnection,
UNI_DB_USERNAME
,
UNI_DB_PASSWORD
);
140
if
(pSQLServer ==
nullptr
) {
141
cout <<
"Connection to the database was not established"
<< endl;
142
return
-1;
143
}
144
145
TString
sql =
"select file_path "
146
"from simulation_file"
;
147
148
bool
isWhere =
false
;
149
// if event generator selection
150
if
(isGen ==
true
) {
151
if
(isWhere)
152
sql +=
TString::Format
(
" AND lower(generator_name) = '%s'"
, strGen.data());
153
else
{
154
isWhere =
true
;
155
sql +=
TString::Format
(
" "
156
"where lower(generator_name) = '%s'"
,
157
strGen.data());
158
}
159
}
160
// if energy selection
161
if
(isEnergy ==
true
) {
162
if
(isWhere)
163
sql +=
" AND "
;
164
else
{
165
isWhere =
true
;
166
sql +=
" "
167
"where "
;
168
}
169
170
if
(isMinEnergy) {
171
sql +=
TString::Format
(
"energy >= %f"
, fEnergy);
172
if
(isMaxEnergy)
173
sql +=
TString::Format
(
" AND energy <= %f"
, fMaxEnergy);
174
}
else
{
175
if
(isMaxEnergy)
176
sql +=
TString::Format
(
"energy <= %f"
, fMaxEnergy);
177
else
178
sql +=
TString::Format
(
"energy = %f"
, fEnergy);
179
}
180
}
181
// if beam particle was selected
182
if
(isBeam ==
true
) {
183
if
(isWhere)
184
sql +=
TString::Format
(
" AND lower(beam_particle) = '%s'"
, strBeam.data());
185
else
{
186
isWhere =
true
;
187
sql +=
TString::Format
(
" "
188
"where lower(beam_particle) = '%s'"
,
189
strBeam.data());
190
}
191
}
192
// if target particle was selected
193
if
(isTarget ==
true
) {
194
if
(isWhere)
195
sql +=
TString::Format
(
" AND lower(target_particle) = '%s'"
, strTarget.data());
196
else
{
197
isWhere =
true
;
198
sql +=
TString::Format
(
" "
199
"where lower(target_particle) = '%s'"
,
200
strTarget.data());
201
}
202
}
203
if
(isDesc ==
true
) {
204
if
(isWhere)
205
sql +=
TString::Format
(
" AND lower(file_desc) like '%%%s%%'"
, strDesc.data());
206
else
{
207
isWhere =
true
;
208
sql +=
TString::Format
(
" "
209
"where lower(file_desc) like '%%%s%%'"
,
210
strDesc.data());
211
}
212
}
213
if
(isPath ==
true
) {
214
if
(isWhere)
215
sql +=
TString::Format
(
" AND lower(file_path) like '%%%s%%'"
, strPath.data());
216
else
{
217
isWhere =
true
;
218
sql +=
TString::Format
(
" "
219
"where lower(file_path) like '%%%s%%'"
,
220
strPath.data());
221
}
222
}
223
224
sql +=
" order by generator_name,energy"
;
225
// cout<<sql<<endl;
226
227
TSQLResult
* res = pSQLServer->
Query
(sql);
228
229
int
nrows = res->GetRowCount();
230
if
(nrows == 0)
231
cout <<
"There are no simulation files for these parameters"
<< endl;
232
else
{
233
TSQLRow
* row;
234
while
((row = res->Next()) !=
nullptr
) {
235
TString
path = row->
GetField
(0);
236
cout << path << endl;
237
238
delete
row;
239
}
240
241
cout << endl <<
"Total count: "
<< nrows << endl;
242
}
243
244
delete
res;
245
246
if
(pSQLServer)
247
delete
pSQLServer;
248
249
return
0;
250
}
i
int i
Definition
P4_F32vec4.h:22
TSQLResult.h
TSQLRow.h
TSQLServer.h
TString.h
TSQLResult
TSQLRow
TSQLRow::GetField
virtual const char * GetField(Int_t field)=0
TSQLServer
TSQLServer::Query
virtual TSQLResult * Query(const char *sql)=0
TSQLServer::Connect
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
TString
TString::Format
static TString Format(const char *fmt,...)
uni_db_settings.h
UNI_DB_HOST
const char *const UNI_DB_HOST
Definition
uni_db_settings.h:9
UNI_DB_NAME
const char *const UNI_DB_NAME
Definition
uni_db_settings.h:10
UNI_DB_PASSWORD
const char *const UNI_DB_PASSWORD
Definition
uni_db_settings.h:8
UNI_DB_USERNAME
const char *const UNI_DB_USERNAME
Definition
uni_db_settings.h:7
std
Definition
json.hpp:4446
main
int main(void)
Definition
test_FC.cpp:33
database
uni_db
show_simulation_files.cxx
Generated on
for BmnRoot by
1.17.0