9#include "TSQLStatement.h"
19 TString* shift_leader_id,
32 TString* record_comment,
33 int* system_status_id)
35 connectionDB = db_connect;
37 i_record_id = record_id;
38 dt_record_date = record_date;
39 str_shift_leader_id = shift_leader_id;
41 i_period_number = period_number;
43 i_trigger_id = trigger_id;
44 str_daq_status = daq_status;
51 d_target_width = target_width;
52 str_record_comment = record_comment;
53 i_system_status_id = system_status_id;
61 if (str_shift_leader_id)
62 delete str_shift_leader_id;
64 delete i_period_number;
70 delete str_daq_status;
80 delete d_target_width;
81 if (str_record_comment)
82 delete str_record_comment;
83 if (i_system_status_id)
84 delete i_system_status_id;
89 TString* shift_leader_id,
101 double* target_width,
102 TString* record_comment,
103 int* system_status_id)
106 if (connDb ==
nullptr)
111 TString sql = TString::Format(
112 "insert into record_(record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, daq_status, "
113 "sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id) "
114 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)");
115 TSQLStatement* stmt = db_server->Statement(sql);
117 stmt->NextIteration();
118 stmt->SetDatime(0, record_date);
119 if (shift_leader_id ==
nullptr)
122 stmt->SetString(1, *shift_leader_id);
123 stmt->SetInt(2, type_id);
124 if (period_number ==
nullptr)
127 stmt->SetInt(3, *period_number);
128 if (run_number ==
nullptr)
131 stmt->SetInt(4, *run_number);
132 if (trigger_id ==
nullptr)
135 stmt->SetInt(5, *trigger_id);
136 if (daq_status ==
nullptr)
139 stmt->SetString(6, *daq_status);
140 if (sp_41 ==
nullptr)
143 stmt->SetInt(7, *sp_41);
144 if (sp_57 ==
nullptr)
147 stmt->SetInt(8, *sp_57);
151 stmt->SetInt(9, *vkm2);
152 stmt->SetString(10, beam);
153 if (energy ==
nullptr)
156 stmt->SetDouble(11, *energy);
157 stmt->SetString(12, target);
158 if (target_width ==
nullptr)
161 stmt->SetDouble(13, *target_width);
162 if (record_comment ==
nullptr)
165 stmt->SetString(14, *record_comment);
166 if (system_status_id ==
nullptr)
169 stmt->SetInt(15, *system_status_id);
172 if (!stmt->Process()) {
173 cout <<
"ERROR: inserting new record to the Database has been failed" << endl;
183 TSQLStatement* stmt_last = db_server->Statement(
"SELECT currval(pg_get_serial_sequence('record_','record_id'))");
186 if (stmt_last->Process()) {
188 stmt_last->StoreResult();
191 if (!stmt_last->NextResultRow()) {
192 cout <<
"ERROR: no last ID in DB!" << endl;
196 record_id = stmt_last->GetInt(0);
200 cout <<
"ERROR: getting last ID has been failed!" << endl;
206 tmp_record_id = record_id;
207 TDatime tmp_record_date;
208 tmp_record_date = record_date;
209 TString* tmp_shift_leader_id;
210 if (shift_leader_id ==
nullptr)
211 tmp_shift_leader_id =
nullptr;
213 tmp_shift_leader_id =
new TString(*shift_leader_id);
215 tmp_type_id = type_id;
216 int* tmp_period_number;
217 if (period_number ==
nullptr)
218 tmp_period_number =
nullptr;
220 tmp_period_number =
new int(*period_number);
222 if (run_number ==
nullptr)
223 tmp_run_number =
nullptr;
225 tmp_run_number =
new int(*run_number);
227 if (trigger_id ==
nullptr)
228 tmp_trigger_id =
nullptr;
230 tmp_trigger_id =
new int(*trigger_id);
231 TString* tmp_daq_status;
232 if (daq_status ==
nullptr)
233 tmp_daq_status =
nullptr;
235 tmp_daq_status =
new TString(*daq_status);
237 if (sp_41 ==
nullptr)
240 tmp_sp_41 =
new int(*sp_41);
242 if (sp_57 ==
nullptr)
245 tmp_sp_57 =
new int(*sp_57);
250 tmp_vkm2 =
new int(*vkm2);
254 if (energy ==
nullptr)
255 tmp_energy =
nullptr;
257 tmp_energy =
new double(*energy);
260 double* tmp_target_width;
261 if (target_width ==
nullptr)
262 tmp_target_width =
nullptr;
264 tmp_target_width =
new double(*target_width);
265 TString* tmp_record_comment;
266 if (record_comment ==
nullptr)
267 tmp_record_comment =
nullptr;
269 tmp_record_comment =
new TString(*record_comment);
270 int* tmp_system_status_id;
271 if (system_status_id ==
nullptr)
272 tmp_system_status_id =
nullptr;
274 tmp_system_status_id =
new int(*system_status_id);
276 return new ElogRecord(connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number,
277 tmp_run_number, tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam,
278 tmp_energy, tmp_target, tmp_target_width, tmp_record_comment, tmp_system_status_id);
285 if (connDb ==
nullptr)
290 TString sql = TString::Format(
291 "select record_id, record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, daq_status, "
292 "sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
294 "where record_id = %d",
296 TSQLStatement* stmt = db_server->Statement(sql);
299 if (!stmt->Process()) {
300 cout <<
"ERROR: getting record from the database has been failed" << endl;
311 if (!stmt->NextResultRow()) {
312 cout <<
"ERROR: record was not found in the database" << endl;
320 tmp_record_id = stmt->GetInt(0);
321 TDatime tmp_record_date;
322 tmp_record_date = stmt->GetDatime(1);
323 TString* tmp_shift_leader_id;
325 tmp_shift_leader_id =
nullptr;
327 tmp_shift_leader_id =
new TString(stmt->GetString(2));
329 tmp_type_id = stmt->GetInt(3);
330 int* tmp_period_number;
332 tmp_period_number =
nullptr;
334 tmp_period_number =
new int(stmt->GetInt(4));
337 tmp_run_number =
nullptr;
339 tmp_run_number =
new int(stmt->GetInt(5));
342 tmp_trigger_id =
nullptr;
344 tmp_trigger_id =
new int(stmt->GetInt(6));
345 TString* tmp_daq_status;
347 tmp_daq_status =
nullptr;
349 tmp_daq_status =
new TString(stmt->GetString(7));
354 tmp_sp_41 =
new int(stmt->GetInt(8));
359 tmp_sp_57 =
new int(stmt->GetInt(9));
361 if (stmt->IsNull(10))
364 tmp_vkm2 =
new int(stmt->GetInt(10));
366 tmp_beam = stmt->GetString(11);
368 if (stmt->IsNull(12))
369 tmp_energy =
nullptr;
371 tmp_energy =
new double(stmt->GetDouble(12));
373 tmp_target = stmt->GetString(13);
374 double* tmp_target_width;
375 if (stmt->IsNull(14))
376 tmp_target_width =
nullptr;
378 tmp_target_width =
new double(stmt->GetDouble(14));
379 TString* tmp_record_comment;
380 if (stmt->IsNull(15))
381 tmp_record_comment =
nullptr;
383 tmp_record_comment =
new TString(stmt->GetString(15));
384 int* tmp_system_status_id;
385 if (stmt->IsNull(16))
386 tmp_system_status_id =
nullptr;
388 tmp_system_status_id =
new int(stmt->GetInt(16));
392 return new ElogRecord(connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number,
393 tmp_run_number, tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam,
394 tmp_energy, tmp_target, tmp_target_width, tmp_record_comment, tmp_system_status_id);
401 if (connDb ==
nullptr)
406 TString sql = TString::Format(
"select 1 "
408 "where record_id = %d",
410 TSQLStatement* stmt = db_server->Statement(sql);
413 if (!stmt->Process()) {
414 cout <<
"ERROR: getting record from the database has been failed" << endl;
425 if (!stmt->NextResultRow()) {
441 if (connDb ==
nullptr)
446 TString sql = TString::Format(
"delete from record_ "
447 "where record_id = $1");
448 TSQLStatement* stmt = db_server->Statement(sql);
450 stmt->NextIteration();
451 stmt->SetInt(0, record_id);
454 if (!stmt->Process()) {
455 cout <<
"ERROR: deleting record from the dataBase has been failed" << endl;
471 if (connDb ==
nullptr)
476 TString sql = TString::Format(
477 "select record_id, record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, daq_status, "
478 "sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
480 TSQLStatement* stmt = db_server->Statement(sql);
483 if (!stmt->Process()) {
484 cout <<
"ERROR: getting all 'records' from the dataBase has been failed" << endl;
495 cout <<
"Table 'record_':" << endl;
496 while (stmt->NextResultRow()) {
497 cout <<
"record_id: ";
498 cout << (stmt->GetInt(0));
499 cout <<
", record_date: ";
500 cout << (stmt->GetDatime(1)).AsSQLString();
501 cout <<
", shift_leader_id: ";
505 cout << stmt->GetString(2);
506 cout <<
", type_id: ";
507 cout << (stmt->GetInt(3));
508 cout <<
", period_number: ";
512 cout << stmt->GetInt(4);
513 cout <<
", run_number: ";
517 cout << stmt->GetInt(5);
518 cout <<
", trigger_id: ";
522 cout << stmt->GetInt(6);
523 cout <<
", daq_status: ";
527 cout << stmt->GetString(7);
532 cout << stmt->GetInt(8);
537 cout << stmt->GetInt(9);
539 if (stmt->IsNull(10))
542 cout << stmt->GetInt(10);
544 cout << (stmt->GetString(11));
545 cout <<
", energy: ";
546 if (stmt->IsNull(12))
549 cout << stmt->GetDouble(12);
550 cout <<
", target: ";
551 cout << (stmt->GetString(13));
552 cout <<
", target_width: ";
553 if (stmt->IsNull(14))
556 cout << stmt->GetDouble(14);
557 cout <<
", record_comment: ";
558 if (stmt->IsNull(15))
561 cout << stmt->GetString(15);
562 cout <<
", system_status_id: ";
563 if (stmt->IsNull(16))
566 cout << stmt->GetInt(16);
580 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
586 TString sql = TString::Format(
"update record_ "
587 "set record_date = $1 "
588 "where record_id = $2");
589 TSQLStatement* stmt = db_server->Statement(sql);
591 stmt->NextIteration();
592 stmt->SetDatime(0, record_date);
593 stmt->SetInt(1, i_record_id);
596 if (!stmt->Process()) {
597 cout <<
"ERROR: updating information about record has been failed" << endl;
603 dt_record_date = record_date;
612 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
618 TString sql = TString::Format(
"update record_ "
619 "set shift_leader_id = $1 "
620 "where record_id = $2");
621 TSQLStatement* stmt = db_server->Statement(sql);
623 stmt->NextIteration();
624 if (shift_leader_id ==
nullptr)
627 stmt->SetString(0, *shift_leader_id);
628 stmt->SetInt(1, i_record_id);
631 if (!stmt->Process()) {
632 cout <<
"ERROR: updating information about record has been failed" << endl;
638 if (str_shift_leader_id)
639 delete str_shift_leader_id;
640 if (shift_leader_id ==
nullptr)
641 str_shift_leader_id =
nullptr;
643 str_shift_leader_id =
new TString(*shift_leader_id);
652 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
658 TString sql = TString::Format(
"update record_ "
660 "where record_id = $2");
661 TSQLStatement* stmt = db_server->Statement(sql);
663 stmt->NextIteration();
664 stmt->SetInt(0, type_id);
665 stmt->SetInt(1, i_record_id);
668 if (!stmt->Process()) {
669 cout <<
"ERROR: updating information about record has been failed" << endl;
684 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
690 TString sql = TString::Format(
"update record_ "
691 "set period_number = $1 "
692 "where record_id = $2");
693 TSQLStatement* stmt = db_server->Statement(sql);
695 stmt->NextIteration();
696 if (period_number ==
nullptr)
699 stmt->SetInt(0, *period_number);
700 stmt->SetInt(1, i_record_id);
703 if (!stmt->Process()) {
704 cout <<
"ERROR: updating information about record has been failed" << endl;
711 delete i_period_number;
712 if (period_number ==
nullptr)
713 i_period_number =
nullptr;
715 i_period_number =
new int(*period_number);
724 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
730 TString sql = TString::Format(
"update record_ "
731 "set run_number = $1 "
732 "where record_id = $2");
733 TSQLStatement* stmt = db_server->Statement(sql);
735 stmt->NextIteration();
736 if (run_number ==
nullptr)
739 stmt->SetInt(0, *run_number);
740 stmt->SetInt(1, i_record_id);
743 if (!stmt->Process()) {
744 cout <<
"ERROR: updating information about record has been failed" << endl;
752 if (run_number ==
nullptr)
753 i_run_number =
nullptr;
755 i_run_number =
new int(*run_number);
764 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
770 TString sql = TString::Format(
"update record_ "
771 "set trigger_id = $1 "
772 "where record_id = $2");
773 TSQLStatement* stmt = db_server->Statement(sql);
775 stmt->NextIteration();
776 if (trigger_id ==
nullptr)
779 stmt->SetInt(0, *trigger_id);
780 stmt->SetInt(1, i_record_id);
783 if (!stmt->Process()) {
784 cout <<
"ERROR: updating information about record has been failed" << endl;
792 if (trigger_id ==
nullptr)
793 i_trigger_id =
nullptr;
795 i_trigger_id =
new int(*trigger_id);
804 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
810 TString sql = TString::Format(
"update record_ "
811 "set daq_status = $1 "
812 "where record_id = $2");
813 TSQLStatement* stmt = db_server->Statement(sql);
815 stmt->NextIteration();
816 if (daq_status ==
nullptr)
819 stmt->SetString(0, *daq_status);
820 stmt->SetInt(1, i_record_id);
823 if (!stmt->Process()) {
824 cout <<
"ERROR: updating information about record has been failed" << endl;
831 delete str_daq_status;
832 if (daq_status ==
nullptr)
833 str_daq_status =
nullptr;
835 str_daq_status =
new TString(*daq_status);
844 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
850 TString sql = TString::Format(
"update record_ "
852 "where record_id = $2");
853 TSQLStatement* stmt = db_server->Statement(sql);
855 stmt->NextIteration();
856 if (sp_41 ==
nullptr)
859 stmt->SetInt(0, *sp_41);
860 stmt->SetInt(1, i_record_id);
863 if (!stmt->Process()) {
864 cout <<
"ERROR: updating information about record has been failed" << endl;
872 if (sp_41 ==
nullptr)
875 i_sp_41 =
new int(*sp_41);
884 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
890 TString sql = TString::Format(
"update record_ "
892 "where record_id = $2");
893 TSQLStatement* stmt = db_server->Statement(sql);
895 stmt->NextIteration();
896 if (sp_57 ==
nullptr)
899 stmt->SetInt(0, *sp_57);
900 stmt->SetInt(1, i_record_id);
903 if (!stmt->Process()) {
904 cout <<
"ERROR: updating information about record has been failed" << endl;
912 if (sp_57 ==
nullptr)
915 i_sp_57 =
new int(*sp_57);
924 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
930 TString sql = TString::Format(
"update record_ "
932 "where record_id = $2");
933 TSQLStatement* stmt = db_server->Statement(sql);
935 stmt->NextIteration();
939 stmt->SetInt(0, *vkm2);
940 stmt->SetInt(1, i_record_id);
943 if (!stmt->Process()) {
944 cout <<
"ERROR: updating information about record has been failed" << endl;
955 i_vkm2 =
new int(*vkm2);
964 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
970 TString sql = TString::Format(
"update record_ "
972 "where record_id = $2");
973 TSQLStatement* stmt = db_server->Statement(sql);
975 stmt->NextIteration();
976 stmt->SetString(0, beam);
977 stmt->SetInt(1, i_record_id);
980 if (!stmt->Process()) {
981 cout <<
"ERROR: updating information about record has been failed" << endl;
996 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1002 TString sql = TString::Format(
"update record_ "
1004 "where record_id = $2");
1005 TSQLStatement* stmt = db_server->Statement(sql);
1007 stmt->NextIteration();
1008 if (energy ==
nullptr)
1011 stmt->SetDouble(0, *energy);
1012 stmt->SetInt(1, i_record_id);
1015 if (!stmt->Process()) {
1016 cout <<
"ERROR: updating information about record has been failed" << endl;
1024 if (energy ==
nullptr)
1027 d_energy =
new double(*energy);
1035 if (!connectionDB) {
1036 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1042 TString sql = TString::Format(
"update record_ "
1044 "where record_id = $2");
1045 TSQLStatement* stmt = db_server->Statement(sql);
1047 stmt->NextIteration();
1048 stmt->SetString(0, target);
1049 stmt->SetInt(1, i_record_id);
1052 if (!stmt->Process()) {
1053 cout <<
"ERROR: updating information about record has been failed" << endl;
1059 str_target = target;
1067 if (!connectionDB) {
1068 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1074 TString sql = TString::Format(
"update record_ "
1075 "set target_width = $1 "
1076 "where record_id = $2");
1077 TSQLStatement* stmt = db_server->Statement(sql);
1079 stmt->NextIteration();
1080 if (target_width ==
nullptr)
1083 stmt->SetDouble(0, *target_width);
1084 stmt->SetInt(1, i_record_id);
1087 if (!stmt->Process()) {
1088 cout <<
"ERROR: updating information about record has been failed" << endl;
1095 delete d_target_width;
1096 if (target_width ==
nullptr)
1097 d_target_width =
nullptr;
1099 d_target_width =
new double(*target_width);
1107 if (!connectionDB) {
1108 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1114 TString sql = TString::Format(
"update record_ "
1115 "set record_comment = $1 "
1116 "where record_id = $2");
1117 TSQLStatement* stmt = db_server->Statement(sql);
1119 stmt->NextIteration();
1120 if (record_comment ==
nullptr)
1123 stmt->SetString(0, *record_comment);
1124 stmt->SetInt(1, i_record_id);
1127 if (!stmt->Process()) {
1128 cout <<
"ERROR: updating information about record has been failed" << endl;
1134 if (str_record_comment)
1135 delete str_record_comment;
1136 if (record_comment ==
nullptr)
1137 str_record_comment =
nullptr;
1139 str_record_comment =
new TString(*record_comment);
1147 if (!connectionDB) {
1148 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1154 TString sql = TString::Format(
"update record_ "
1155 "set system_status_id = $1 "
1156 "where record_id = $2");
1157 TSQLStatement* stmt = db_server->Statement(sql);
1159 stmt->NextIteration();
1160 if (system_status_id ==
nullptr)
1163 stmt->SetInt(0, *system_status_id);
1164 stmt->SetInt(1, i_record_id);
1167 if (!stmt->Process()) {
1168 cout <<
"ERROR: updating information about record has been failed" << endl;
1174 if (i_system_status_id)
1175 delete i_system_status_id;
1176 if (system_status_id ==
nullptr)
1177 i_system_status_id =
nullptr;
1179 i_system_status_id =
new int(*system_status_id);
1188 cout <<
"Table 'record_'";
1189 cout <<
". record_id: " << i_record_id <<
". record_date: " << dt_record_date.AsSQLString() <<
". shift_leader_id: "
1190 << (str_shift_leader_id ==
nullptr ?
"nullptr" : TString::Format(
"%d", *str_shift_leader_id))
1191 <<
". type_id: " << i_type_id
1192 <<
". period_number: " << (i_period_number ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_period_number))
1193 <<
". run_number: " << (i_run_number ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_run_number))
1194 <<
". trigger_id: " << (i_trigger_id ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_trigger_id))
1195 <<
". daq_status: " << (str_daq_status ==
nullptr ?
"nullptr" : *str_daq_status)
1196 <<
". sp_41: " << (i_sp_41 ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_sp_41))
1197 <<
". sp_57: " << (i_sp_57 ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_sp_57))
1198 <<
". vkm2: " << (i_vkm2 ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_vkm2)) <<
". beam: " << str_beam
1199 <<
". energy: " << (d_energy ==
nullptr ?
"nullptr" : TString::Format(
"%f", *d_energy))
1200 <<
". target: " << str_target
1201 <<
". target_width: " << (d_target_width ==
nullptr ?
"nullptr" : TString::Format(
"%f", *d_target_width))
1202 <<
". record_comment: " << (str_record_comment ==
nullptr ?
"nullptr" : *str_record_comment)
1203 <<
". system_status_id: "
1204 << (i_system_status_id ==
nullptr ?
"nullptr" : TString::Format(
"%d", *i_system_status_id)) << endl;
1213 TObjArray* arrayResult =
nullptr;
1216 if (connDb ==
nullptr) {
1217 cout <<
"ERROR: connection to the eLog Database was failed" << endl;
1224 if (!findPreviousRun)
1225 sql = TString::Format(
1226 "select record_id, record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, "
1227 "daq_status, sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
1229 "where period_number = %d and run_number = %d",
1230 period_number, run_number);
1232 sql = TString::Format(
1233 "select record_id, record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, "
1234 "daq_status, sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
1236 "where (period_number < %d) OR ((period_number = %d) AND (run_number < %d)) "
1237 "order by period_number desc, run_number desc "
1239 period_number, period_number, run_number);
1240 TSQLStatement* stmt = db_server->Statement(sql);
1244 if (!stmt->Process()) {
1245 cout <<
"ERROR: getting record from the database has been failed" << endl;
1254 stmt->StoreResult();
1257 arrayResult =
new TObjArray();
1258 arrayResult->SetOwner(kTRUE);
1259 while (stmt->NextResultRow()) {
1261 if (connRecord ==
nullptr) {
1262 cout <<
"ERROR: connection to the eLog database for a record was failed" << endl;
1267 tmp_record_id = stmt->GetInt(0);
1268 TDatime tmp_record_date;
1269 tmp_record_date = stmt->GetDatime(1);
1270 TString* tmp_shift_leader_id;
1271 if (stmt->IsNull(2))
1272 tmp_shift_leader_id =
nullptr;
1274 tmp_shift_leader_id =
new TString(stmt->GetString(2));
1276 tmp_type_id = stmt->GetInt(3);
1277 int* tmp_period_number;
1278 if (stmt->IsNull(4))
1279 tmp_period_number =
nullptr;
1281 tmp_period_number =
new int(stmt->GetInt(4));
1282 int* tmp_run_number;
1283 if (stmt->IsNull(5))
1284 tmp_run_number =
nullptr;
1286 tmp_run_number =
new int(stmt->GetInt(5));
1287 int* tmp_trigger_id;
1288 if (stmt->IsNull(6))
1289 tmp_trigger_id =
nullptr;
1291 tmp_trigger_id =
new int(stmt->GetInt(6));
1292 TString* tmp_daq_status;
1293 if (stmt->IsNull(7))
1294 tmp_daq_status =
nullptr;
1296 tmp_daq_status =
new TString(stmt->GetString(7));
1298 if (stmt->IsNull(8))
1299 tmp_sp_41 =
nullptr;
1301 tmp_sp_41 =
new int(stmt->GetInt(8));
1303 if (stmt->IsNull(9))
1304 tmp_sp_57 =
nullptr;
1306 tmp_sp_57 =
new int(stmt->GetInt(9));
1308 if (stmt->IsNull(10))
1311 tmp_vkm2 =
new int(stmt->GetInt(10));
1313 tmp_beam = stmt->GetString(11);
1315 if (stmt->IsNull(12))
1316 tmp_energy =
nullptr;
1318 tmp_energy =
new double(stmt->GetDouble(12));
1320 tmp_target = stmt->GetString(13);
1321 double* tmp_target_width;
1322 if (stmt->IsNull(14))
1323 tmp_target_width =
nullptr;
1325 tmp_target_width =
new double(stmt->GetDouble(14));
1326 TString* tmp_record_comment;
1327 if (stmt->IsNull(15))
1328 tmp_record_comment =
nullptr;
1330 tmp_record_comment =
new TString(stmt->GetString(15));
1331 int* tmp_system_status_id;
1332 if (stmt->IsNull(16))
1333 tmp_system_status_id =
nullptr;
1335 tmp_system_status_id =
new int(stmt->GetInt(16));
1338 connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number, tmp_run_number,
1339 tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam, tmp_energy, tmp_target,
1340 tmp_target_width, tmp_record_comment, tmp_system_status_id));
1350 TObjArray* arrayResult =
nullptr;
1353 if (connDb ==
nullptr) {
1354 cout <<
"ERROR: connection to the eLog Database was failed" << endl;
1360 TString sql = TString::Format(
1361 "select record_id, record_date, shift_leader_id, r.type_id, period_number, run_number, r.trigger_id, "
1362 "daq_status, sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
1363 "from record_ r left join person_ p on r.shift_leader_id = p.person_id "
1364 "left join type_ t on r.type_id = t.type_id "
1365 "left join trigger_ tr on r.trigger_id = tr.trigger_id");
1367 TString strCondition;
1368 bool isFirst =
true;
1369 TIter next(&search_conditions);
1376 strCondition +=
"record_date ";
1379 strCondition +=
"lower(person_name) ";
1382 strCondition +=
"lower(type_text) ";
1385 strCondition +=
"run_number ";
1388 strCondition +=
"period_number ";
1391 strCondition +=
"lower(trigger_info) ";
1394 strCondition +=
"lower(daq_status) ";
1397 strCondition +=
"sp_41 ";
1400 strCondition +=
"sp_57 ";
1403 strCondition +=
"vkm2 ";
1406 strCondition +=
"lower(beam) ";
1409 strCondition +=
"energy ";
1412 strCondition +=
"lower(target) ";
1415 cout <<
"ERROR: column in the search condition was not defined, condition is skipped" << endl;
1421 strCondition +=
"< ";
1424 strCondition +=
"<= ";
1427 strCondition +=
"= ";
1430 strCondition +=
"<> ";
1433 strCondition +=
"> ";
1436 strCondition +=
">= ";
1439 strCondition +=
"like ";
1442 strCondition +=
"is null ";
1445 strCondition +=
"is not null ";
1448 cout <<
"ERROR: comparison operator in the search condition was not defined, condition is skipped"
1460 strCondition += Form(
"%d", curCondition->
GetIntValue());
1463 strCondition += Form(
"%u", curCondition->
GetUIntValue());
1469 strCondition += Form(
"lower('%s')", curCondition->
GetStringValue().Data());
1472 strCondition += Form(
"'%s'", curCondition->
GetDatimeValue().AsSQLString());
1475 cout <<
"ERROR: value type in the search condition was not found, condition is skipped" << endl;
1485 sql += strCondition;
1487 sql +=
" order by record_date";
1489 TSQLStatement* stmt = db_server->Statement(sql);
1493 if (!stmt->Process()) {
1494 cout <<
"ERROR: getting eLog records from the database has been failed" << endl;
1502 stmt->StoreResult();
1505 arrayResult =
new TObjArray();
1506 arrayResult->SetOwner(kTRUE);
1507 while (stmt->NextResultRow()) {
1509 if (connRun ==
nullptr) {
1510 cout <<
"ERROR: connection to the eLog database for a record was failed" << endl;
1515 tmp_record_id = stmt->GetInt(0);
1516 TDatime tmp_record_date;
1517 tmp_record_date = stmt->GetDatime(1);
1518 TString* tmp_shift_leader_id;
1519 if (stmt->IsNull(2))
1520 tmp_shift_leader_id =
nullptr;
1522 tmp_shift_leader_id =
new TString(stmt->GetString(2));
1524 tmp_type_id = stmt->GetInt(3);
1525 int* tmp_period_number;
1526 if (stmt->IsNull(4))
1527 tmp_period_number =
nullptr;
1529 tmp_period_number =
new int(stmt->GetInt(4));
1530 int* tmp_run_number;
1531 if (stmt->IsNull(5))
1532 tmp_run_number =
nullptr;
1534 tmp_run_number =
new int(stmt->GetInt(5));
1535 int* tmp_trigger_id;
1536 if (stmt->IsNull(6))
1537 tmp_trigger_id =
nullptr;
1539 tmp_trigger_id =
new int(stmt->GetInt(6));
1540 TString* tmp_daq_status;
1541 if (stmt->IsNull(7))
1542 tmp_daq_status =
nullptr;
1544 tmp_daq_status =
new TString(stmt->GetString(7));
1546 if (stmt->IsNull(8))
1547 tmp_sp_41 =
nullptr;
1549 tmp_sp_41 =
new int(stmt->GetInt(8));
1551 if (stmt->IsNull(9))
1552 tmp_sp_57 =
nullptr;
1554 tmp_sp_57 =
new int(stmt->GetInt(9));
1556 if (stmt->IsNull(10))
1559 tmp_vkm2 =
new int(stmt->GetInt(10));
1561 tmp_beam = stmt->GetString(11);
1563 if (stmt->IsNull(12))
1564 tmp_energy =
nullptr;
1566 tmp_energy =
new double(stmt->GetDouble(12));
1568 tmp_target = stmt->GetString(13);
1569 double* tmp_target_width;
1570 if (stmt->IsNull(14))
1571 tmp_target_width =
nullptr;
1573 tmp_target_width =
new double(stmt->GetDouble(14));
1574 TString* tmp_record_comment;
1575 if (stmt->IsNull(15))
1576 tmp_record_comment =
nullptr;
1578 tmp_record_comment =
new TString(stmt->GetString(15));
1579 int* tmp_system_status_id;
1580 if (stmt->IsNull(16))
1581 tmp_system_status_id =
nullptr;
1583 tmp_system_status_id =
new int(stmt->GetInt(16));
1586 connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number, tmp_run_number,
1587 tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam, tmp_energy, tmp_target,
1588 tmp_target_width, tmp_record_comment, tmp_system_status_id));
1598 TObjArray search_conditions;
1599 search_conditions.Add((TObject*)&search_condition);
1601 return Search(search_conditions);
static ElogConnection * Open()
TSQLServer * GetSQLServer()
int SetShiftLeaderId(TString *shift_leader_id)
set shift leader id of the current record
int SetSystemStatusId(int *system_status_id)
set system status id of the current record
int SetTypeId(int type_id)
set type id of the current record
int SetVkm2(int *vkm2)
set vkm2 of the current record
static int PrintAll()
print all records
int SetRunNumber(int *run_number)
set run number of the current record
int SetTarget(TString target)
set target of the current record
int SetPeriodNumber(int *period_number)
set period number of the current record
int SetDaqStatus(TString *daq_status)
set daq status of the current record
int SetTriggerId(int *trigger_id)
set trigger id of the current record
static TObjArray * GetRecords(int period_number, int run_number, bool findPreviousRun=false)
get array of ElogRecord-s for a given or a previous run from the database
int SetTargetWidth(double *target_width)
set target width of the current record
int SetSp57(int *sp_57)
set sp 57 of the current record
int SetRecordComment(TString *record_comment)
set record comment of the current record
static int DeleteRecord(int record_id)
delete record from the database
int SetSp41(int *sp_41)
set sp 41 of the current record
int SetBeam(TString beam)
set beam of the current record
int SetEnergy(double *energy)
set energy of the current record
static ElogRecord * GetRecord(int record_id)
get record from the database
static TObjArray * Search(const ElogSearchCondition &search_condition)
get ELOG records corresponding to the specified single condition
static int CheckRecordExists(int record_id)
check record exists in the database: 1- true, 0 - false, <0 - database operation error
void Print()
print information about current record
static ElogRecord * CreateRecord(TDatime record_date, TString *shift_leader_id, int type_id, int *period_number, int *run_number, int *trigger_id, TString *daq_status, int *sp_41, int *sp_57, int *vkm2, TString beam, double *energy, TString target, double *target_width, TString *record_comment, int *system_status_id)
add new record to the database
int SetRecordDate(TDatime record_date)
set record date of the current record
@ conditionGreaterOrEqual
enumConditions GetCondition()
unsigned int GetUIntValue()