25int main(
int argc,
char** argv)
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
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;
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++) {
57 string input = argv[
i];
58 istringstream ss(input);
62 while (getline(ss, token,
',')) {
64 transform(token.begin(), token.end(), token.begin(), ::tolower);
67 if ((token.length() > 4) && (token.substr(0, 4) ==
"gen=")) {
69 strGen = token.substr(4);
72 if ((token.length() > 7) && (token.substr(0, 7) ==
"energy=")) {
73 token = token.substr(7);
75 size_t indDash = token.find_first_of(
'-');
76 if (indDash != string::npos) {
78 stream << token.substr(0, indDash);
85 if (token.length() > indDash) {
87 stream2 << token.substr(indDash + 1);
88 if (stream2 >> dVal) {
101 if (stream >> dVal) {
110 if ((token.length() > 5) && (token.substr(0, 5) ==
"beam=")) {
112 strBeam = token.substr(5);
115 if ((token.length() > 5) && (token.substr(0, 5) ==
"desc=")) {
117 strDesc = token.substr(5);
120 if ((token.length() > 7) && (token.substr(0, 7) ==
"target=")) {
122 strTarget = token.substr(7);
125 if ((token.length() > 5) && (token.substr(0, 5) ==
"path=")) {
127 strPath = token.substr(5);
140 if (pSQLServer ==
nullptr) {
141 cout <<
"Connection to the database was not established" << endl;
145 TString sql =
"select file_path "
146 "from simulation_file";
148 bool isWhere =
false;
152 sql += TString::Format(
" AND lower(generator_name) = '%s'", strGen.data());
155 sql += TString::Format(
" "
156 "where lower(generator_name) = '%s'",
161 if (isEnergy ==
true) {
171 sql += TString::Format(
"energy >= %f", fEnergy);
173 sql += TString::Format(
" AND energy <= %f", fMaxEnergy);
176 sql += TString::Format(
"energy <= %f", fMaxEnergy);
178 sql += TString::Format(
"energy = %f", fEnergy);
182 if (isBeam ==
true) {
184 sql += TString::Format(
" AND lower(beam_particle) = '%s'", strBeam.data());
187 sql += TString::Format(
" "
188 "where lower(beam_particle) = '%s'",
193 if (isTarget ==
true) {
195 sql += TString::Format(
" AND lower(target_particle) = '%s'", strTarget.data());
198 sql += TString::Format(
" "
199 "where lower(target_particle) = '%s'",
203 if (isDesc ==
true) {
205 sql += TString::Format(
" AND lower(file_desc) like '%%%s%%'", strDesc.data());
208 sql += TString::Format(
" "
209 "where lower(file_desc) like '%%%s%%'",
213 if (isPath ==
true) {
215 sql += TString::Format(
" AND lower(file_path) like '%%%s%%'", strPath.data());
218 sql += TString::Format(
" "
219 "where lower(file_path) like '%%%s%%'",
224 sql +=
" order by generator_name,energy";
227 TSQLResult* res = pSQLServer->Query(sql);
229 int nrows = res->GetRowCount();
231 cout <<
"There are no simulation files for these parameters" << endl;
234 while ((row = res->Next()) !=
nullptr) {
235 TString path = row->GetField(0);
236 cout << path << endl;
241 cout << endl <<
"Total count: " << nrows << endl;