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 experimental raw files satisfying the given parameters." << endl
32 <<
"Parameters separated by comma:" << endl
33 <<
"period - period number (range is supported by '-' symbol)" << endl
34 <<
"run - run number (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 <<
"energy - collision energy (range is supported by '-' symbol)" << endl
38 <<
"events - event count (range is supported by '-' symbol)" << endl
39 <<
"time - experimental file (or files in case of the time interval) including event at this time "
40 "(range is supported by '-' symbol), datetime format - yyyy-mm-dd 24hh:mm:ss"
42 <<
"field - field current (range is supported by '-' symbol)" << endl
43 <<
"size - file size (range is supported by '-' symbol)" << endl
44 <<
"path - part of the file path" << endl
46 <<
"Examples:" << endl
47 <<
"show_experiment_files period=5,energy=3-,beam=d,target=C" << endl
48 <<
"show_experiment_files period=4-5,field=-800" << endl;
55 bool isPeriod =
false, isMinPeriod =
false, isMaxPeriod =
false, isRun =
false, isMinRun =
false, isMaxRun =
false,
56 isBeam =
false, isTarget =
false, isEnergy =
false, isMinEnergy =
false, isMaxEnergy =
false, isEvents =
false,
57 isMinEvents =
false, isMaxEvents =
false, isTime =
false, isMinTime =
false, isMaxTime =
false,
58 isField =
false, isMinField =
false, isMaxField =
false, isSize =
false, isMinSize =
false, isMaxSize =
false,
60 string strBeam, strTarget, strTime, strMaxTime, strPath;
61 int iPeriod, iMaxPeriod, iRun, iMaxRun, iEvents, iMaxEvents, iField, iMaxField;
62 double fEnergy, fMaxEnergy, fSize, fMaxSize;
63 for (
int i = 1;
i < argc;
i++) {
67 string input = argv[
i];
68 istringstream ss(input);
72 while (getline(ss, token,
',')) {
74 transform(token.begin(), token.end(), token.begin(), ::tolower);
77 if ((token.length() > 7) && (token.substr(0, 7) ==
"period=")) {
78 token = token.substr(7);
80 size_t indDash = token.find_first_of(
'-');
81 if (indDash != string::npos) {
83 stream << token.substr(0, indDash);
90 if (token.length() > indDash) {
92 stream2 << token.substr(indDash + 1);
93 if (stream2 >> iVal) {
106 if (stream >> iVal) {
115 if ((token.length() > 4) && (token.substr(0, 4) ==
"run=")) {
116 token = token.substr(4);
118 size_t indDash = token.find_first_of(
'-');
119 if (indDash != string::npos) {
121 stream << token.substr(0, indDash);
123 if (stream >> iVal) {
128 if (token.length() > indDash) {
129 stringstream stream2;
130 stream2 << token.substr(indDash + 1);
131 if (stream2 >> iVal) {
144 if (stream >> iVal) {
153 if ((token.length() > 5) && (token.substr(0, 5) ==
"beam=")) {
155 strBeam = token.substr(5);
158 if ((token.length() > 7) && (token.substr(0, 7) ==
"target=")) {
160 strTarget = token.substr(7);
163 if ((token.length() > 7) && (token.substr(0, 7) ==
"energy=")) {
164 token = token.substr(7);
166 size_t indDash = token.find_first_of(
'-');
167 if (indDash != string::npos) {
169 stream << token.substr(0, indDash);
171 if (stream >> dVal) {
176 if (token.length() > indDash) {
177 stringstream stream2;
178 stream2 << token.substr(indDash + 1);
179 if (stream2 >> dVal) {
192 if (stream >> dVal) {
201 if ((token.length() > 6) && (token.substr(0, 6) ==
"events=")) {
202 token = token.substr(6);
204 size_t indDash = token.find_first_of(
'-');
205 if (indDash != string::npos) {
207 stream << token.substr(0, indDash);
209 if (stream >> iVal) {
214 if (token.length() > indDash) {
215 stringstream stream2;
216 stream2 << token.substr(indDash + 1);
217 if (stream2 >> iVal) {
230 if (stream >> iVal) {
239 if ((token.length() > 5) && (token.substr(0, 5) ==
"time=")) {
240 token = token.substr(5);
242 size_t indDash = token.find_first_of(
'-');
243 if (indDash != string::npos) {
247 strTime = token.substr(0, indDash);
249 if (token.length() > indDash) {
252 strMaxTime = token.substr(indDash + 1);
265 if ((token.length() > 6) && (token.substr(0, 6) ==
"field=")) {
266 token = token.substr(6);
268 size_t indDash = token.find_first_of(
'-');
269 if (indDash != string::npos) {
271 stream << token.substr(0, indDash);
273 if (stream >> iVal) {
278 if (token.length() > indDash) {
279 stringstream stream2;
280 stream2 << token.substr(indDash + 1);
281 if (stream2 >> iVal) {
294 if (stream >> iVal) {
303 if ((token.length() > 5) && (token.substr(0, 5) ==
"size=")) {
304 token = token.substr(5);
306 size_t indDash = token.find_first_of(
'-');
307 if (indDash != string::npos) {
309 stream << token.substr(0, indDash);
311 if (stream >> dVal) {
316 if (token.length() > indDash) {
317 stringstream stream2;
318 stream2 << token.substr(indDash + 1);
319 if (stream2 >> dVal) {
332 if (stream >> dVal) {
341 if ((token.length() > 5) && (token.substr(0, 5) ==
"path=")) {
343 strPath = token.substr(5);
360 if (pSQLServer ==
nullptr) {
361 cout <<
"Connection to the database was not established" << endl;
365 TString sql =
"select file_path "
368 bool isWhere =
false;
370 if (isPeriod ==
true) {
380 sql += TString::Format(
"period_number >= %d", iPeriod);
382 sql += TString::Format(
" AND period_number <= %d", iMaxPeriod);
385 sql += TString::Format(
"period_number <= %d", iMaxPeriod);
387 sql += TString::Format(
"period_number = %d", iPeriod);
401 sql += TString::Format(
"run_number >= %d", iRun);
403 sql += TString::Format(
" AND run_number <= %d", iMaxRun);
406 sql += TString::Format(
"run_number <= %d", iMaxRun);
408 sql += TString::Format(
"run_number = %d", iRun);
412 if (isBeam ==
true) {
414 sql += TString::Format(
" AND lower(beam_particle) = '%s'", strBeam.data());
417 sql += TString::Format(
" "
418 "where lower(beam_particle) = '%s'",
423 if (isTarget ==
true) {
425 sql += TString::Format(
" AND lower(target_particle) = '%s'", strTarget.data());
428 sql += TString::Format(
" "
429 "where lower(target_particle) = '%s'",
434 if (isEnergy ==
true) {
444 sql += TString::Format(
"energy >= %f", fEnergy);
446 sql += TString::Format(
" AND energy <= %f", fMaxEnergy);
449 sql += TString::Format(
"energy <= %f", fMaxEnergy);
451 sql += TString::Format(
"energy = %f", fEnergy);
455 if (isEvents ==
true) {
465 sql += TString::Format(
"event_count >= %d", iEvents);
467 sql += TString::Format(
" AND event_count <= %d", iMaxEvents);
470 sql += TString::Format(
"event_count <= %d", iMaxEvents);
472 sql += TString::Format(
"event_count = %d", iEvents);
476 if (isTime ==
true) {
487 if (!strptime(strMaxTime.c_str(),
"%Y-%m-%d %H:%M:%S", &tm)) {
489 cout <<
"ERROR: " << strMaxTime
490 <<
" is not correct datetime. DateTime format should be yyyy-mm-dd 24hh:mm:ss." << endl;
492 if (!strptime(strTime.c_str(),
"%Y-%m-%d %H:%M:%S", &tm)) {
494 cout <<
"ERROR: " << strTime <<
" is not correct datetime. DateTime format should be yyyy-mm-dd 24hh:mm:ss."
501 sql += TString::Format(
"end_datetime >= '%s'", strTime.c_str());
503 sql += TString::Format(
" AND start_datetime <= '%s'", strMaxTime.c_str());
506 sql += TString::Format(
"start_datetime <= '%s'", strMaxTime.c_str());
509 sql += TString::Format(
"start_datetime <= '%s' AND end_datetime >= '%s'", strTime.c_str(),
515 if (isField ==
true) {
525 sql += TString::Format(
"field_voltage >= %d", iField);
527 sql += TString::Format(
" AND field_voltage <= %d", iMaxField);
530 sql += TString::Format(
"field_voltage <= %d", iMaxField);
532 sql += TString::Format(
"field_voltage = %d", iField);
536 if (isSize ==
true) {
546 sql += TString::Format(
"file_size >= %f", fSize);
548 sql += TString::Format(
" AND file_size <= %f", fMaxSize);
551 sql += TString::Format(
"file_size <= %f", fMaxSize);
553 sql += TString::Format(
"file_size = %f", fSize);
556 if (isPath ==
true) {
558 sql += TString::Format(
" AND lower(file_path) like '%%%s%%'", strPath.data());
561 sql += TString::Format(
" "
562 "where lower(file_path) like '%%%s%%'",
567 sql +=
" order by period_number,run_number";
570 TSQLResult* res = pSQLServer->Query(sql);
572 int nrows = res->GetRowCount();
574 cout <<
"There are no experimental files for these parameters" << endl;
577 while ((row = res->Next()) !=
nullptr) {
578 TString path = row->GetField(0);
579 cout << path << endl;
584 cout << endl <<
"Total count: " << nrows << endl;