33 int* system_status_id)
101 double* target_width,
103 int* system_status_id)
106 if (connDb ==
nullptr)
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)");
119 if (shift_leader_id ==
nullptr)
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)
140 if (sp_41 ==
nullptr)
144 if (sp_57 ==
nullptr)
153 if (energy ==
nullptr)
158 if (target_width ==
nullptr)
162 if (record_comment ==
nullptr)
166 if (system_status_id ==
nullptr)
169 stmt->
SetInt(15, *system_status_id);
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'))");
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;
208 tmp_record_date = record_date;
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);
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);
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)
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",
300 cout <<
"ERROR: getting record from the database has been failed" << endl;
312 cout <<
"ERROR: record was not found in the database" << endl;
320 tmp_record_id = stmt->
GetInt(0);
325 tmp_shift_leader_id =
nullptr;
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));
347 tmp_daq_status =
nullptr;
354 tmp_sp_41 =
new int(stmt->
GetInt(8));
359 tmp_sp_57 =
new int(stmt->
GetInt(9));
364 tmp_vkm2 =
new int(stmt->
GetInt(10));
369 tmp_energy =
nullptr;
371 tmp_energy =
new double(stmt->
GetDouble(12));
374 double* tmp_target_width;
376 tmp_target_width =
nullptr;
378 tmp_target_width =
new double(stmt->
GetDouble(14));
381 tmp_record_comment =
nullptr;
384 int* tmp_system_status_id;
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)
408 "where record_id = %d",
414 cout <<
"ERROR: getting record from the database has been failed" << endl;
441 if (connDb ==
nullptr)
447 "where record_id = $1");
451 stmt->
SetInt(0, record_id);
455 cout <<
"ERROR: deleting record from the dataBase has been failed" << endl;
471 if (connDb ==
nullptr)
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 "
484 cout <<
"ERROR: getting all 'records' from the dataBase has been failed" << endl;
495 cout <<
"Table 'record_':" << endl;
497 cout <<
"record_id: ";
498 cout << (stmt->
GetInt(0));
499 cout <<
", record_date: ";
500 cout << (stmt->
GetDatime(1)).AsSQLString();
501 cout <<
", shift_leader_id: ";
506 cout <<
", type_id: ";
507 cout << (stmt->
GetInt(3));
508 cout <<
", period_number: ";
513 cout <<
", run_number: ";
518 cout <<
", trigger_id: ";
523 cout <<
", daq_status: ";
545 cout <<
", energy: ";
550 cout <<
", target: ";
552 cout <<
", target_width: ";
557 cout <<
", record_comment: ";
562 cout <<
", system_status_id: ";
580 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
587 "set record_date = $1 "
588 "where record_id = $2");
597 cout <<
"ERROR: updating information about record has been failed" << endl;
612 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
619 "set shift_leader_id = $1 "
620 "where record_id = $2");
624 if (shift_leader_id ==
nullptr)
632 cout <<
"ERROR: updating information about record has been failed" << endl;
640 if (shift_leader_id ==
nullptr)
652 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
660 "where record_id = $2");
669 cout <<
"ERROR: updating information about record has been failed" << endl;
684 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
691 "set period_number = $1 "
692 "where record_id = $2");
696 if (period_number ==
nullptr)
699 stmt->
SetInt(0, *period_number);
704 cout <<
"ERROR: updating information about record has been failed" << endl;
712 if (period_number ==
nullptr)
724 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
731 "set run_number = $1 "
732 "where record_id = $2");
736 if (run_number ==
nullptr)
739 stmt->
SetInt(0, *run_number);
744 cout <<
"ERROR: updating information about record has been failed" << endl;
752 if (run_number ==
nullptr)
764 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
771 "set trigger_id = $1 "
772 "where record_id = $2");
776 if (trigger_id ==
nullptr)
779 stmt->
SetInt(0, *trigger_id);
784 cout <<
"ERROR: updating information about record has been failed" << endl;
792 if (trigger_id ==
nullptr)
804 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
811 "set daq_status = $1 "
812 "where record_id = $2");
816 if (daq_status ==
nullptr)
824 cout <<
"ERROR: updating information about record has been failed" << endl;
832 if (daq_status ==
nullptr)
844 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
852 "where record_id = $2");
856 if (sp_41 ==
nullptr)
864 cout <<
"ERROR: updating information about record has been failed" << endl;
872 if (sp_41 ==
nullptr)
884 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
892 "where record_id = $2");
896 if (sp_57 ==
nullptr)
904 cout <<
"ERROR: updating information about record has been failed" << endl;
912 if (sp_57 ==
nullptr)
924 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
932 "where record_id = $2");
944 cout <<
"ERROR: updating information about record has been failed" << endl;
964 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
972 "where record_id = $2");
981 cout <<
"ERROR: updating information about record has been failed" << endl;
996 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1004 "where record_id = $2");
1008 if (energy ==
nullptr)
1016 cout <<
"ERROR: updating information about record has been failed" << endl;
1024 if (energy ==
nullptr)
1036 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1044 "where record_id = $2");
1053 cout <<
"ERROR: updating information about record has been failed" << endl;
1068 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1075 "set target_width = $1 "
1076 "where record_id = $2");
1080 if (target_width ==
nullptr)
1088 cout <<
"ERROR: updating information about record has been failed" << endl;
1096 if (target_width ==
nullptr)
1108 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1115 "set record_comment = $1 "
1116 "where record_id = $2");
1120 if (record_comment ==
nullptr)
1128 cout <<
"ERROR: updating information about record has been failed" << endl;
1136 if (record_comment ==
nullptr)
1148 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
1155 "set system_status_id = $1 "
1156 "where record_id = $2");
1160 if (system_status_id ==
nullptr)
1163 stmt->
SetInt(0, *system_status_id);
1168 cout <<
"ERROR: updating information about record has been failed" << endl;
1176 if (system_status_id ==
nullptr)
1188 cout <<
"Table 'record_'";
1203 <<
". system_status_id: "
1220 if (connDb ==
nullptr) {
1221 cout <<
"ERROR: connection to the eLog Database was failed" << endl;
1228 const char* columns =
1229 "record_id, record_date, shift_leader_id, type_id, period_number, run_number, trigger_id, "
1230 "daq_status, sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id";
1233 if (findNeighbourRun == 0)
1237 "where period_number = %d and run_number = %d",
1238 columns, period_number, run_number);
1245 const char* aggregate = (findNeighbourRun < 0) ?
"max" :
"min";
1246 const char* comparison = (findNeighbourRun < 0) ?
"<" :
">";
1248 (findNeighbourRun == -2 || findNeighbourRun == 2) ?
TString(
" and type_id in (1, 2, 3)") :
TString(
"");
1251 "where period_number = %d%s and run_number = ("
1252 "select %s(run_number) from record_ "
1253 "where period_number = %d%s and run_number %s %d)",
1254 columns, period_number, type_filter.
Data(), aggregate, period_number, type_filter.
Data(),
1255 comparison, run_number);
1262 cout <<
"ERROR: getting record from the database has been failed" << endl;
1278 if (connRecord ==
nullptr) {
1279 cout <<
"ERROR: connection to the eLog database for a record was failed" << endl;
1284 tmp_record_id = stmt->
GetInt(0);
1289 tmp_shift_leader_id =
nullptr;
1293 tmp_type_id = stmt->
GetInt(3);
1294 int* tmp_period_number;
1296 tmp_period_number =
nullptr;
1298 tmp_period_number =
new int(stmt->
GetInt(4));
1299 int* tmp_run_number;
1301 tmp_run_number =
nullptr;
1303 tmp_run_number =
new int(stmt->
GetInt(5));
1304 int* tmp_trigger_id;
1306 tmp_trigger_id =
nullptr;
1308 tmp_trigger_id =
new int(stmt->
GetInt(6));
1311 tmp_daq_status =
nullptr;
1316 tmp_sp_41 =
nullptr;
1318 tmp_sp_41 =
new int(stmt->
GetInt(8));
1321 tmp_sp_57 =
nullptr;
1323 tmp_sp_57 =
new int(stmt->
GetInt(9));
1328 tmp_vkm2 =
new int(stmt->
GetInt(10));
1333 tmp_energy =
nullptr;
1335 tmp_energy =
new double(stmt->
GetDouble(12));
1338 double* tmp_target_width;
1340 tmp_target_width =
nullptr;
1342 tmp_target_width =
new double(stmt->
GetDouble(14));
1345 tmp_record_comment =
nullptr;
1348 int* tmp_system_status_id;
1350 tmp_system_status_id =
nullptr;
1352 tmp_system_status_id =
new int(stmt->
GetInt(16));
1355 connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number, tmp_run_number,
1356 tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam, tmp_energy, tmp_target,
1357 tmp_target_width, tmp_record_comment, tmp_system_status_id));
1370 if (connDb ==
nullptr) {
1371 cout <<
"ERROR: connection to the eLog Database was failed" << endl;
1378 "select record_id, record_date, shift_leader_id, r.type_id, period_number, run_number, r.trigger_id, "
1379 "daq_status, sp_41, sp_57, vkm2, beam, energy, target, target_width, record_comment, system_status_id "
1380 "from record_ r left join person_ p on r.shift_leader_id = p.person_id "
1381 "left join type_ t on r.type_id = t.type_id "
1382 "left join trigger_ tr on r.trigger_id = tr.trigger_id");
1385 bool isFirst =
true;
1386 TIter next(&search_conditions);
1393 strCondition +=
"record_date ";
1396 strCondition +=
"lower(person_name) ";
1399 strCondition +=
"lower(type_text) ";
1402 strCondition +=
"run_number ";
1405 strCondition +=
"period_number ";
1408 strCondition +=
"lower(trigger_info) ";
1411 strCondition +=
"lower(daq_status) ";
1414 strCondition +=
"sp_41 ";
1417 strCondition +=
"sp_57 ";
1420 strCondition +=
"vkm2 ";
1423 strCondition +=
"lower(beam) ";
1426 strCondition +=
"energy ";
1429 strCondition +=
"lower(target) ";
1432 cout <<
"ERROR: column in the search condition was not defined, condition is skipped" << endl;
1438 strCondition +=
"< ";
1441 strCondition +=
"<= ";
1444 strCondition +=
"= ";
1447 strCondition +=
"<> ";
1450 strCondition +=
"> ";
1453 strCondition +=
">= ";
1456 strCondition +=
"like ";
1459 strCondition +=
"is null ";
1462 strCondition +=
"is not null ";
1465 cout <<
"ERROR: comparison operator in the search condition was not defined, condition is skipped"
1492 cout <<
"ERROR: value type in the search condition was not found, condition is skipped" << endl;
1502 sql += strCondition;
1504 sql +=
" order by record_date";
1511 cout <<
"ERROR: getting eLog records from the database has been failed" << endl;
1526 if (connRun ==
nullptr) {
1527 cout <<
"ERROR: connection to the eLog database for a record was failed" << endl;
1532 tmp_record_id = stmt->
GetInt(0);
1537 tmp_shift_leader_id =
nullptr;
1541 tmp_type_id = stmt->
GetInt(3);
1542 int* tmp_period_number;
1544 tmp_period_number =
nullptr;
1546 tmp_period_number =
new int(stmt->
GetInt(4));
1547 int* tmp_run_number;
1549 tmp_run_number =
nullptr;
1551 tmp_run_number =
new int(stmt->
GetInt(5));
1552 int* tmp_trigger_id;
1554 tmp_trigger_id =
nullptr;
1556 tmp_trigger_id =
new int(stmt->
GetInt(6));
1559 tmp_daq_status =
nullptr;
1564 tmp_sp_41 =
nullptr;
1566 tmp_sp_41 =
new int(stmt->
GetInt(8));
1569 tmp_sp_57 =
nullptr;
1571 tmp_sp_57 =
new int(stmt->
GetInt(9));
1576 tmp_vkm2 =
new int(stmt->
GetInt(10));
1581 tmp_energy =
nullptr;
1583 tmp_energy =
new double(stmt->
GetDouble(12));
1586 double* tmp_target_width;
1588 tmp_target_width =
nullptr;
1590 tmp_target_width =
new double(stmt->
GetDouble(14));
1593 tmp_record_comment =
nullptr;
1596 int* tmp_system_status_id;
1598 tmp_system_status_id =
nullptr;
1600 tmp_system_status_id =
new int(stmt->
GetInt(16));
1603 connDb, tmp_record_id, tmp_record_date, tmp_shift_leader_id, tmp_type_id, tmp_period_number, tmp_run_number,
1604 tmp_trigger_id, tmp_daq_status, tmp_sp_41, tmp_sp_57, tmp_vkm2, tmp_beam, tmp_energy, tmp_target,
1605 tmp_target_width, tmp_record_comment, tmp_system_status_id));
1616 search_conditions.
Add((
TObject*)&search_condition);
1618 return Search(search_conditions);
char * Form(const char *fmt,...)
static ElogConnection * Open()
TSQLServer * GetSQLServer()
TString * str_shift_leader_id
shift leader id
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 * i_system_status_id
system status id
int SetVkm2(int *vkm2)
set vkm2 of the current record
ElogConnection * connectionDB
connection to the database
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
TString * str_daq_status
daq status
int SetPeriodNumber(int *period_number)
set period number of the current record
int * i_trigger_id
trigger id
int SetDaqStatus(TString *daq_status)
set daq status of the current record
double * d_target_width
target width
int SetTriggerId(int *trigger_id)
set trigger id of the current record
int * i_period_number
period number
ElogRecord(ElogConnection *db_connect, int record_id, 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)
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
TString * str_record_comment
record comment
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
int * i_run_number
run number
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
static TObjArray * GetRecords(int period_number, int run_number, int findNeighbourRun=0)
get array of ElogRecord-s for a given or a neighbour run (the same period) from the database if findN...
TDatime dt_record_date
record date
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()
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
void Add(TObject *obj) override
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t NextIteration()=0
virtual Bool_t NextResultRow()=0
virtual Bool_t SetString(Int_t, const char *, Int_t=256)
Bool_t SetDatime(Int_t, const TDatime &)
virtual Int_t GetInt(Int_t)
virtual Bool_t IsNull(Int_t)
virtual Bool_t SetDouble(Int_t, Double_t)
virtual Bool_t Process()=0
virtual Bool_t SetInt(Int_t, Int_t)
virtual Bool_t SetNull(Int_t)
virtual Double_t GetDouble(Int_t)
virtual Bool_t StoreResult()=0
const char * Data() const
static TString Format(const char *fmt,...)