BmnRoot
Loading...
Searching...
No Matches
UniSimulationFile.cxx
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2// UniSimulationFile cxx file
3// Generated 05-11-2015
4// ----------------------------------------------------------------------
5
6#include "UniSimulationFile.h"
7
8#include "TObjArray.h"
9#include "TSQLServer.h"
10#include "TSQLStatement.h"
11
12#include <iostream>
13using namespace std;
14
15/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */
16// ----- Constructor with database connection -----------------------
17UniSimulationFile::UniSimulationFile(UniConnection* db_connect,
18 int file_id,
19 TString generator_name,
20 int file_type,
21 TString file_path,
22 TString beam_particle,
23 TString target_particle,
24 double* energy,
25 TString centrality,
26 int* event_count,
27 int64_t* file_size,
28 TString* file_hash,
29 TString* file_desc)
30{
31 connectionDB = db_connect;
32
33 i_file_id = file_id;
34 str_generator_name = generator_name;
35 i_file_type = file_type;
36 str_file_path = file_path;
37 str_beam_particle = beam_particle;
38 str_target_particle = target_particle;
39 d_energy = energy;
40 str_centrality = centrality;
41 i_event_count = event_count;
42 i64_file_size = file_size;
43 str_file_hash = file_hash;
44 str_file_desc = file_desc;
45}
46
47// ----- Destructor -------------------------------------------------
49{
50 if (connectionDB)
51 delete connectionDB;
52 if (d_energy)
53 delete d_energy;
54 if (i_event_count)
55 delete i_event_count;
56 if (i64_file_size)
57 delete i64_file_size;
58 if (str_file_hash)
59 delete str_file_hash;
60 if (str_file_desc)
61 delete str_file_desc;
62}
63
64// ----- Creating new simulation file in the database ---------------------------
66 int file_type,
67 TString file_path,
68 TString beam_particle,
69 TString target_particle,
70 double* energy,
71 TString centrality,
72 int* event_count,
73 int64_t* file_size,
74 TString* file_hash,
75 TString* file_desc)
76{
78 if (connDb == nullptr)
79 return nullptr;
80
81 TSQLServer* db_server = connDb->GetSQLServer();
82
83 TString sql = TString::Format("insert into simulation_file(generator_name, file_type, file_path, beam_particle, "
84 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc) "
85 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)");
86 TSQLStatement* stmt = db_server->Statement(sql);
87
88 stmt->NextIteration();
89 stmt->SetString(0, generator_name);
90 stmt->SetInt(1, file_type);
91 stmt->SetString(2, file_path);
92 stmt->SetString(3, beam_particle);
93 stmt->SetString(4, target_particle);
94 if (energy == nullptr)
95 stmt->SetNull(5);
96 else
97 stmt->SetDouble(5, *energy);
98 stmt->SetString(6, centrality);
99 if (event_count == nullptr)
100 stmt->SetNull(7);
101 else
102 stmt->SetInt(7, *event_count);
103 if (file_size == nullptr)
104 stmt->SetNull(8);
105 else
106 stmt->SetLong64(8, *file_size);
107 if (file_hash == nullptr)
108 stmt->SetNull(9);
109 else
110 stmt->SetString(9, *file_hash);
111 if (file_desc == nullptr)
112 stmt->SetNull(10);
113 else
114 stmt->SetString(10, *file_desc);
115
116 // inserting new simulation file to the Database
117 if (!stmt->Process()) {
118 cout << "ERROR: inserting new simulation file to the Database has been failed" << endl;
119 delete stmt;
120 delete connDb;
121 return nullptr;
122 }
123
124 delete stmt;
125
126 // getting last inserted ID
127 int file_id;
128 TSQLStatement* stmt_last =
129 db_server->Statement("SELECT currval(pg_get_serial_sequence('simulation_file','file_id'))");
130
131 // process getting last id
132 if (stmt_last->Process()) {
133 // store result of statement in buffer
134 stmt_last->StoreResult();
135
136 // if there is no last id then exit with error
137 if (!stmt_last->NextResultRow()) {
138 cout << "ERROR: no last ID in DB!" << endl;
139 delete stmt_last;
140 return nullptr;
141 } else {
142 file_id = stmt_last->GetInt(0);
143 delete stmt_last;
144 }
145 } else {
146 cout << "ERROR: getting last ID has been failed!" << endl;
147 delete stmt_last;
148 return nullptr;
149 }
150
151 int tmp_file_id;
152 tmp_file_id = file_id;
153 TString tmp_generator_name;
154 tmp_generator_name = generator_name;
155 int tmp_file_type;
156 tmp_file_type = file_type;
157 TString tmp_file_path;
158 tmp_file_path = file_path;
159 TString tmp_beam_particle;
160 tmp_beam_particle = beam_particle;
161 TString tmp_target_particle;
162 tmp_target_particle = target_particle;
163 double* tmp_energy;
164 if (energy == nullptr)
165 tmp_energy = nullptr;
166 else
167 tmp_energy = new double(*energy);
168 TString tmp_centrality;
169 tmp_centrality = centrality;
170 int* tmp_event_count;
171 if (event_count == nullptr)
172 tmp_event_count = nullptr;
173 else
174 tmp_event_count = new int(*event_count);
175 int64_t* tmp_file_size;
176 if (file_size == nullptr)
177 tmp_file_size = nullptr;
178 else
179 tmp_file_size = new int64_t(*file_size);
180 TString* tmp_file_hash;
181 if (file_hash == nullptr)
182 tmp_file_hash = nullptr;
183 else
184 tmp_file_hash = new TString(*file_hash);
185 TString* tmp_file_desc;
186 if (file_desc == nullptr)
187 tmp_file_desc = nullptr;
188 else
189 tmp_file_desc = new TString(*file_desc);
190
191 return new UniSimulationFile(connDb, tmp_file_id, tmp_generator_name, tmp_file_type, tmp_file_path,
192 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_centrality, tmp_event_count,
193 tmp_file_size, tmp_file_hash, tmp_file_desc);
194}
195
196// ----- Get simulation file from the database ---------------------------
198{
200 if (connDb == nullptr)
201 return nullptr;
202
203 TSQLServer* db_server = connDb->GetSQLServer();
204
205 TString sql = TString::Format("select file_id, generator_name, file_type, file_path, beam_particle, "
206 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc "
207 "from simulation_file "
208 "where file_id = %d",
209 file_id);
210 TSQLStatement* stmt = db_server->Statement(sql);
211
212 // get simulation file from the database
213 if (!stmt->Process()) {
214 cout << "ERROR: getting simulation file from the database has been failed" << endl;
215
216 delete stmt;
217 delete connDb;
218 return nullptr;
219 }
220
221 // store result of statement in buffer
222 stmt->StoreResult();
223
224 // extract row
225 if (!stmt->NextResultRow()) {
226 cout << "ERROR: simulation file was not found in the database" << endl;
227
228 delete stmt;
229 delete connDb;
230 return nullptr;
231 }
232
233 int tmp_file_id;
234 tmp_file_id = stmt->GetInt(0);
235 TString tmp_generator_name;
236 tmp_generator_name = stmt->GetString(1);
237 int tmp_file_type;
238 tmp_file_type = stmt->GetInt(2);
239 TString tmp_file_path;
240 tmp_file_path = stmt->GetString(3);
241 TString tmp_beam_particle;
242 tmp_beam_particle = stmt->GetString(4);
243 TString tmp_target_particle;
244 tmp_target_particle = stmt->GetString(5);
245 double* tmp_energy;
246 if (stmt->IsNull(6))
247 tmp_energy = nullptr;
248 else
249 tmp_energy = new double(stmt->GetDouble(6));
250 TString tmp_centrality;
251 tmp_centrality = stmt->GetString(7);
252 int* tmp_event_count;
253 if (stmt->IsNull(8))
254 tmp_event_count = nullptr;
255 else
256 tmp_event_count = new int(stmt->GetInt(8));
257 int64_t* tmp_file_size;
258 if (stmt->IsNull(9))
259 tmp_file_size = nullptr;
260 else
261 tmp_file_size = new int64_t(stmt->GetLong64(9));
262 TString* tmp_file_hash;
263 if (stmt->IsNull(10))
264 tmp_file_hash = nullptr;
265 else
266 tmp_file_hash = new TString(stmt->GetString(10));
267 TString* tmp_file_desc;
268 if (stmt->IsNull(11))
269 tmp_file_desc = nullptr;
270 else
271 tmp_file_desc = new TString(stmt->GetString(11));
272
273 delete stmt;
274
275 return new UniSimulationFile(connDb, tmp_file_id, tmp_generator_name, tmp_file_type, tmp_file_path,
276 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_centrality, tmp_event_count,
277 tmp_file_size, tmp_file_hash, tmp_file_desc);
278}
279
280// ----- Get simulation file from the database by unique key --------------
282{
284 if (connDb == nullptr)
285 return nullptr;
286
287 TSQLServer* db_server = connDb->GetSQLServer();
288
289 TString sql = TString::Format("select file_id, generator_name, file_type, file_path, beam_particle, "
290 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc "
291 "from simulation_file "
292 "where lower(file_path) = lower('%s')",
293 file_path.Data());
294 TSQLStatement* stmt = db_server->Statement(sql);
295
296 // get simulation file from the database
297 if (!stmt->Process()) {
298 cout << "ERROR: getting simulation file from the database has been failed" << endl;
299
300 delete stmt;
301 delete connDb;
302 return nullptr;
303 }
304
305 // store result of statement in buffer
306 stmt->StoreResult();
307
308 // extract row
309 if (!stmt->NextResultRow()) {
310 cout << "ERROR: simulation file was not found in the database" << endl;
311
312 delete stmt;
313 delete connDb;
314 return nullptr;
315 }
316
317 int tmp_file_id;
318 tmp_file_id = stmt->GetInt(0);
319 TString tmp_generator_name;
320 tmp_generator_name = stmt->GetString(1);
321 int tmp_file_type;
322 tmp_file_type = stmt->GetInt(2);
323 TString tmp_file_path;
324 tmp_file_path = stmt->GetString(3);
325 TString tmp_beam_particle;
326 tmp_beam_particle = stmt->GetString(4);
327 TString tmp_target_particle;
328 tmp_target_particle = stmt->GetString(5);
329 double* tmp_energy;
330 if (stmt->IsNull(6))
331 tmp_energy = nullptr;
332 else
333 tmp_energy = new double(stmt->GetDouble(6));
334 TString tmp_centrality;
335 tmp_centrality = stmt->GetString(7);
336 int* tmp_event_count;
337 if (stmt->IsNull(8))
338 tmp_event_count = nullptr;
339 else
340 tmp_event_count = new int(stmt->GetInt(8));
341 int64_t* tmp_file_size;
342 if (stmt->IsNull(9))
343 tmp_file_size = nullptr;
344 else
345 tmp_file_size = new int64_t(stmt->GetLong64(9));
346 TString* tmp_file_hash;
347 if (stmt->IsNull(10))
348 tmp_file_hash = nullptr;
349 else
350 tmp_file_hash = new TString(stmt->GetString(10));
351 TString* tmp_file_desc;
352 if (stmt->IsNull(11))
353 tmp_file_desc = nullptr;
354 else
355 tmp_file_desc = new TString(stmt->GetString(11));
356
357 delete stmt;
358
359 return new UniSimulationFile(connDb, tmp_file_id, tmp_generator_name, tmp_file_type, tmp_file_path,
360 tmp_beam_particle, tmp_target_particle, tmp_energy, tmp_centrality, tmp_event_count,
361 tmp_file_size, tmp_file_hash, tmp_file_desc);
362}
363
364// ----- Check simulation file exists in the database ---------------------------
366{
368 if (connDb == nullptr)
369 return -1;
370
371 TSQLServer* db_server = connDb->GetSQLServer();
372
373 TString sql = TString::Format("select 1 "
374 "from simulation_file "
375 "where file_id = %d",
376 file_id);
377 TSQLStatement* stmt = db_server->Statement(sql);
378
379 // get simulation file from the database
380 if (!stmt->Process()) {
381 cout << "ERROR: getting simulation file from the database has been failed" << endl;
382
383 delete stmt;
384 delete connDb;
385 return -2;
386 }
387
388 // store result of statement in buffer
389 stmt->StoreResult();
390
391 // extract row
392 if (!stmt->NextResultRow()) {
393 delete stmt;
394 delete connDb;
395 return 0;
396 }
397
398 delete stmt;
399 delete connDb;
400
401 return 1;
402}
403
404// ----- Check simulation file exists in the database by unique key --------------
406{
408 if (connDb == nullptr)
409 return -1;
410
411 TSQLServer* db_server = connDb->GetSQLServer();
412
413 TString sql = TString::Format("select 1 "
414 "from simulation_file "
415 "where lower(file_path) = lower('%s')",
416 file_path.Data());
417 TSQLStatement* stmt = db_server->Statement(sql);
418
419 // get simulation file from the database
420 if (!stmt->Process()) {
421 cout << "ERROR: getting simulation file from the database has been failed" << endl;
422
423 delete stmt;
424 delete connDb;
425 return -2;
426 }
427
428 // store result of statement in buffer
429 stmt->StoreResult();
430
431 // extract row
432 if (!stmt->NextResultRow()) {
433 delete stmt;
434 delete connDb;
435 return 0;
436 }
437
438 delete stmt;
439 delete connDb;
440
441 return 1;
442}
443
444// ----- Delete simulation file from the database ---------------------------
446{
448 if (connDb == nullptr)
449 return -1;
450
451 TSQLServer* db_server = connDb->GetSQLServer();
452
453 TString sql = TString::Format("delete from simulation_file "
454 "where file_id = $1");
455 TSQLStatement* stmt = db_server->Statement(sql);
456
457 stmt->NextIteration();
458 stmt->SetInt(0, file_id);
459
460 // delete simulation file from the dataBase
461 if (!stmt->Process()) {
462 cout << "ERROR: deleting simulation file from the dataBase has been failed" << endl;
463
464 delete stmt;
465 delete connDb;
466 return -2;
467 }
468
469 delete stmt;
470 delete connDb;
471 return 0;
472}
473
474// ----- Delete simulation file from the database by unique key --------------
476{
478 if (connDb == nullptr)
479 return -1;
480
481 TSQLServer* db_server = connDb->GetSQLServer();
482
483 TString sql = TString::Format("delete from simulation_file "
484 "where lower(file_path) = lower($1)");
485 TSQLStatement* stmt = db_server->Statement(sql);
486
487 stmt->NextIteration();
488 stmt->SetString(0, file_path);
489
490 // delete simulation file from the dataBase
491 if (!stmt->Process()) {
492 cout << "ERROR: deleting simulation file from the DataBase has been failed" << endl;
493
494 delete stmt;
495 delete connDb;
496 return -2;
497 }
498
499 delete stmt;
500 delete connDb;
501 return 0;
502}
503
504// ----- Print all 'simulation files' ---------------------------------
506{
508 if (connDb == nullptr)
509 return -1;
510
511 TSQLServer* db_server = connDb->GetSQLServer();
512
513 TString sql = TString::Format("select file_id, generator_name, file_type, file_path, beam_particle, "
514 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc "
515 "from simulation_file");
516 TSQLStatement* stmt = db_server->Statement(sql);
517
518 // get all 'simulation files' from the database
519 if (!stmt->Process()) {
520 cout << "ERROR: getting all 'simulation files' from the dataBase has been failed" << endl;
521
522 delete stmt;
523 delete connDb;
524 return -2;
525 }
526
527 // store result of statement in buffer
528 stmt->StoreResult();
529
530 // print rows
531 cout << "Table 'simulation_file':" << endl;
532 while (stmt->NextResultRow()) {
533 cout << "file_id: ";
534 cout << (stmt->GetInt(0));
535 cout << ", generator_name: ";
536 cout << (stmt->GetString(1));
537 cout << ", file_type: ";
538 cout << (stmt->GetInt(2));
539 cout << ", file_path: ";
540 cout << (stmt->GetString(3));
541 cout << ", beam_particle: ";
542 cout << (stmt->GetString(4));
543 cout << ", target_particle: ";
544 cout << (stmt->GetString(5));
545 cout << ", energy: ";
546 if (stmt->IsNull(6))
547 cout << "nullptr";
548 else
549 cout << stmt->GetDouble(6);
550 cout << ", centrality: ";
551 cout << (stmt->GetString(7));
552 cout << ", event_count: ";
553 if (stmt->IsNull(8))
554 cout << "nullptr";
555 else
556 cout << stmt->GetInt(8);
557 cout << ", file_size: ";
558 if (stmt->IsNull(9))
559 cout << "nullptr";
560 else
561 cout << stmt->GetLong64(9);
562 cout << ", file_hash: ";
563 if (stmt->IsNull(10))
564 cout << "nullptr";
565 else
566 cout << stmt->GetString(10);
567 cout << ", file_desc: ";
568 if (stmt->IsNull(11))
569 cout << "nullptr";
570 else
571 cout << stmt->GetString(11);
572 cout << "." << endl;
573 }
574
575 delete stmt;
576 delete connDb;
577
578 return 0;
579}
580
581// Setters functions
582int UniSimulationFile::SetGeneratorName(TString generator_name)
583{
584 if (!connectionDB) {
585 cout << "CRITICAL ERROR: Connection object is null" << endl;
586 return -1;
587 }
588
589 TSQLServer* db_server = connectionDB->GetSQLServer();
590
591 TString sql = TString::Format("update simulation_file "
592 "set generator_name = $1 "
593 "where file_id = $2");
594 TSQLStatement* stmt = db_server->Statement(sql);
595
596 stmt->NextIteration();
597 stmt->SetString(0, generator_name);
598 stmt->SetInt(1, i_file_id);
599
600 // write new value to the database
601 if (!stmt->Process()) {
602 cout << "ERROR: updating information about simulation file has been failed" << endl;
603
604 delete stmt;
605 return -2;
606 }
607
608 str_generator_name = generator_name;
609
610 delete stmt;
611 return 0;
612}
613
615{
616 if (!connectionDB) {
617 cout << "CRITICAL ERROR: Connection object is null" << endl;
618 return -1;
619 }
620
621 TSQLServer* db_server = connectionDB->GetSQLServer();
622
623 TString sql = TString::Format("update simulation_file "
624 "set file_type = $1 "
625 "where file_id = $2");
626 TSQLStatement* stmt = db_server->Statement(sql);
627
628 stmt->NextIteration();
629 stmt->SetInt(0, file_type);
630 stmt->SetInt(1, i_file_id);
631
632 // write new value to the database
633 if (!stmt->Process()) {
634 cout << "ERROR: updating information about simulation file has been failed" << endl;
635
636 delete stmt;
637 return -2;
638 }
639
640 i_file_type = file_type;
641
642 delete stmt;
643 return 0;
644}
645
646int UniSimulationFile::SetFilePath(TString file_path)
647{
648 if (!connectionDB) {
649 cout << "CRITICAL ERROR: Connection object is null" << endl;
650 return -1;
651 }
652
653 TSQLServer* db_server = connectionDB->GetSQLServer();
654
655 TString sql = TString::Format("update simulation_file "
656 "set file_path = $1 "
657 "where file_id = $2");
658 TSQLStatement* stmt = db_server->Statement(sql);
659
660 stmt->NextIteration();
661 stmt->SetString(0, file_path);
662 stmt->SetInt(1, i_file_id);
663
664 // write new value to the database
665 if (!stmt->Process()) {
666 cout << "ERROR: updating information about simulation file has been failed" << endl;
667
668 delete stmt;
669 return -2;
670 }
671
672 str_file_path = file_path;
673
674 delete stmt;
675 return 0;
676}
677
678int UniSimulationFile::SetBeamParticle(TString beam_particle)
679{
680 if (!connectionDB) {
681 cout << "CRITICAL ERROR: Connection object is null" << endl;
682 return -1;
683 }
684
685 TSQLServer* db_server = connectionDB->GetSQLServer();
686
687 TString sql = TString::Format("update simulation_file "
688 "set beam_particle = $1 "
689 "where file_id = $2");
690 TSQLStatement* stmt = db_server->Statement(sql);
691
692 stmt->NextIteration();
693 stmt->SetString(0, beam_particle);
694 stmt->SetInt(1, i_file_id);
695
696 // write new value to the database
697 if (!stmt->Process()) {
698 cout << "ERROR: updating information about simulation file has been failed" << endl;
699
700 delete stmt;
701 return -2;
702 }
703
704 str_beam_particle = beam_particle;
705
706 delete stmt;
707 return 0;
708}
709
710int UniSimulationFile::SetTargetParticle(TString target_particle)
711{
712 if (!connectionDB) {
713 cout << "CRITICAL ERROR: Connection object is null" << endl;
714 return -1;
715 }
716
717 TSQLServer* db_server = connectionDB->GetSQLServer();
718
719 TString sql = TString::Format("update simulation_file "
720 "set target_particle = $1 "
721 "where file_id = $2");
722 TSQLStatement* stmt = db_server->Statement(sql);
723
724 stmt->NextIteration();
725 stmt->SetString(0, target_particle);
726 stmt->SetInt(1, i_file_id);
727
728 // write new value to the database
729 if (!stmt->Process()) {
730 cout << "ERROR: updating information about simulation file has been failed" << endl;
731
732 delete stmt;
733 return -2;
734 }
735
736 str_target_particle = target_particle;
737
738 delete stmt;
739 return 0;
740}
741
743{
744 if (!connectionDB) {
745 cout << "CRITICAL ERROR: Connection object is null" << endl;
746 return -1;
747 }
748
749 TSQLServer* db_server = connectionDB->GetSQLServer();
750
751 TString sql = TString::Format("update simulation_file "
752 "set energy = $1 "
753 "where file_id = $2");
754 TSQLStatement* stmt = db_server->Statement(sql);
755
756 stmt->NextIteration();
757 if (energy == nullptr)
758 stmt->SetNull(0);
759 else
760 stmt->SetDouble(0, *energy);
761 stmt->SetInt(1, i_file_id);
762
763 // write new value to the database
764 if (!stmt->Process()) {
765 cout << "ERROR: updating information about simulation file has been failed" << endl;
766
767 delete stmt;
768 return -2;
769 }
770
771 if (d_energy)
772 delete d_energy;
773 if (energy == nullptr)
774 d_energy = nullptr;
775 else
776 d_energy = new double(*energy);
777
778 delete stmt;
779 return 0;
780}
781
782int UniSimulationFile::SetCentrality(TString centrality)
783{
784 if (!connectionDB) {
785 cout << "CRITICAL ERROR: Connection object is null" << endl;
786 return -1;
787 }
788
789 TSQLServer* db_server = connectionDB->GetSQLServer();
790
791 TString sql = TString::Format("update simulation_file "
792 "set centrality = $1 "
793 "where file_id = $2");
794 TSQLStatement* stmt = db_server->Statement(sql);
795
796 stmt->NextIteration();
797 stmt->SetString(0, centrality);
798 stmt->SetInt(1, i_file_id);
799
800 // write new value to the database
801 if (!stmt->Process()) {
802 cout << "ERROR: updating information about simulation file has been failed" << endl;
803
804 delete stmt;
805 return -2;
806 }
807
808 str_centrality = centrality;
809
810 delete stmt;
811 return 0;
812}
813
815{
816 if (!connectionDB) {
817 cout << "CRITICAL ERROR: Connection object is null" << endl;
818 return -1;
819 }
820
821 TSQLServer* db_server = connectionDB->GetSQLServer();
822
823 TString sql = TString::Format("update simulation_file "
824 "set event_count = $1 "
825 "where file_id = $2");
826 TSQLStatement* stmt = db_server->Statement(sql);
827
828 stmt->NextIteration();
829 if (event_count == nullptr)
830 stmt->SetNull(0);
831 else
832 stmt->SetInt(0, *event_count);
833 stmt->SetInt(1, i_file_id);
834
835 // write new value to the database
836 if (!stmt->Process()) {
837 cout << "ERROR: updating information about simulation file has been failed" << endl;
838
839 delete stmt;
840 return -2;
841 }
842
843 if (i_event_count)
844 delete i_event_count;
845 if (event_count == nullptr)
846 i_event_count = nullptr;
847 else
848 i_event_count = new int(*event_count);
849
850 delete stmt;
851 return 0;
852}
853
855{
856 if (!connectionDB) {
857 cout << "CRITICAL ERROR: Connection object is null" << endl;
858 return -1;
859 }
860
861 TSQLServer* db_server = connectionDB->GetSQLServer();
862
863 TString sql = TString::Format("update simulation_file "
864 "set file_size = $1 "
865 "where file_id = $2");
866 TSQLStatement* stmt = db_server->Statement(sql);
867
868 stmt->NextIteration();
869 if (file_size == nullptr)
870 stmt->SetNull(0);
871 else
872 stmt->SetLong64(0, *file_size);
873 stmt->SetInt(1, i_file_id);
874
875 // write new value to the database
876 if (!stmt->Process()) {
877 cout << "ERROR: updating information about simulation file has been failed" << endl;
878
879 delete stmt;
880 return -2;
881 }
882
883 if (i64_file_size)
884 delete i64_file_size;
885 if (file_size == nullptr)
886 i64_file_size = nullptr;
887 else
888 i64_file_size = new int64_t(*file_size);
889
890 delete stmt;
891 return 0;
892}
893
894int UniSimulationFile::SetFileHash(TString* file_hash)
895{
896 if (!connectionDB) {
897 cout << "CRITICAL ERROR: Connection object is null" << endl;
898 return -1;
899 }
900
901 TSQLServer* db_server = connectionDB->GetSQLServer();
902
903 TString sql = TString::Format("update simulation_file "
904 "set file_hash = $1 "
905 "where file_id = $2");
906 TSQLStatement* stmt = db_server->Statement(sql);
907
908 stmt->NextIteration();
909 if (file_hash == nullptr)
910 stmt->SetNull(0);
911 else
912 stmt->SetString(0, *file_hash);
913 stmt->SetInt(1, i_file_id);
914
915 // write new value to the database
916 if (!stmt->Process()) {
917 cout << "ERROR: updating information about simulation file has been failed" << endl;
918
919 delete stmt;
920 return -2;
921 }
922
923 if (str_file_hash)
924 delete str_file_hash;
925 if (file_hash == nullptr)
926 str_file_hash = nullptr;
927 else
928 str_file_hash = new TString(*file_hash);
929
930 delete stmt;
931 return 0;
932}
933
934int UniSimulationFile::SetFileDesc(TString* file_desc)
935{
936 if (!connectionDB) {
937 cout << "CRITICAL ERROR: Connection object is null" << endl;
938 return -1;
939 }
940
941 TSQLServer* db_server = connectionDB->GetSQLServer();
942
943 TString sql = TString::Format("update simulation_file "
944 "set file_desc = $1 "
945 "where file_id = $2");
946 TSQLStatement* stmt = db_server->Statement(sql);
947
948 stmt->NextIteration();
949 if (file_desc == nullptr)
950 stmt->SetNull(0);
951 else
952 stmt->SetString(0, *file_desc);
953 stmt->SetInt(1, i_file_id);
954
955 // write new value to the database
956 if (!stmt->Process()) {
957 cout << "ERROR: updating information about simulation file has been failed" << endl;
958
959 delete stmt;
960 return -2;
961 }
962
963 if (str_file_desc)
964 delete str_file_desc;
965 if (file_desc == nullptr)
966 str_file_desc = nullptr;
967 else
968 str_file_desc = new TString(*file_desc);
969
970 delete stmt;
971 return 0;
972}
973
974// ----- Print current simulation file ---------------------------------------
976{
977 cout << "Table 'simulation_file'";
978 cout << ". file_id: " << i_file_id << ". generator_name: " << str_generator_name << ". file_type: " << i_file_type
979 << ". file_path: " << str_file_path << ". beam_particle: " << str_beam_particle
980 << ". target_particle: " << str_target_particle
981 << ". energy: " << (d_energy == nullptr ? "nullptr" : TString::Format("%f", *d_energy))
982 << ". centrality: " << str_centrality
983 << ". event_count: " << (i_event_count == nullptr ? "nullptr" : TString::Format("%d", *i_event_count))
984 << ". file_size: " << (i64_file_size == nullptr ? "nullptr" : TString::Format("%ld", *i64_file_size))
985 << ". file_hash: " << (str_file_hash == nullptr ? "nullptr" : *str_file_hash)
986 << ". file_desc: " << (str_file_desc == nullptr ? "nullptr" : *str_file_desc) << endl;
987
988 return;
989}
990/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
991
993{
994 TObjArray* arrayResult = nullptr;
995
997 if (connDb == nullptr) {
998 cout << "ERROR: connection to the Unified Condition Database was failed" << endl;
999 return arrayResult;
1000 }
1001
1002 TSQLServer* db_server = connDb->GetSQLServer();
1003
1004 TString sql = TString::Format("select file_id, generator_name, file_type, file_path, beam_particle, "
1005 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc "
1006 "from simulation_file");
1007 TSQLStatement* stmt = db_server->Statement(sql);
1008 // cout<<"SQL code: "<<sql<<endl;
1009
1010 // get record from the database
1011 if (!stmt->Process()) {
1012 cout << "ERROR: getting record from the database has been failed" << endl;
1013
1014 delete stmt;
1015 delete connDb;
1016
1017 return arrayResult;
1018 }
1019
1020 // store result of statement in buffer
1021 stmt->StoreResult();
1022
1023 // extract rows one after another
1024 arrayResult = new TObjArray();
1025 arrayResult->SetOwner(kTRUE);
1026 while (stmt->NextResultRow()) {
1028 if (connRun == nullptr) {
1029 cout
1030 << "ERROR: the connection to the Unified Condition Database for the selected simulation file was failed"
1031 << endl;
1032 delete stmt;
1033 return arrayResult;
1034 }
1035
1036 int tmp_file_id;
1037 tmp_file_id = stmt->GetInt(0);
1038 TString tmp_generator_name;
1039 tmp_generator_name = stmt->GetString(1);
1040 int tmp_file_type;
1041 tmp_file_type = stmt->GetInt(2);
1042 TString tmp_file_path;
1043 tmp_file_path = stmt->GetString(3);
1044 TString tmp_beam_particle;
1045 tmp_beam_particle = stmt->GetString(4);
1046 TString tmp_target_particle;
1047 tmp_target_particle = stmt->GetString(5);
1048 double* tmp_energy;
1049 if (stmt->IsNull(6))
1050 tmp_energy = nullptr;
1051 else
1052 tmp_energy = new double(stmt->GetDouble(6));
1053 TString tmp_centrality;
1054 tmp_centrality = stmt->GetString(7);
1055 int* tmp_event_count;
1056 if (stmt->IsNull(8))
1057 tmp_event_count = nullptr;
1058 else
1059 tmp_event_count = new int(stmt->GetInt(8));
1060 int64_t* tmp_file_size;
1061 if (stmt->IsNull(9))
1062 tmp_file_size = nullptr;
1063 else
1064 tmp_file_size = new int64_t(stmt->GetLong64(9));
1065 TString* tmp_file_hash;
1066 if (stmt->IsNull(10))
1067 tmp_file_hash = nullptr;
1068 else
1069 tmp_file_hash = new TString(stmt->GetString(10));
1070 TString* tmp_file_desc;
1071 if (stmt->IsNull(11))
1072 tmp_file_desc = nullptr;
1073 else
1074 tmp_file_desc = new TString(stmt->GetString(11));
1075
1076 arrayResult->Add((TObject*)new UniSimulationFile(connDb, tmp_file_id, tmp_generator_name, tmp_file_type,
1077 tmp_file_path, tmp_beam_particle, tmp_target_particle,
1078 tmp_energy, tmp_centrality, tmp_event_count, tmp_file_size,
1079 tmp_file_hash, tmp_file_desc));
1080 }
1081
1082 delete stmt;
1083
1084 return arrayResult;
1085}
1086
1087TObjArray* UniSimulationFile::Search(TObjArray& search_conditions)
1088{
1089 TObjArray* arrayResult = nullptr;
1090 search_conditions.SetOwner(kTRUE);
1091
1093 if (connDb == nullptr) {
1094 cout << "ERROR: connection to the Unified Condition Database was failed" << endl;
1095 return arrayResult;
1096 }
1097
1098 TSQLServer* db_server = connDb->GetSQLServer();
1099
1100 TString sql = TString::Format("select file_id, generator_name, file_type, file_path, beam_particle, "
1101 "target_particle, energy, centrality, event_count, file_size, file_hash, file_desc "
1102 "from simulation_file");
1103
1104 TString strCondition;
1105 bool isFirst = true;
1106 TIter next(&search_conditions);
1107 UniSearchCondition* curCondition;
1108 while ((curCondition = (UniSearchCondition*)next()) != nullptr) {
1109 strCondition = "";
1110
1111 switch (curCondition->GetColumn()) {
1113 strCondition += "lower(file_path) ";
1114 break;
1116 strCondition += "lower(generator_name) ";
1117 break;
1119 strCondition += "lower(beam_particle) ";
1120 break;
1122 strCondition += "lower(target_particle) ";
1123 break;
1125 strCondition += "energy ";
1126 break;
1128 strCondition += "lower(centrality) ";
1129 break;
1131 strCondition += "event_count ";
1132 break;
1134 strCondition += "lower(file_desc) ";
1135 break;
1137 strCondition += "file_size ";
1138 break;
1139 default:
1140 cout << "ERROR: the column in the search condition was not defined, the condition is skipped" << endl;
1141 continue;
1142 }
1143
1144 switch (curCondition->GetCondition()) {
1146 strCondition += "< ";
1147 break;
1149 strCondition += "<= ";
1150 break;
1152 strCondition += "= ";
1153 break;
1155 strCondition += "<> ";
1156 break;
1158 strCondition += "> ";
1159 break;
1161 strCondition += ">= ";
1162 break;
1164 strCondition += "like ";
1165 break;
1167 strCondition += "is null ";
1168 break;
1170 strCondition += "is not null ";
1171 break;
1172 default:
1173 cout << "ERROR: the comparison operator in the search condition was not defined, the condition is "
1174 "skipped"
1175 << endl;
1176 continue;
1177 }
1178
1179 switch (curCondition->GetValueType()) {
1180 case 0:
1181 if ((curCondition->GetCondition() != UniSearchCondition::conditionNull)
1182 && (curCondition->GetCondition() != UniSearchCondition::conditionNotNull))
1183 continue;
1184 break;
1185 case 1:
1186 strCondition += Form("%d", curCondition->GetIntValue());
1187 break;
1188 case 2:
1189 strCondition += Form("%u", curCondition->GetUIntValue());
1190 break;
1191 case 3:
1192 strCondition += Form("%f", curCondition->GetDoubleValue());
1193 break;
1194 case 4:
1195 strCondition += Form("lower('%s')", curCondition->GetStringValue().Data());
1196 break;
1197 case 5:
1198 strCondition += Form("'%s'", curCondition->GetDatimeValue().AsSQLString());
1199 break;
1200 default:
1201 cout << "ERROR: the value type in the search condition was not found, the condition is skipped" << endl;
1202 continue;
1203 }
1204
1205 if (isFirst) {
1206 sql += " where ";
1207 isFirst = false;
1208 } else
1209 sql += " and ";
1210
1211 sql += strCondition;
1212 }
1213 sql += " order by generator_name";
1214
1215 TSQLStatement* stmt = db_server->Statement(sql);
1216 // cout<<"SQL code: "<<sql<<endl;
1217
1218 // get table record from DB
1219 if (!stmt->Process()) {
1220 cout << "ERROR: getting simulation files from the Unified Condition Database has been failed" << endl;
1221 delete stmt;
1222 delete connDb;
1223
1224 return arrayResult;
1225 }
1226
1227 // store result of statement in buffer
1228 stmt->StoreResult();
1229
1230 // extract rows one after another
1231 arrayResult = new TObjArray();
1232 arrayResult->SetOwner(kTRUE);
1233 while (stmt->NextResultRow()) {
1235 if (connRun == nullptr) {
1236 cout
1237 << "ERROR: the connection to the Unified Condition Database for the selected simulation file was failed"
1238 << endl;
1239 return arrayResult;
1240 }
1241
1242 int tmp_file_id;
1243 tmp_file_id = stmt->GetInt(0);
1244 TString tmp_generator_name;
1245 tmp_generator_name = stmt->GetString(1);
1246 int tmp_file_type;
1247 tmp_file_type = stmt->GetInt(2);
1248 TString tmp_file_path;
1249 tmp_file_path = stmt->GetString(3);
1250 TString tmp_beam_particle;
1251 tmp_beam_particle = stmt->GetString(4);
1252 TString tmp_target_particle;
1253 tmp_target_particle = stmt->GetString(5);
1254 double* tmp_energy;
1255 if (stmt->IsNull(6))
1256 tmp_energy = nullptr;
1257 else
1258 tmp_energy = new double(stmt->GetDouble(6));
1259 TString tmp_centrality;
1260 tmp_centrality = stmt->GetString(7);
1261 int* tmp_event_count;
1262 if (stmt->IsNull(8))
1263 tmp_event_count = nullptr;
1264 else
1265 tmp_event_count = new int(stmt->GetInt(8));
1266 int64_t* tmp_file_size;
1267 if (stmt->IsNull(9))
1268 tmp_file_size = nullptr;
1269 else
1270 tmp_file_size = new int64_t(stmt->GetLong64(9));
1271 TString* tmp_file_hash;
1272 if (stmt->IsNull(10))
1273 tmp_file_hash = nullptr;
1274 else
1275 tmp_file_hash = new TString(stmt->GetString(10));
1276 TString* tmp_file_desc;
1277 if (stmt->IsNull(11))
1278 tmp_file_desc = nullptr;
1279 else
1280 tmp_file_desc = new TString(stmt->GetString(11));
1281
1282 arrayResult->Add((TObject*)new UniSimulationFile(connDb, tmp_file_id, tmp_generator_name, tmp_file_type,
1283 tmp_file_path, tmp_beam_particle, tmp_target_particle,
1284 tmp_energy, tmp_centrality, tmp_event_count, tmp_file_size,
1285 tmp_file_hash, tmp_file_desc));
1286 }
1287
1288 delete stmt;
1289
1290 return arrayResult;
1291}
1292
1294{
1295 TObjArray search_conditions;
1296 search_conditions.Add((TObject*)&search_condition);
1297
1298 return Search(search_conditions);
1299}
static UniConnection * Open()
TSQLServer * GetSQLServer()
enumConditions GetCondition()
unsigned int GetUIntValue()
static int DeleteSimulationFile(int file_id)
delete simulation file from the database
int SetEnergy(double *energy)
set energy of the current simulation file
void Print()
print information about current simulation file
int SetEventCount(int *event_count)
set event count of the current simulation file
int SetFileHash(TString *file_hash)
set file hash of the current simulation file
int SetCentrality(TString centrality)
set centrality of the current simulation file
static UniSimulationFile * GetSimulationFile(int file_id)
get simulation file from the database
int SetFileType(int file_type)
set file type of the current simulation file
static int PrintAll()
print all simulation files
int SetFileDesc(TString *file_desc)
set file desc of the current simulation file
static TObjArray * GetSimulationFiles()
get array of all UniSimulationFile-s from the database
int SetBeamParticle(TString beam_particle)
set beam particle of the current simulation file
static int CheckSimulationFileExists(int file_id)
check simulation file exists in the database: 1- true, 0 - false, <0 - database operation error
int SetGeneratorName(TString generator_name)
set generator name of the current simulation file
int SetFilePath(TString file_path)
set file path of the current simulation file
int SetTargetParticle(TString target_particle)
set target particle of the current simulation file
static TObjArray * Search(UniSearchCondition &search_condition)
get simulation files corresponding to the specified single condition and set owner for search_conditi...
static UniSimulationFile * CreateSimulationFile(TString generator_name, int file_type, TString file_path, TString beam_particle, TString target_particle, double *energy, TString centrality, int *event_count, int64_t *file_size, TString *file_hash, TString *file_desc)
add new simulation file to the database
int SetFileSize(int64_t *file_size)
set file size of the current simulation file
STL namespace.