BmnRoot 26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
UniDetectorParameter.cxx
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2// UniDetectorParameter cxx file
3// ----------------------------------------------------------------------
4
5#include "TObjString.h"
6#include "TSQLServer.h"
7#include "TSQLStatement.h"
8
9// #define ONLY_DECLARATIONS
10// #include "function_set.h"
11#include "TSystem.h"
12#include "TBufferFile.h"
13#include "TBufferJSON.h"
15#include "UniRunPeriod.h"
16#include "uni_db_structures.h"
17
18#include <fstream>
19
20/* GENERATED CLASS MEMBERS (SHOULD NOT BE CHANGED MANUALLY) */
21// ----- Constructor with database connection -----------------------
23 int value_id,
24 TString detector_name,
25 int parameter_id,
26 int start_period,
27 int start_run,
28 int end_period,
29 int end_run,
30 int value_key,
31 unsigned char* parameter_value,
32 Long_t size_parameter_value,
33 TDatime* expiry_date)
34{
35 connectionDB = db_connect;
36
37 i_value_id = value_id;
38 str_detector_name = detector_name;
39 i_parameter_id = parameter_id;
40 i_start_period = start_period;
41 i_start_run = start_run;
42 i_end_period = end_period;
43 i_end_run = end_run;
44 i_value_key = value_key;
45 blob_parameter_value = parameter_value;
46 sz_parameter_value = size_parameter_value;
47 ts_expiry_date = expiry_date;
48}
49
50// ----- Destructor -------------------------------------------------
60
61// ----- Creating new detector parameter in the database ---------------------------
63 int parameter_id,
64 int start_period,
65 int start_run,
66 int end_period,
67 int end_run,
68 int value_key,
69 unsigned char* parameter_value,
70 Long_t size_parameter_value,
71 TDatime* expiry_date)
72{
74 if (connDb == nullptr)
75 return nullptr;
76
77 TSQLServer* db_server = connDb->GetSQLServer();
78
79 TString sql = TString::Format("insert into detector_parameter(detector_name, parameter_id, start_period, "
80 "start_run, end_period, end_run, value_key, parameter_value, expiry_date) "
81 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9)");
82 TSQLStatement* stmt = db_server->Statement(sql);
83
84 stmt->NextIteration();
85 stmt->SetString(0, detector_name);
86 stmt->SetInt(1, parameter_id);
87 stmt->SetInt(2, start_period);
88 stmt->SetInt(3, start_run);
89 stmt->SetInt(4, end_period);
90 stmt->SetInt(5, end_run);
91 stmt->SetInt(6, value_key);
92 stmt->SetBinary(7, parameter_value, size_parameter_value, 0x4000000);
93 if (expiry_date == nullptr)
94 stmt->SetNull(8);
95 else
96 stmt->SetDatime(8, *expiry_date);
97
98 // inserting new detector parameter to the Database
99 if (!stmt->Process()) {
100 cout << "ERROR: inserting new detector parameter to the Database has been failed" << endl;
101 delete stmt;
102 delete connDb;
103 return nullptr;
104 }
105
106 delete stmt;
107
108 // getting last inserted ID
109 int value_id;
110 TSQLStatement* stmt_last =
111 db_server->Statement("SELECT currval(pg_get_serial_sequence('detector_parameter','value_id'))");
112
113 // process getting last id
114 if (stmt_last->Process()) {
115 // store result of statement in buffer
116 stmt_last->StoreResult();
117
118 // if there is no last id then exit with error
119 if (!stmt_last->NextResultRow()) {
120 cout << "ERROR: no last ID in DB!" << endl;
121 delete stmt_last;
122 return nullptr;
123 } else {
124 value_id = stmt_last->GetInt(0);
125 delete stmt_last;
126 }
127 } else {
128 cout << "ERROR: getting last ID has been failed!" << endl;
129 delete stmt_last;
130 return nullptr;
131 }
132
133 int tmp_value_id;
134 tmp_value_id = value_id;
135 TString tmp_detector_name;
136 tmp_detector_name = detector_name;
137 int tmp_parameter_id;
138 tmp_parameter_id = parameter_id;
139 int tmp_start_period;
140 tmp_start_period = start_period;
141 int tmp_start_run;
142 tmp_start_run = start_run;
143 int tmp_end_period;
144 tmp_end_period = end_period;
145 int tmp_end_run;
146 tmp_end_run = end_run;
147 int tmp_value_key;
148 tmp_value_key = value_key;
149 unsigned char* tmp_parameter_value;
150 Long_t tmp_sz_parameter_value = size_parameter_value;
151 tmp_parameter_value = new unsigned char[tmp_sz_parameter_value];
152 memcpy(tmp_parameter_value, parameter_value, tmp_sz_parameter_value);
153 TDatime* tmp_expiry_date;
154 if (expiry_date == nullptr)
155 tmp_expiry_date = nullptr;
156 else
157 tmp_expiry_date = new TDatime(*expiry_date);
158
159 return new UniDetectorParameter(connDb, tmp_value_id, tmp_detector_name, tmp_parameter_id, tmp_start_period,
160 tmp_start_run, tmp_end_period, tmp_end_run, tmp_value_key, tmp_parameter_value,
161 tmp_sz_parameter_value, tmp_expiry_date);
162}
163
164// ----- Get detector parameter from the database ---------------------------
166{
168 if (connDb == nullptr)
169 return nullptr;
170
171 TSQLServer* db_server = connDb->GetSQLServer();
172
173 TString sql = TString::Format("select value_id, detector_name, parameter_id, start_period, start_run, end_period, "
174 "end_run, value_key, parameter_value, expiry_date "
175 "from detector_parameter "
176 "where value_id = %d",
177 value_id);
178 TSQLStatement* stmt = db_server->Statement(sql);
179
180 // get detector parameter from the database
181 if (!stmt->Process()) {
182 cout << "ERROR: getting detector parameter from the database has been failed" << endl;
183
184 delete stmt;
185 delete connDb;
186 return nullptr;
187 }
188
189 // store result of statement in buffer
190 stmt->StoreResult();
191
192 // extract row
193 if (!stmt->NextResultRow()) {
194 cout << "ERROR: detector parameter was not found in the database" << endl;
195
196 delete stmt;
197 delete connDb;
198 return nullptr;
199 }
200
201 int tmp_value_id;
202 tmp_value_id = stmt->GetInt(0);
203 TString tmp_detector_name;
204 tmp_detector_name = stmt->GetString(1);
205 int tmp_parameter_id;
206 tmp_parameter_id = stmt->GetInt(2);
207 int tmp_start_period;
208 tmp_start_period = stmt->GetInt(3);
209 int tmp_start_run;
210 tmp_start_run = stmt->GetInt(4);
211 int tmp_end_period;
212 tmp_end_period = stmt->GetInt(5);
213 int tmp_end_run;
214 tmp_end_run = stmt->GetInt(6);
215 int tmp_value_key;
216 tmp_value_key = stmt->GetInt(7);
217 unsigned char* tmp_parameter_value;
218 tmp_parameter_value = nullptr;
219 Long_t tmp_sz_parameter_value = 0;
220 stmt->GetBinary(8, (void*&)tmp_parameter_value, tmp_sz_parameter_value);
221 TDatime* tmp_expiry_date;
222 if (stmt->IsNull(9))
223 tmp_expiry_date = nullptr;
224 else
225 tmp_expiry_date = new TDatime(stmt->GetDatime(9));
226
227 delete stmt;
228
229 return new UniDetectorParameter(connDb, tmp_value_id, tmp_detector_name, tmp_parameter_id, tmp_start_period,
230 tmp_start_run, tmp_end_period, tmp_end_run, tmp_value_key, tmp_parameter_value,
231 tmp_sz_parameter_value, tmp_expiry_date);
232}
233
234// ----- Check detector parameter exists in the database ---------------------------
236{
238 if (connDb == nullptr)
239 return -1;
240
241 TSQLServer* db_server = connDb->GetSQLServer();
242
243 TString sql = TString::Format("select 1 "
244 "from detector_parameter "
245 "where value_id = %d",
246 value_id);
247 TSQLStatement* stmt = db_server->Statement(sql);
248
249 // get detector parameter from the database
250 if (!stmt->Process()) {
251 cout << "ERROR: getting detector parameter from the database has been failed" << endl;
252
253 delete stmt;
254 delete connDb;
255 return -2;
256 }
257
258 // store result of statement in buffer
259 stmt->StoreResult();
260
261 // extract row
262 if (!stmt->NextResultRow()) {
263 delete stmt;
264 delete connDb;
265 return 0;
266 }
267
268 delete stmt;
269 delete connDb;
270
271 return 1;
272}
273
274// ----- Delete detector parameter from the database ---------------------------
276{
278 if (connDb == nullptr)
279 return -1;
280
281 TSQLServer* db_server = connDb->GetSQLServer();
282
283 TString sql = TString::Format("delete from detector_parameter "
284 "where value_id = $1");
285 TSQLStatement* stmt = db_server->Statement(sql);
286
287 stmt->NextIteration();
288 stmt->SetInt(0, value_id);
289
290 // delete detector parameter from the dataBase
291 if (!stmt->Process()) {
292 cout << "ERROR: deleting detector parameter from the dataBase has been failed" << endl;
293
294 delete stmt;
295 delete connDb;
296 return -2;
297 }
298
299 delete stmt;
300 delete connDb;
301 return 0;
302}
303
304// ----- Print all 'detector parameters' ---------------------------------
306{
308 if (connDb == nullptr)
309 return -1;
310
311 TSQLServer* db_server = connDb->GetSQLServer();
312
313 TString sql = TString::Format("select value_id, detector_name, parameter_id, start_period, start_run, end_period, "
314 "end_run, value_key, parameter_value, expiry_date "
315 "from detector_parameter");
316 TSQLStatement* stmt = db_server->Statement(sql);
317
318 // get all 'detector parameters' from the database
319 if (!stmt->Process()) {
320 cout << "ERROR: getting all 'detector parameters' from the database has been failed" << endl;
321
322 delete stmt;
323 delete connDb;
324 return -2;
325 }
326
327 // store result of statement in buffer
328 stmt->StoreResult();
329
330 // print rows
331 cout << "Table 'detector_parameter':" << endl;
332 while (stmt->NextResultRow()) {
333 cout << "value_id: ";
334 cout << (stmt->GetInt(0));
335 cout << ", detector_name: ";
336 cout << (stmt->GetString(1));
337 cout << ", parameter_id: ";
338 cout << (stmt->GetInt(2));
339 cout << ", start_period: ";
340 cout << (stmt->GetInt(3));
341 cout << ", start_run: ";
342 cout << (stmt->GetInt(4));
343 cout << ", end_period: ";
344 cout << (stmt->GetInt(5));
345 cout << ", end_run: ";
346 cout << (stmt->GetInt(6));
347 cout << ", value_key: ";
348 cout << (stmt->GetInt(7));
349 cout << ", parameter_value: ";
350 unsigned char* tmp_parameter_value = nullptr;
351 Long_t tmp_sz_parameter_value = 0;
352 stmt->GetBinary(8, (void*&)tmp_parameter_value, tmp_sz_parameter_value);
353 cout << (void*)tmp_parameter_value << ", binary size: " << tmp_sz_parameter_value;
354 cout << ", expiry_date: ";
355 if (stmt->IsNull(9))
356 cout << "nullptr";
357 else
358 cout << stmt->GetDatime(9).AsSQLString();
359 cout << "." << endl;
360 }
361
362 delete stmt;
363 delete connDb;
364
365 return 0;
366}
367
368// Setters functions
370{
371 if (!connectionDB) {
372 cout << "CRITICAL ERROR: Connection object is null" << endl;
373 return -1;
374 }
375
376 TSQLServer* db_server = connectionDB->GetSQLServer();
377
378 TString sql = TString::Format("update detector_parameter "
379 "set detector_name = $1 "
380 "where value_id = $2");
381 TSQLStatement* stmt = db_server->Statement(sql);
382
383 stmt->NextIteration();
384 stmt->SetString(0, detector_name);
385 stmt->SetInt(1, i_value_id);
386
387 // write new value to the database
388 if (!stmt->Process()) {
389 cout << "ERROR: updating information about detector parameter has been failed" << endl;
390
391 delete stmt;
392 return -2;
393 }
394
395 str_detector_name = detector_name;
396
397 delete stmt;
398 return 0;
399}
400
402{
403 if (!connectionDB) {
404 cout << "CRITICAL ERROR: Connection object is null" << endl;
405 return -1;
406 }
407
408 TSQLServer* db_server = connectionDB->GetSQLServer();
409
410 TString sql = TString::Format("update detector_parameter "
411 "set parameter_id = $1 "
412 "where value_id = $2");
413 TSQLStatement* stmt = db_server->Statement(sql);
414
415 stmt->NextIteration();
416 stmt->SetInt(0, parameter_id);
417 stmt->SetInt(1, i_value_id);
418
419 // write new value to the database
420 if (!stmt->Process()) {
421 cout << "ERROR: updating information about detector parameter has been failed" << endl;
422
423 delete stmt;
424 return -2;
425 }
426
427 i_parameter_id = parameter_id;
428
429 delete stmt;
430 return 0;
431}
432
434{
435 if (!connectionDB) {
436 cout << "CRITICAL ERROR: Connection object is null" << endl;
437 return -1;
438 }
439
440 TSQLServer* db_server = connectionDB->GetSQLServer();
441
442 TString sql = TString::Format("update detector_parameter "
443 "set start_period = $1 "
444 "where value_id = $2");
445 TSQLStatement* stmt = db_server->Statement(sql);
446
447 stmt->NextIteration();
448 stmt->SetInt(0, start_period);
449 stmt->SetInt(1, i_value_id);
450
451 // write new value to the database
452 if (!stmt->Process()) {
453 cout << "ERROR: updating information about detector parameter has been failed" << endl;
454
455 delete stmt;
456 return -2;
457 }
458
459 i_start_period = start_period;
460
461 delete stmt;
462 return 0;
463}
464
466{
467 if (!connectionDB) {
468 cout << "CRITICAL ERROR: Connection object is null" << endl;
469 return -1;
470 }
471
472 TSQLServer* db_server = connectionDB->GetSQLServer();
473
474 TString sql = TString::Format("update detector_parameter "
475 "set start_run = $1 "
476 "where value_id = $2");
477 TSQLStatement* stmt = db_server->Statement(sql);
478
479 stmt->NextIteration();
480 stmt->SetInt(0, start_run);
481 stmt->SetInt(1, i_value_id);
482
483 // write new value to the database
484 if (!stmt->Process()) {
485 cout << "ERROR: updating information about detector parameter has been failed" << endl;
486
487 delete stmt;
488 return -2;
489 }
490
491 i_start_run = start_run;
492
493 delete stmt;
494 return 0;
495}
496
498{
499 if (!connectionDB) {
500 cout << "CRITICAL ERROR: Connection object is null" << endl;
501 return -1;
502 }
503
504 TSQLServer* db_server = connectionDB->GetSQLServer();
505
506 TString sql = TString::Format("update detector_parameter "
507 "set end_period = $1 "
508 "where value_id = $2");
509 TSQLStatement* stmt = db_server->Statement(sql);
510
511 stmt->NextIteration();
512 stmt->SetInt(0, end_period);
513 stmt->SetInt(1, i_value_id);
514
515 // write new value to the database
516 if (!stmt->Process()) {
517 cout << "ERROR: updating information about detector parameter has been failed" << endl;
518
519 delete stmt;
520 return -2;
521 }
522
523 i_end_period = end_period;
524
525 delete stmt;
526 return 0;
527}
528
530{
531 if (!connectionDB) {
532 cout << "CRITICAL ERROR: Connection object is null" << endl;
533 return -1;
534 }
535
536 TSQLServer* db_server = connectionDB->GetSQLServer();
537
538 TString sql = TString::Format("update detector_parameter "
539 "set end_run = $1 "
540 "where value_id = $2");
541 TSQLStatement* stmt = db_server->Statement(sql);
542
543 stmt->NextIteration();
544 stmt->SetInt(0, end_run);
545 stmt->SetInt(1, i_value_id);
546
547 // write new value to the database
548 if (!stmt->Process()) {
549 cout << "ERROR: updating information about detector parameter has been failed" << endl;
550
551 delete stmt;
552 return -2;
553 }
554
555 i_end_run = end_run;
556
557 delete stmt;
558 return 0;
559}
560
562{
563 if (!connectionDB) {
564 cout << "CRITICAL ERROR: Connection object is null" << endl;
565 return -1;
566 }
567
568 TSQLServer* db_server = connectionDB->GetSQLServer();
569
570 TString sql = TString::Format("update detector_parameter "
571 "set value_key = $1 "
572 "where value_id = $2");
573 TSQLStatement* stmt = db_server->Statement(sql);
574
575 stmt->NextIteration();
576 stmt->SetInt(0, value_key);
577 stmt->SetInt(1, i_value_id);
578
579 // write new value to the database
580 if (!stmt->Process()) {
581 cout << "ERROR: updating information about detector parameter has been failed" << endl;
582
583 delete stmt;
584 return -2;
585 }
586
587 i_value_key = value_key;
588
589 delete stmt;
590 return 0;
591}
592
593int UniDetectorParameter::SetParameterValue(unsigned char* parameter_value, Long_t size_parameter_value)
594{
595 if (!connectionDB) {
596 cout << "CRITICAL ERROR: Connection object is null" << endl;
597 return -1;
598 }
599
600 TSQLServer* db_server = connectionDB->GetSQLServer();
601
602 TString sql = TString::Format("update detector_parameter "
603 "set parameter_value = $1 "
604 "where value_id = $2");
605 TSQLStatement* stmt = db_server->Statement(sql);
606
607 stmt->NextIteration();
608 stmt->SetBinary(0, parameter_value, size_parameter_value, 0x4000000);
609 stmt->SetInt(1, i_value_id);
610
611 // write new value to the database
612 if (!stmt->Process()) {
613 cout << "ERROR: updating information about detector parameter has been failed" << endl;
614
615 delete stmt;
616 return -2;
617 }
618
620 delete[] blob_parameter_value;
621 sz_parameter_value = size_parameter_value;
622 blob_parameter_value = new unsigned char[sz_parameter_value];
623 memcpy(blob_parameter_value, parameter_value, sz_parameter_value);
624
625 delete stmt;
626 return 0;
627}
628
630{
631 if (!connectionDB) {
632 cout << "CRITICAL ERROR: Connection object is null" << endl;
633 return -1;
634 }
635
636 TSQLServer* db_server = connectionDB->GetSQLServer();
637
638 TString sql = TString::Format("update detector_parameter "
639 "set expiry_date = $1 "
640 "where value_id = $2");
641 TSQLStatement* stmt = db_server->Statement(sql);
642
643 stmt->NextIteration();
644 if (expiry_date == nullptr)
645 stmt->SetNull(0);
646 else
647 stmt->SetDatime(0, *expiry_date);
648 stmt->SetInt(1, i_value_id);
649
650 // write new value to the database
651 if (!stmt->Process()) {
652 cout << "ERROR: updating information about detector parameter has been failed" << endl;
653
654 delete stmt;
655 return -2;
656 }
657
658 if (ts_expiry_date)
659 delete ts_expiry_date;
660 if (expiry_date == nullptr)
661 ts_expiry_date = nullptr;
662 else
663 ts_expiry_date = new TDatime(*expiry_date);
664
665 delete stmt;
666 return 0;
667}
668
669// ----- Print current detector parameter ---------------------------------------
671{
672 cout << "Table 'detector_parameter'";
673 cout << ". value_id: " << i_value_id << ". detector_name: " << str_detector_name
674 << ". parameter_id: " << i_parameter_id << ". start_period: " << i_start_period
675 << ". start_run: " << i_start_run << ". end_period: " << i_end_period << ". end_run: " << i_end_run
676 << ". value_key: " << i_value_key << ". parameter_value: " << (void*)blob_parameter_value
677 << ", binary size: " << sz_parameter_value
678 << ". expiry_date: " << (ts_expiry_date == nullptr ? "nullptr" : (*ts_expiry_date).AsSQLString()) << endl;
679
680 return;
681}
682/* END OF GENERATED CLASS PART (SHOULD NOT BE CHANGED MANUALLY) */
683
684// non-user function for getting parameter value as a binary (char) array
685unsigned char* UniDetectorParameter::GetUNC(enumValueType enum_parameter_type)
686{
687 if (enum_parameter_type > -1) {
688 if (!connectionDB) {
689 cout << "CRITICAL ERROR: Connection object is null" << endl;
690 return nullptr;
691 }
692
693 TSQLServer* db_server = connectionDB->GetSQLServer();
694
695 // get parameter object from 'parameter_' table
696 TString sql = TString::Format("select parameter_name, parameter_type "
697 "from parameter_ "
698 "where parameter_id = %d",
700 TSQLStatement* stmt = db_server->Statement(sql);
701
702 // get table record from DB
703 if (!stmt->Process()) {
704 cout << "CRITICAL ERROR: getting record with parameter from 'parameter_' table has been failed" << endl;
705 delete stmt;
706 return nullptr;
707 }
708
709 stmt->StoreResult();
710
711 // extract row with parameter
712 if (!stmt->NextResultRow()) {
713 cout << "CRITICAL ERROR: the parameter with id '" << i_parameter_id << "' was not found" << endl;
714 delete stmt;
715 return nullptr;
716 }
717
718 TString parameter_name = stmt->GetString(0);
719 int parameter_type = stmt->GetInt(1);
720 delete stmt;
721
722 if (parameter_type != enum_parameter_type) {
723 cout << "CRITICAL ERROR: the parameter with name '" << parameter_name
724 << "' is not corresponding the given type: "
725 "Database Type - "
726 << parameter_type << ", but user type - " << enum_parameter_type << endl;
727 return nullptr;
728 }
729 }
730
732}
733
734// non-user function for setting parameter value as a binary (char) array
735int UniDetectorParameter::SetUNC(unsigned char* p_parameter_value, Long_t size_parameter_value)
736{
737 if (!connectionDB) {
738 cout << "Connection object is null" << endl;
739 return -1;
740 }
741
742 TSQLServer* db_server = connectionDB->GetSQLServer();
743
744 TString sql = TString::Format("update detector_parameter "
745 "set parameter_value = $1 "
746 "where detector_name = $2 and parameter_id = $3 and start_period = $4 and start_run "
747 "= $5 and end_period = $6 and end_run = $7 and value_key = $8");
748
749 TSQLStatement* stmt = db_server->Statement(sql);
750
751 stmt->NextIteration();
752 stmt->SetBinary(0, (void*)p_parameter_value, size_parameter_value);
754 stmt->SetInt(2, i_parameter_id);
755 stmt->SetInt(3, i_start_period);
756 stmt->SetInt(4, i_start_run);
757 stmt->SetInt(5, i_end_period);
758 stmt->SetInt(6, i_end_run);
759 stmt->SetInt(7, i_value_key);
760
761 // write new value to database
762 if (!stmt->Process()) {
763 cout << "ERROR: updating the detector parameter has been failed" << endl;
764 delete stmt;
765 return -2;
766 }
767
769 delete[] blob_parameter_value;
770 blob_parameter_value = p_parameter_value;
771 sz_parameter_value = size_parameter_value;
772
773 delete stmt;
774 return 0;
775}
776
777// non-user function for writing new parameter value (integer value key is optional, default, 0)
779 TString parameter_name,
780 int start_period,
781 int start_run,
782 int end_period,
783 int end_run,
784 unsigned char* p_parameter_value,
785 Long_t size_parameter_value,
786 enumValueType enum_parameter_type,
787 int value_key)
788{
789 if (((end_period < start_period) or ((end_period == start_period) and (end_run < start_run)))
790 or ((start_period > end_period) or ((start_period == end_period) and (start_run > end_run))))
791 {
792 cout << "ERROR: end run should be after or the same as start run" << endl;
793 return nullptr;
794 }
795
797 if (connDb == nullptr)
798 return nullptr;
799
800 TSQLServer* db_server = connDb->GetSQLServer();
801
802 int parameter_id = -1;
803 bool res_code = UniParameter::CheckAndGetParameterID(db_server, parameter_name, enum_parameter_type, parameter_id);
804 if (!res_code) {
805 delete connDb;
806 return nullptr;
807 }
808
809 TString sql = TString::Format("insert into detector_parameter(detector_name, parameter_id, start_period, "
810 "start_run, end_period, end_run, value_key, parameter_value) "
811 "values ($1, $2, $3, $4, $5, $6, $7, $8)");
812 TSQLStatement* stmt = db_server->Statement(sql);
813
814 // cout<<"DEBUG: detector_name = "<<detector_name<<". parameter_id = "<<parameter_id<<". start_period =
815 // "<<start_period<<". start_run = "<<start_run<<". end_period = "<<end_period<<". end_run = "<<end_run<<".
816 // value_key = "<<value_key<<". p_parameter_value[0] = "<<p_parameter_value[0]<<". size_parameter_value =
817 // "<<size_parameter_value<<endl;
818 stmt->NextIteration();
819 stmt->SetString(0, detector_name);
820 stmt->SetInt(1, parameter_id);
821 stmt->SetInt(2, start_period);
822 stmt->SetInt(3, start_run);
823 stmt->SetInt(4, end_period);
824 stmt->SetInt(5, end_run);
825 stmt->SetInt(6, value_key);
826 stmt->SetBinary(7, (void*)p_parameter_value, size_parameter_value);
827
828 // inserting new record to DB
829 if (!stmt->Process()) {
830 cout << "ERROR: inserting new parameter value to the database has been failed" << endl;
831 delete stmt;
832 delete connDb;
833 return nullptr;
834 }
835
836 delete stmt;
837
838 // getting last inserted node ID
839 int last_id = -1;
840 // TSQLStatement* stmt_last = db_server->Statement("SELECT LAST_INSERT_ID()"); //MySQL
841 TSQLStatement* stmt_last =
842 db_server->Statement("SELECT currval(pg_get_serial_sequence('detector_parameter','value_id'))");
843
844 if (stmt_last->Process()) {
845 // store result of statement in buffer
846 stmt_last->StoreResult();
847
848 // if there is no last id then exit with error
849 if (!stmt_last->NextResultRow()) {
850 cout << "ERROR: no last ID in the Database for the parameter value has been found!" << endl;
851 delete stmt_last;
852 return nullptr;
853 } else {
854 last_id = stmt_last->GetInt(0);
855 delete stmt_last;
856 }
857 } else {
858 cout << "ERROR: getting last ID for new parameter value has been failed!" << endl;
859 delete stmt_last;
860 return nullptr;
861 }
862
863 // unsigned char* tmp_parameter_value = new unsigned char[size_parameter_value];
864 // memcpy(tmp_parameter_value, p_parameter_value, size_parameter_value);
865 return new UniDetectorParameter(connDb, last_id, detector_name, parameter_id, start_period, start_run, end_period,
866 end_run, value_key, p_parameter_value, size_parameter_value, nullptr);
867}
868
869// write detector parameter value presented by an array (integer value key is optional, default, 0)
871 TString parameter_name,
872 int start_period,
873 int start_run,
874 int end_period,
875 int end_run,
876 vector<UniValue*> parameter_value,
877 int value_key)
878{
879 if (parameter_value.size() < 1) {
880 cout << "ERROR: The length of the parameter array should be greater zero" << endl;
881 return nullptr;
882 }
883 enumValueType parameter_type = parameter_value[0]->GetType();
884
885 // calculate total size
886 size_t size_parameter_value = 0;
887 for (size_t i = 0; i < parameter_value.size(); i++) {
888 if (parameter_value[i]->GetType() != parameter_type) {
889 cout << "ERROR: the type of the parameters in the array must be the same" << endl;
890 return nullptr;
891 }
892 size_parameter_value += parameter_value[i]->GetStorageSize();
893 }
894
895 // write parameters of the vector to the buffer
896 unsigned char* p_parameter_value = new unsigned char[size_parameter_value];
897 unsigned char* tmp_pointer = p_parameter_value;
898 for (size_t i = 0; i < parameter_value.size(); i++) {
899 parameter_value[i]->WriteValue(tmp_pointer);
900 tmp_pointer += parameter_value[i]->GetStorageSize();
901 }
902
903 if (start_run < 1) {
904 int first_run = UniRunPeriod::GetFirstRunNumber(start_period);
905 if (first_run >= 0)
906 start_run = first_run;
907 }
908 if (end_period < 1)
909 end_period = start_period;
910 if (end_run < 1) {
911 int last_run = UniRunPeriod::GetLastRunNumber(end_period);
912 if (last_run >= 0)
913 end_run = last_run;
914 }
915
917 detector_name, parameter_name, start_period, start_run, end_period, end_run, p_parameter_value,
918 size_parameter_value, parameter_type, value_key);
919 if (pDetectorParameter == nullptr)
920 delete[] p_parameter_value;
921
922 return pDetectorParameter;
923}
924
925// write detector parameter value presented by a single value (integer value key is optional, default, 0)
927 TString parameter_name,
928 int start_period,
929 int start_run,
930 int end_period,
931 int end_run,
932 UniValue* parameter_value,
933 int value_key)
934{
935 if (parameter_value == nullptr) {
936 cout << "ERROR: the parameter value must not be nullptr" << endl;
937 return nullptr;
938 }
939 enumValueType parameter_type = parameter_value->GetType();
940
941 // write the parameter to the buffer
942 size_t size_parameter_value = parameter_value->GetStorageSize();
943 unsigned char* p_parameter_value = new unsigned char[size_parameter_value];
944 parameter_value->WriteValue(p_parameter_value);
945
946 if (start_run < 1) {
947 int first_run = UniRunPeriod::GetFirstRunNumber(start_period);
948 if (first_run >= 0)
949 start_run = first_run;
950 }
951 if (end_period < 1)
952 end_period = start_period;
953 if (end_run < 1) {
954 int last_run = UniRunPeriod::GetLastRunNumber(end_period);
955 if (last_run >= 0)
956 end_run = last_run;
957 }
958
960 detector_name, parameter_name, start_period, start_run, end_period, end_run, p_parameter_value,
961 size_parameter_value, parameter_type, value_key);
962 if (pDetectorParameter == nullptr)
963 delete[] p_parameter_value;
964
965 return pDetectorParameter;
966}
967
968// get detector parameter value (integer value key is optional, default, 0)
970 TString parameter_name,
971 int period_number,
972 int run_number,
973 TDatime* usage_time,
974 int value_key)
975{
977 if (connDb == nullptr)
978 return nullptr;
979
980 TSQLServer* db_server = connDb->GetSQLServer();
981
982 TString sql = TString::Format("select value_id, detector_name, p.parameter_id, start_period, start_run, "
983 "end_period, end_run, parameter_value, expiry_date "
984 "from detector_parameter dp join parameter_ p on dp.parameter_id = p.parameter_id "
985 "where lower(detector_name) = lower('%s') and lower(parameter_name) = lower('%s') "
986 "and (not (((%d < start_period) or ((%d = start_period) and (%d < start_run))) or "
987 "((%d > end_period) or ((%d = end_period) and (%d > end_run))))) "
988 "and value_key = %d",
989 detector_name.Data(), parameter_name.Data(), period_number, period_number, run_number,
990 period_number, period_number, run_number, value_key);
991 if (usage_time != nullptr)
992 sql += TString::Format(" and ((expiry_date is null) or ('%s' < expiry_date)) order by expiry_date",
993 (*usage_time).AsSQLString());
994 else
995 sql += " and expiry_date is null";
996 TSQLStatement* stmt = db_server->Statement(sql);
997
998 // get table record from DB
999 if (!stmt->Process()) {
1000 cout << "ERROR: getting record from the Database has been failed" << endl;
1001 delete stmt;
1002 delete connDb;
1003 return nullptr;
1004 }
1005
1006 // store result of statement in buffer
1007 stmt->StoreResult();
1008
1009 // extract row
1010 if (!stmt->NextResultRow()) {
1011 cout << "ERROR: parameter value was not found in the Condition Database" << endl;
1012 delete stmt;
1013 delete connDb;
1014 return nullptr;
1015 }
1016
1017 int tmp_value_id;
1018 tmp_value_id = stmt->GetInt(0);
1019 TString tmp_detector_name;
1020 tmp_detector_name = stmt->GetString(1);
1021 int tmp_parameter_id;
1022 tmp_parameter_id = stmt->GetInt(2);
1023 int tmp_start_period;
1024 tmp_start_period = stmt->GetInt(3);
1025 int tmp_start_run;
1026 tmp_start_run = stmt->GetInt(4);
1027 int tmp_end_period;
1028 tmp_end_period = stmt->GetInt(5);
1029 int tmp_end_run;
1030 tmp_end_run = stmt->GetInt(6);
1031 unsigned char* tmp_parameter_value = nullptr;
1032 Long_t tmp_sz_parameter_value = 0;
1033 stmt->GetBinary(7, (void*&)tmp_parameter_value, tmp_sz_parameter_value);
1034 TDatime* tmp_expiry_date;
1035 if (stmt->IsNull(8))
1036 tmp_expiry_date = nullptr;
1037 else
1038 tmp_expiry_date = new TDatime(stmt->GetDatime(8));
1039
1040 delete stmt;
1041
1042 return new UniDetectorParameter(connDb, tmp_value_id, tmp_detector_name, tmp_parameter_id, tmp_start_period,
1043 tmp_start_run, tmp_end_period, tmp_end_run, value_key, tmp_parameter_value,
1044 tmp_sz_parameter_value, tmp_expiry_date);
1045}
1046
1047// delete detector parameter value (integer value key is optional, default, 0)
1049 TString parameter_name,
1050 int start_period,
1051 int start_run,
1052 int end_period,
1053 int end_run,
1054 TDatime* usage_time,
1055 int value_key)
1056{
1058 if (connDb == nullptr)
1059 return -1;
1060
1061 TSQLServer* db_server = connDb->GetSQLServer();
1062
1063 TString sql = "delete from detector_parameter "
1064 "where lower(detector_name) = lower($1) and parameter_id IN (select parameter_id from parameter_ "
1065 "where lower(parameter_name) = lower($2)) and "
1066 "start_period = $3 and start_run = $4 and end_period = $5 and end_run = $6 and value_key = $7";
1067 if (usage_time == nullptr)
1068 sql += " and expiry_date is null";
1069 else
1070 sql += " and expiry_date >= $8 and expiry_date < $9";
1071 TSQLStatement* stmt = db_server->Statement(sql);
1072
1073 stmt->NextIteration();
1074 stmt->SetString(0, detector_name);
1075 stmt->SetString(1, parameter_name);
1076 stmt->SetInt(2, start_period);
1077 stmt->SetInt(3, start_run);
1078 stmt->SetInt(4, end_period);
1079 stmt->SetInt(5, end_run);
1080 stmt->SetInt(6, value_key);
1081 if (usage_time != nullptr) {
1082 stmt->SetDatime(7, *usage_time);
1083 TDatime dt_plus_1(usage_time->Convert() + 1);
1084 stmt->SetDatime(8, dt_plus_1);
1085 }
1086
1087 // delete table record from DB
1088 if (!stmt->Process()) {
1089 cout << "ERROR: deleting parameter value from the Database has been failed" << endl;
1090
1091 delete stmt;
1092 delete connDb;
1093 return -2;
1094 }
1095
1096 if (stmt->GetNumAffectedRows() == 0) {
1097 cout << "WARNING: parameter value was not found in the Condition Database for deletion" << endl;
1098 delete stmt;
1099 delete connDb;
1100 return -2;
1101 }
1102
1103 delete stmt;
1104 delete connDb;
1105 return 0;
1106}
1107
1108// get value of detector parameter presented by an array
1109int UniDetectorParameter::GetValue(vector<UniValue*>& parameter_value)
1110{
1111 unsigned char* p_parameter_value = GetUNC();
1112 if (p_parameter_value == nullptr)
1113 return -1;
1114
1115 Long_t full_size = sz_parameter_value;
1116 while (full_size > 0) {
1117 // cout<<"full_size = "<<full_size<<". GetParameterType() = "<<GetParameterType()<<endl;
1118 UniValue* pParameterValue = CreateParameterValue(GetParameterType());
1119 pParameterValue->ReadValue(p_parameter_value);
1120 full_size -= pParameterValue->GetStorageSize();
1121 p_parameter_value += pParameterValue->GetStorageSize();
1122 parameter_value.push_back(pParameterValue);
1123 }
1124
1125 return 0;
1126}
1127
1128// get value of detector parameter presented by a single value
1130{
1131 unsigned char* p_parameter_value = GetUNC();
1132 if (p_parameter_value == nullptr)
1133 return nullptr;
1134
1135 UniValue* parameter_value = CreateParameterValue(GetParameterType());
1136 parameter_value->ReadValue(p_parameter_value);
1137
1138 return parameter_value;
1139}
1140
1141// set value to detector parameter presented by an array
1142int UniDetectorParameter::SetValue(vector<UniValue*> parameter_value)
1143{
1144 if (parameter_value.size() < 1) {
1145 cout << "ERROR: The length of the parameter array should be greater zero" << endl;
1146 return -1;
1147 }
1148
1149 // calculate full size to create a 'char' buffer
1150 size_t size_parameter_value = 0;
1151 for (size_t i = 0; i < parameter_value.size(); i++)
1152 size_parameter_value += parameter_value[i]->GetStorageSize();
1153 unsigned char* p_parameter_value = new unsigned char[size_parameter_value];
1154
1155 // write value by value to the 'char' buffer
1156 unsigned char* tmp_pointer = p_parameter_value;
1157 for (size_t i = 0; i < parameter_value.size(); i++) {
1158 parameter_value[i]->WriteValue(tmp_pointer);
1159 tmp_pointer += parameter_value[i]->GetStorageSize();
1160 }
1161
1162 int res_code = SetUNC(p_parameter_value, size_parameter_value);
1163 if (res_code != 0) {
1164 delete[] p_parameter_value;
1165 return res_code;
1166 }
1167
1168 return 0;
1169}
1170
1171// set value to detector parameter presented by a single value
1173{
1174 if (parameter_value == nullptr) {
1175 cout << "ERROR: the parameter value must not be nullptr" << endl;
1176 return -1;
1177 }
1178
1179 // write value to the 'char' buffer
1180 size_t size_parameter_value = parameter_value->GetStorageSize();
1181 unsigned char* p_parameter_value = new unsigned char[size_parameter_value];
1182 parameter_value->WriteValue(p_parameter_value);
1183
1184 int res_code = SetUNC(p_parameter_value, size_parameter_value);
1185 if (res_code != 0) {
1186 delete[] p_parameter_value;
1187 return res_code;
1188 }
1189
1190 return 0;
1191}
1192
1193// write ROOT object as a binary parameter to the Database from start run to end one
1194int UniDetectorParameter::WriteObjectBinary(const char* detector_name,
1195 const char* parameter_name,
1196 int start_period,
1197 int start_run,
1198 int end_period,
1199 int end_run,
1200 TObject* ptr_object)
1201{
1202 if (!ptr_object) {
1203 cout << "ERROR: object pointer is nullptr" << endl;
1204 return -1;
1205 }
1206
1207 // Create buffer to write ROOT object
1209
1210 // Serialize ROOT object to the buffer
1211 buf.WriteObject(ptr_object);
1212
1213 if (!buf.Buffer()) {
1214 cout << "ERROR: buffer for writing the given object is nullptr" << endl;
1215 return -2;
1216 }
1217
1218 // create binary parameter with the buffer bytes
1219 BinaryValue* pValue = new BinaryValue;
1220 pValue->size = buf.Length();
1221 pValue->value = (unsigned char*) buf.Buffer();
1223 detector_name, parameter_name, start_period, start_run, end_period, end_run, pValue);
1224 if (pParameterValue == nullptr) {
1225 delete pValue;
1226 return -3;
1227 }
1228
1229 delete pValue;
1230 delete pParameterValue;
1231
1232 return 0;
1233}
1234
1235// read ROOT object as a binary parameter from from the Database for the selected run
1236int UniDetectorParameter::ReadObjectBinary(const char* detector_name,
1237 const char* parameter_name,
1238 int period_number,
1239 int run_number,
1240 TObject*& ptr_object)
1241{
1242 UniDetectorParameter* pDetectorParameter =
1243 UniDetectorParameter::GetDetectorParameter(detector_name, parameter_name, period_number, run_number);
1244 if (!pDetectorParameter)
1245 return -1;
1246 BinaryValue* pValue = (BinaryValue*) pDetectorParameter->GetValue();
1247 if (!pValue)
1248 return -2;
1249
1250 // Create buffer to read ROOT object
1251 TBufferFile buf(TBuffer::kRead, pValue->size, pValue->value);
1252
1253 // Deserialize the object
1254 ptr_object = buf.ReadObject(TObject::Class());
1255
1256 delete pValue;
1257
1258 return 0;
1259}
1260
1261// write ROOT object as a JSON parameter to the Database from start run to end one
1262int UniDetectorParameter::WriteObjectJSON(const char* detector_name,
1263 const char* parameter_name,
1264 int start_period,
1265 int start_run,
1266 int end_period,
1267 int end_run,
1268 TObject* ptr_object)
1269{
1270 if (!ptr_object) {
1271 cout << "ERROR: object pointer is nullptr" << endl;
1272 return -1;
1273 }
1274
1275 // Create JSON string to write the ROOT object
1276 TString json_str = TBufferJSON::ConvertToJSON(ptr_object);
1277
1278 // create JSON parameter with the object
1279 JsonValue json_value;
1280 json_value.value = json::parse(json_str.Data());
1282 detector_name, parameter_name, start_period, start_run, end_period, end_run, &json_value);
1283 if (pParameterValue == nullptr) {
1284 return -2;
1285 }
1286
1287 // clean memory after work
1288 delete pParameterValue;
1289
1290 return 0;
1291}
1292
1293// read ROOT object as a JSON parameter from from the Database for the selected run
1294int UniDetectorParameter::ReadObjectJSON(const char* detector_name,
1295 const char* parameter_name,
1296 int period_number,
1297 int run_number,
1298 TObject*& ptr_object)
1299{
1300 // get parameter value (JSON value)
1301 UniDetectorParameter* pDetectorParameter =
1302 UniDetectorParameter::GetDetectorParameter(detector_name, parameter_name, period_number, run_number);
1303 if (!pDetectorParameter)
1304 return -1;
1305 JsonValue* pValue = (JsonValue*)pDetectorParameter->GetValue();
1306 if (!pValue)
1307 return -2;
1308
1309 // Read ROOT object from the JSON value
1310 ptr_object = TBufferJSON::ConvertFromJSON(pValue->value.dump().c_str());
1311
1312 // clean memory after work
1313 delete pValue;
1314
1315 return 0;
1316}
1317
1318// write a whole file with parameter value (with given detector and parameter names)
1319// to the Database from start run to end one
1320int UniDetectorParameter::WriteFile(const char* detector_name,
1321 const char* parameter_name,
1322 int start_period,
1323 int start_run,
1324 int end_period,
1325 int end_run,
1326 const char* file_path)
1327{
1328 TString strFilePath(file_path);
1329 gSystem->ExpandPathName(strFilePath);
1330
1331 FILE* cur_file = fopen(strFilePath.Data(), "rb");
1332 if (cur_file == nullptr) {
1333 cout << "ERROR: opening file: " << strFilePath << " was failed" << endl;
1334 return -1;
1335 }
1336
1337 fseek(cur_file, 0, SEEK_END);
1338 size_t file_size = ftell(cur_file);
1339 rewind(cur_file);
1340 if (file_size <= 0) {
1341 cout << "ERROR: getting file size: " << strFilePath << " was failed" << endl;
1342 fclose(cur_file);
1343 return -2;
1344 }
1345
1346 unsigned char* buffer = new unsigned char[file_size];
1347 if (buffer == nullptr) {
1348 cout << "ERROR: getting memory from heap for file was failed" << endl;
1349 fclose(cur_file);
1350 return -3;
1351 }
1352
1353 size_t bytes_read = fread(buffer, 1, file_size, cur_file);
1354 if (bytes_read != file_size) {
1355 cout << "ERROR: reading file: " << strFilePath << ", got " << bytes_read << " bytes of " << file_size << endl;
1356 delete[] buffer;
1357 fclose(cur_file);
1358 return -4;
1359 }
1360
1361 fclose(cur_file);
1362
1363 // create binary parameter with file's bytes
1364 BinaryValue* pValue = new BinaryValue;
1365 pValue->size = file_size;
1366 pValue->value = buffer;
1368 detector_name, parameter_name, start_period, start_run, end_period, end_run, pValue);
1369 if (pParameterValue == nullptr) {
1370 delete[] buffer;
1371 return -5;
1372 }
1373 delete pValue;
1374
1375 delete[] buffer;
1376 delete pParameterValue;
1377
1378 return 0;
1379}
1380
1381// read a whole file with parameter value (with given detector and parameter names)
1382// from the Database for the selected run
1383int UniDetectorParameter::ReadFile(const char* detector_name,
1384 const char* parameter_name,
1385 int period_number,
1386 int run_number,
1387 const char* file_path)
1388{
1389 UniDetectorParameter* pDetectorParameter =
1390 UniDetectorParameter::GetDetectorParameter(detector_name, parameter_name, period_number, run_number);
1391 if (pDetectorParameter == nullptr)
1392 return -1;
1393 BinaryValue* pValue = (BinaryValue*)pDetectorParameter->GetValue();
1394
1395 FILE* cur_file = fopen(file_path, "wb");
1396 if (cur_file == nullptr) {
1397 cout << "ERROR: creating file: " << file_path << " has been failed!" << endl;
1398 delete pValue;
1399 delete pDetectorParameter;
1400 return -2;
1401 }
1402
1403 unsigned char* buffer = pValue->value;
1404 if (buffer == nullptr) {
1405 cout << "ERROR: getting binary parameter array" << endl;
1406 delete pValue;
1407 delete pDetectorParameter;
1408 fclose(cur_file);
1409 return -3;
1410 }
1411 size_t parameter_size = pValue->size;
1412
1413 size_t bytes_write = fwrite(buffer, 1, parameter_size, cur_file);
1414 delete pDetectorParameter;
1415 if (bytes_write != parameter_size) {
1416 cout << "ERROR: writing file: " << file_path << ", put " << bytes_write << " bytes of " << parameter_size
1417 << endl;
1418 fclose(cur_file);
1419 delete pValue;
1420 return -4;
1421 }
1422
1423 fclose(cur_file);
1424 delete[] buffer;
1425 delete pValue;
1426
1427 return 0;
1428}
1429
1431{
1432 TObjArray* arrayResult = nullptr;
1433 search_conditions.SetOwner(kTRUE);
1434
1436 if (connDb == nullptr) {
1437 cout << "ERROR: the connection to the Unified Condition Database was failed" << endl;
1438 return arrayResult;
1439 }
1440
1441 TSQLServer* db_server = connDb->GetSQLServer();
1442
1443 TString sql = TString::Format("select value_id, detector_name, p.parameter_id, start_period, start_run, "
1444 "end_period, end_run, value_key, parameter_value, expiry_date "
1445 "from detector_parameter dp join parameter_ p on dp.parameter_id = p.parameter_id");
1446
1447 TString strCondition;
1448 bool isFirst = true;
1449 TIter next(&search_conditions);
1450 UniSearchCondition* curCondition;
1451 while ((curCondition = (UniSearchCondition*)next()) != nullptr) {
1452 strCondition = "";
1453
1454 switch (curCondition->GetColumn()) {
1456 strCondition += "lower(detector_name) ";
1457 break;
1459 strCondition += "lower(parameter_name) ";
1460 break;
1462 strCondition += "start_period ";
1463 break;
1465 strCondition += "start_run ";
1466 break;
1468 strCondition += "end_period ";
1469 break;
1471 strCondition += "end_run ";
1472 break;
1473 default:
1474 cout << "ERROR: the column in the search condition was not defined, the condition is skipped" << endl;
1475 continue;
1476 }
1477
1478 switch (curCondition->GetCondition()) {
1480 strCondition += "< ";
1481 break;
1483 strCondition += "<= ";
1484 break;
1486 strCondition += "= ";
1487 break;
1489 strCondition += "<> ";
1490 break;
1492 strCondition += "> ";
1493 break;
1495 strCondition += ">= ";
1496 break;
1498 strCondition += "like ";
1499 break;
1501 strCondition += "is null ";
1502 break;
1504 strCondition += "is not null ";
1505 break;
1506 default:
1507 cout << "ERROR: the comparison operator in the search condition was not defined, the condition is "
1508 "skipped"
1509 << endl;
1510 continue;
1511 }
1512
1513 switch (curCondition->GetValueType()) {
1514 case 0:
1515 if ((curCondition->GetCondition() != UniSearchCondition::conditionNull)
1516 && (curCondition->GetCondition() != UniSearchCondition::conditionNotNull))
1517 continue;
1518 break;
1519 case 1:
1520 strCondition += Form("%d", curCondition->GetIntValue());
1521 break;
1522 case 2:
1523 strCondition += Form("%u", curCondition->GetUIntValue());
1524 break;
1525 case 3:
1526 strCondition += Form("%f", curCondition->GetDoubleValue());
1527 break;
1528 case 4:
1529 strCondition += Form("lower('%s')", curCondition->GetStringValue().Data());
1530 break;
1531 case 5:
1532 strCondition += Form("'%s'", curCondition->GetDatimeValue().AsSQLString());
1533 break;
1534 default:
1535 cout << "ERROR: the value type in the search condition was not found, the condition is skipped" << endl;
1536 continue;
1537 }
1538
1539 if (isFirst) {
1540 sql += " where ";
1541 isFirst = false;
1542 } else
1543 sql += " and ";
1544
1545 sql += strCondition;
1546 }
1547
1548 TSQLStatement* stmt = db_server->Statement(sql);
1549
1550 // get table record from DB
1551 if (!stmt->Process()) {
1552 cout << "ERROR: getting runs from the Unified Condition Database has been failed" << endl;
1553 delete stmt;
1554 delete connDb;
1555
1556 return arrayResult;
1557 }
1558
1559 // store result of statement in buffer
1560 stmt->StoreResult();
1561
1562 // extract rows one after another
1563 arrayResult = new TObjArray();
1564 arrayResult->SetOwner(kTRUE);
1565 while (stmt->NextResultRow()) {
1567 if (connPar == nullptr) {
1568 cout << "ERROR: the connection to the Unified Condition Database for the selected run was failed" << endl;
1569 return arrayResult;
1570 }
1571
1572 int tmp_value_id;
1573 tmp_value_id = stmt->GetInt(0);
1574 TString tmp_detector_name;
1575 tmp_detector_name = stmt->GetString(1);
1576 int tmp_parameter_id;
1577 tmp_parameter_id = stmt->GetInt(2);
1578 int tmp_start_period;
1579 tmp_start_period = stmt->GetInt(3);
1580 int tmp_start_run;
1581 tmp_start_run = stmt->GetInt(4);
1582 int tmp_end_period;
1583 tmp_end_period = stmt->GetInt(5);
1584 int tmp_end_run;
1585 tmp_end_run = stmt->GetInt(6);
1586 int tmp_value_key;
1587 tmp_value_key = stmt->GetInt(7);
1588 unsigned char* tmp_parameter_value;
1589 tmp_parameter_value = nullptr;
1590 Long_t tmp_sz_parameter_value = 0;
1591 stmt->GetBinary(8, (void*&)tmp_parameter_value, tmp_sz_parameter_value);
1592 TDatime* tmp_expiry_date;
1593 if (stmt->IsNull(9))
1594 tmp_expiry_date = nullptr;
1595 else
1596 tmp_expiry_date = new TDatime(stmt->GetDatime(9));
1597
1598 arrayResult->Add((TObject*)new UniDetectorParameter(
1599 connPar, tmp_value_id, tmp_detector_name, tmp_parameter_id, tmp_start_period, tmp_start_run, tmp_end_period,
1600 tmp_end_run, tmp_value_key, tmp_parameter_value, tmp_sz_parameter_value, tmp_expiry_date));
1601 }
1602
1603 delete stmt;
1604
1605 arrayResult->SetOwner(kTRUE);
1606 return arrayResult;
1607}
1608
1610{
1611 TObjArray search_conditions;
1612 search_conditions.Add((TObject*)&search_condition);
1613
1614 return Search(search_conditions);
1615}
1616
1617// get parameter name of the current detector parameter
1619{
1621 if (pCurParameter == nullptr) {
1622 cout << "ERROR: parameter with current ID was not found" << endl;
1623 return "";
1624 }
1625
1626 TString par_name = pCurParameter->GetParameterName();
1627
1628 delete pCurParameter;
1629 return par_name;
1630}
1631
1632// get parameter type of the current detector parameter
1634{
1636 if (pCurParameter == nullptr) {
1637 cout << "ERROR: parameter with current ID was not found" << endl;
1638 return UndefinedType;
1639 }
1640
1641 enumValueType par_type = (enumValueType)pCurParameter->GetParameterType();
1642
1643 delete pCurParameter;
1644 return par_type;
1645}
1646
1647// get start period and run of the current detector parameter
1648void UniDetectorParameter::GetStart(int& start_period, int& start_run)
1649{
1650 start_period = i_start_period;
1651 start_run = i_start_run;
1652
1653 return;
1654}
1655
1656// get end period and run of the current detector parameter
1657void UniDetectorParameter::GetEnd(int& end_period, int& end_run)
1658{
1659 end_period = i_end_period;
1660 end_run = i_end_run;
1661
1662 return;
1663}
1664
1665// set start period and run of the current detector parameter
1666int UniDetectorParameter::SetStart(int start_period, int start_run)
1667{
1668 if (!connectionDB) {
1669 cout << "ERROR: Connection object is null" << endl;
1670 return -1;
1671 }
1672
1673 TSQLServer* db_server = connectionDB->GetSQLServer();
1674
1675 TString sql = TString::Format("update detector_parameter "
1676 "set start_period = $1, start_run = $2"
1677 "where value_id = $3");
1678 TSQLStatement* stmt = db_server->Statement(sql);
1679
1680 stmt->NextIteration();
1681 stmt->SetInt(0, start_period);
1682 stmt->SetInt(1, start_run);
1683 stmt->SetInt(2, i_value_id);
1684
1685 // write new value to database
1686 if (!stmt->Process()) {
1687 cout << "ERROR: updating the record has been failed" << endl;
1688
1689 delete stmt;
1690 return -2;
1691 }
1692
1693 i_start_period = start_period;
1694 i_start_run = start_run;
1695
1696 delete stmt;
1697 return 0;
1698}
1699
1700// set end period and run of the current detector parameter
1701int UniDetectorParameter::SetEnd(int end_period, int end_run)
1702{
1703 if (!connectionDB) {
1704 cout << "ERROR: Connection object is null" << endl;
1705 return -1;
1706 }
1707
1708 TSQLServer* db_server = connectionDB->GetSQLServer();
1709
1710 TString sql = TString::Format("update detector_parameter "
1711 "set end_period = $1, end_run = $2"
1712 "where value_id = $3");
1713 TSQLStatement* stmt = db_server->Statement(sql);
1714
1715 stmt->NextIteration();
1716 stmt->SetInt(0, end_period);
1717 stmt->SetInt(1, end_run);
1718 stmt->SetInt(2, i_value_id);
1719
1720 // write new value to database
1721 if (!stmt->Process()) {
1722 cout << "ERROR: updating the record has been failed" << endl;
1723
1724 delete stmt;
1725 return -2;
1726 }
1727
1728 i_end_period = end_period;
1729 i_end_run = end_run;
1730
1731 delete stmt;
1732 return 0;
1733}
1734
1735// ----- Print all 'detector parameters', except expired if the flag is true ---------------------------------
1736int UniDetectorParameter::PrintAll(bool isNonExpiredOnly)
1737{
1739 if (connDb == nullptr)
1740 return -1;
1741
1742 TSQLServer* db_server = connDb->GetSQLServer();
1743
1744 TString sql = TString::Format("select value_id, detector_name, parameter_id, start_period, start_run, end_period, "
1745 "end_run, value_key, parameter_value, expiry_date "
1746 "from detector_parameter%s",
1747 isNonExpiredOnly ? " where expiry_date is null" : "");
1748 TSQLStatement* stmt = db_server->Statement(sql);
1749
1750 // get all 'detector parameters' from the database
1751 if (!stmt->Process()) {
1752 cout << "ERROR: getting all 'detector parameters' from the database has been failed" << endl;
1753
1754 delete stmt;
1755 delete connDb;
1756 return -2;
1757 }
1758
1759 // store result of statement in buffer
1760 stmt->StoreResult();
1761
1762 // print rows
1763 cout << "Table 'detector_parameter':" << endl;
1764 while (stmt->NextResultRow()) {
1765 cout << "value_id: ";
1766 cout << (stmt->GetInt(0));
1767 cout << ", detector_name: ";
1768 cout << (stmt->GetString(1));
1769 cout << ", parameter_id: ";
1770 cout << (stmt->GetInt(2));
1771 cout << ", start_period: ";
1772 cout << (stmt->GetInt(3));
1773 cout << ", start_run: ";
1774 cout << (stmt->GetInt(4));
1775 cout << ", end_period: ";
1776 cout << (stmt->GetInt(5));
1777 cout << ", end_run: ";
1778 cout << (stmt->GetInt(6));
1779 cout << ", value_key: ";
1780 cout << (stmt->GetInt(7));
1781 cout << ", parameter_value: ";
1782 unsigned char* tmp_parameter_value = nullptr;
1783 Long_t tmp_sz_parameter_value = 0;
1784 stmt->GetBinary(8, (void*&)tmp_parameter_value, tmp_sz_parameter_value);
1785 cout << (void*)tmp_parameter_value << ", binary size: " << tmp_sz_parameter_value;
1786 if (!isNonExpiredOnly) {
1787 cout << ", expiry_date: ";
1788 if (stmt->IsNull(9))
1789 cout << "nullptr";
1790 else
1791 cout << stmt->GetDatime(9).AsSQLString();
1792 }
1793 cout << "." << endl;
1794 }
1795
1796 delete stmt;
1797 delete connDb;
1798
1799 return 0;
1800}
1801
1802/*
1803/// parse detector parameter's values, function returns row count added to the database
1804int UniDetectorParameter::ParseTxt(TString text_file, TString detector_name, TString parameter_name, int start_period,
1805int start_run, int end_period, int end_run, bool isSerialChannel)
1806{
1807 ifstream txtFile;
1808 txtFile.open(text_file, ios::in);
1809 if (!txtFile.is_open())
1810 {
1811 cout<<"Error: opening TXT file '"<<text_file<<"' was failed"<<endl;
1812 return -1;
1813 }
1814
1815 // open connection to database
1816 UniConnection* connDb = UniConnection::Open();
1817 if (connDb == nullptr)
1818 return -3;
1819
1820 TSQLServer* db_server = connDb->GetSQLServer();
1821
1822 string cur_line;
1823 while (getline(txtFile, cur_line))
1824 {
1825 //remove duplicates of whitespaces and tabs
1826 TString reduce_line = reduce(cur_line);
1827
1828 if (reduce_line[0] == '#')
1829 continue;
1830
1831 //stringstream ss;
1832 //ss.str(reduce_line);
1833
1834 // get detector object from 'detector_' table
1835 TString sql = TString::Format(
1836 "select detector_name "
1837 "from detector_ "
1838 "where lower(detector_name) = lower('%s'')", detector_name.Data());
1839 TSQLStatement* stmt = db_server->Statement(sql);
1840
1841 // get table record from DB
1842 if (!stmt->Process())
1843 {
1844 cout<<"Error: getting record with detector from 'detector_' table has been failed"<<endl;
1845 delete stmt;
1846 return -4;
1847 }
1848 stmt->StoreResult();
1849
1850 // check detector with the given name is exist
1851 if (!stmt->NextResultRow())
1852 {
1853 cout<<"Error: the detector with name '"<<detector_name<<"' was not found"<<endl;
1854 delete stmt;
1855 return -5;
1856 }
1857
1858 detector_name = stmt->GetString(0);
1859
1860 delete stmt;
1861
1862 // get parameter object from 'parameter_' table
1863 sql = TString::Format(
1864 "select parameter_id, parameter_name, parameter_type "
1865 "from parameter_ "
1866 "where lower(parameter_name) = lower('%s')", parameter_name.Data());
1867 stmt = db_server->Statement(sql);
1868
1869 // get table record from DB
1870 if (!stmt->Process())
1871 {
1872 cout<<"Error: getting record with parameter from 'parameter_' table has been failed"<<endl;
1873 delete stmt;
1874 return -6;
1875 }
1876
1877 stmt->StoreResult();
1878
1879 // extract row with parameter
1880 if (!stmt->NextResultRow())
1881 {
1882 cout<<"Error: the parameter with name '"<<parameter_name<<"' was not found"<<endl;
1883 delete stmt;
1884 return -7;
1885 }
1886
1887 //int parameter_id = stmt->GetInt(0);
1888 parameter_name = stmt->GetString(1);
1889 int parameter_type = stmt->GetInt(2);
1890
1891 delete stmt;
1892
1893 TObjArray* tokens = reduce_line.Tokenize("\t ");
1894 TObjString* item;
1895 int value_count = tokens->GetEntriesFast();
1896
1897 UniDetectorParameter* pDetectorParameter = nullptr;
1898 // choose parsing method for parameter's value according it's type
1899 int serial_number = -1, channel_number = -1, cur_num_item = 0;
1900 switch (parameter_type)
1901 {
1902 case BoolType:
1903 {
1904 int count_required = 1;
1905 if (isSerialChannel) count_required++, count_required++;
1906
1907 if (value_count != count_required)
1908 {
1909 cout<<"Warning: the count of parameters is not equal 1 or 3 ([serial] [channel]
1910value)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
1911 }
1912 if (isSerialChannel)
1913 {
1914 // get serial number
1915 item = (TObjString*) tokens->At(cur_num_item++);
1916 serial_number = item->GetString().Atoi();
1917 // get channel number
1918 item = (TObjString*) tokens->At(cur_num_item++);
1919 channel_number = item->GetString().Atoi();
1920 }
1921 item = (TObjString*) tokens->At(cur_num_item++);
1922 tokens->Delete();
1923
1924 bool value = (bool) item->GetString().Atoi();
1925 if (isSerialChannel)
1926 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
1927parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, value); else
1928 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
1929parameter_name,start_period, start_run, end_period, end_run, value);
1930
1931 break;
1932 }
1933 case IntType:
1934 {
1935 int count_required = 1;
1936 if (isSerialChannel) count_required++, count_required++;
1937
1938 if (value_count != count_required)
1939 {
1940 cout<<"Warning: the count of parameters is not equal 1 or 3 ([serial] [channel]
1941value)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
1942 }
1943 if (isSerialChannel)
1944 {
1945 // get serial number
1946 item = (TObjString*) tokens->At(cur_num_item++);
1947 serial_number = item->GetString().Atoi();
1948 // get channel number
1949 item = (TObjString*) tokens->At(cur_num_item++);
1950 channel_number = item->GetString().Atoi();
1951 }
1952 item = (TObjString*) tokens->At(cur_num_item++);
1953 tokens->Delete();
1954
1955 int value = item->GetString().Atoi();
1956 if (value == 0)
1957 {
1958 if (!item->GetString().IsDigit())
1959 {
1960 cout<<"Error: the parameter value is not integer: '"<<item<<"'"<<endl;
1961 continue;
1962 }
1963 }
1964
1965 if (isSerialChannel)
1966 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
1967parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, value); else
1968 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
1969parameter_name,start_period, start_run, end_period, end_run, value);
1970
1971 break;
1972 }
1973 case DoubleType:
1974 {
1975 int count_required = 1;
1976 if (isSerialChannel) count_required++, count_required++;
1977
1978 if (value_count != count_required)
1979 {
1980 cout<<"Warning: the count of parameters is not equal 1 or 3 ([serial] [channel]
1981value)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
1982 }
1983 if (isSerialChannel)
1984 {
1985 // get serial number
1986 item = (TObjString*) tokens->At(cur_num_item++);
1987 serial_number = item->GetString().Atoi();
1988 // get channel number
1989 item = (TObjString*) tokens->At(cur_num_item++);
1990 channel_number = item->GetString().Atoi();
1991 }
1992 item = (TObjString*) tokens->At(cur_num_item++);
1993 tokens->Delete();
1994
1995 double value = item->GetString().Atof();
1996 if (isSerialChannel)
1997 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
1998parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, value); else
1999 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2000parameter_name,start_period, start_run, end_period, end_run, value);
2001
2002 break;
2003 }
2004 case IIArrayType:
2005 {
2006 int count_required = 2, size_arr = value_count/2;
2007 if (isSerialChannel)
2008 {
2009 count_required++, count_required++;
2010 size_arr--;
2011 }
2012
2013 if ((value_count < count_required) || ((value_count % 2) != 0))
2014 {
2015 cout<<"Warning: the count of parameters should be greater 2 or 4 ([serial] [channel] values@2)
2016and should be even"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2017 }
2018 if (isSerialChannel)
2019 {
2020 // get serial number
2021 item = (TObjString*) tokens->At(cur_num_item++);
2022 serial_number = item->GetString().Atoi();
2023 // get channel number
2024 item = (TObjString*) tokens->At(cur_num_item++);
2025 channel_number = item->GetString().Atoi();
2026 }
2027
2028 int iter = 0, num = count_required-2;
2029 IIStructure* pValues = new IIStructure[size_arr];
2030 for (; iter < size_arr; iter++)
2031 {
2032 pValues[iter].int_1 = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2033 pValues[iter].int_2 = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2034 }
2035 tokens->Delete();
2036
2037 if (isSerialChannel)
2038 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2039parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2040 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2041parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2042
2043 delete [] pValues;
2044 break;
2045 }
2046 case IntArrayType:
2047 {
2048 int count_required = 1, size_arr = value_count;
2049 if (isSerialChannel)
2050 {
2051 count_required++, count_required++;
2052 size_arr--, size_arr--;
2053 }
2054
2055 if (value_count < count_required)
2056 {
2057 cout<<"Warning: the count of parameters should be greater 1 or 3 ([serial] [channel] value1
2058value2...)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2059 }
2060 if (isSerialChannel)
2061 {
2062 // get serial number
2063 item = (TObjString*) tokens->At(cur_num_item++);
2064 serial_number = item->GetString().Atoi();
2065 // get channel number
2066 item = (TObjString*) tokens->At(cur_num_item++);
2067 channel_number = item->GetString().Atoi();
2068 }
2069
2070 int iter = 0;
2071 int* pValues = new int[size_arr];
2072 for (int num = count_required-1; num < value_count; num++,iter++)
2073 pValues[iter] = ((TObjString*) tokens->At(num))->GetString().Atoi();
2074 tokens->Delete();
2075
2076 if (isSerialChannel)
2077 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2078parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2079 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2080parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2081
2082 delete [] pValues;
2083 break;
2084 }
2085 case DoubleArrayType:
2086 {
2087 int count_required = 1, size_arr = value_count;
2088 if (isSerialChannel)
2089 {
2090 count_required++, count_required++;
2091 size_arr--, size_arr--;
2092 }
2093
2094 if (value_count < count_required)
2095 {
2096 cout<<"Warning: the count of parameters should be greater 1 or 3 ([serial] [channel] value1
2097value2...)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2098 }
2099 if (isSerialChannel)
2100 {
2101 // get serial number
2102 item = (TObjString*) tokens->At(cur_num_item++);
2103 serial_number = item->GetString().Atoi();
2104 // get channel number
2105 item = (TObjString*) tokens->At(cur_num_item++);
2106 channel_number = item->GetString().Atoi();
2107 }
2108
2109 int iter = 0;
2110 double* pValues = new double[size_arr];
2111 for (int num = count_required-1; num < value_count; num++, iter++)
2112 pValues[iter] = ((TObjString*) tokens->At(num))->GetString().Atof();
2113 tokens->Delete();
2114
2115 if (isSerialChannel)
2116 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2117parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2118 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2119parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2120
2121 delete [] pValues;
2122 break;
2123 }
2124 case UIntArrayType:
2125 {
2126 int count_required = 1, size_arr = value_count;
2127 if (isSerialChannel)
2128 {
2129 count_required++, count_required++;
2130 size_arr--, size_arr--;
2131 }
2132
2133 if (value_count < count_required)
2134 {
2135 cout<<"Warning: the count of parameters should be greater 1 or 3 ([serial] [channel] value1
2136value2...)"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2137 }
2138 if (isSerialChannel)
2139 {
2140 // get serial number
2141 item = (TObjString*) tokens->At(cur_num_item++);
2142 serial_number = item->GetString().Atoi();
2143 // get channel number
2144 item = (TObjString*) tokens->At(cur_num_item++);
2145 channel_number = item->GetString().Atoi();
2146 }
2147
2148 int iter = 0;
2149 unsigned int* pValues = new unsigned int[size_arr];
2150 for (int num = count_required-1; num < value_count; num++, iter++)
2151 pValues[iter] = (unsigned int) ((TObjString*) tokens->At(num))->GetString().Atoll();
2152 tokens->Delete();
2153
2154 if (isSerialChannel)
2155 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2156parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2157 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2158parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2159
2160 delete [] pValues;
2161 break;
2162 }
2163 case DchMapArrayType:
2164 {
2165 int count_required = 6, size_arr = value_count/6;
2166 if (isSerialChannel)
2167 count_required++, count_required++;
2168
2169 if ((value_count < count_required) || (((value_count-count_required+6) % 6) != 0))
2170 {
2171 cout<<"Warning: the count of parameters should be greater 6 or 8 ([serial] [channel] values@6)
2172and must be divisible by 6"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2173 }
2174 if (isSerialChannel)
2175 {
2176 // get serial number
2177 item = (TObjString*) tokens->At(cur_num_item++);
2178 serial_number = item->GetString().Atoi();
2179 // get channel number
2180 item = (TObjString*) tokens->At(cur_num_item++);
2181 channel_number = item->GetString().Atoi();
2182 }
2183
2184 int iter = 0, num = count_required-6;
2185 DchMapStructure* pValues = new DchMapStructure[size_arr];
2186 for (; iter < size_arr; iter++)
2187 {
2188 pValues[iter].plane = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2189 pValues[iter].group = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2190 pValues[iter].crate = (unsigned int) ((TObjString*) tokens->At(num++))->GetString().Atoll();
2191 pValues[iter].slot = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2192 pValues[iter].channel_low = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2193 pValues[iter].channel_high = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2194 }
2195 tokens->Delete();
2196
2197 if (isSerialChannel)
2198 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2199parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2200 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2201parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2202
2203 delete [] pValues;
2204 break;
2205 }
2206 case GemMapArrayType:
2207 {
2208 int count_required = 6, size_arr = value_count/6;
2209 if (isSerialChannel)
2210 count_required++, count_required++;
2211
2212 if ((value_count < count_required) || (((value_count-count_required+6) % 6) != 0))
2213 {
2214 cout<<"Warning: the count of parameters should be greater 6 or 8 ([serial] [channel] values@6)
2215and must be divisible by 6"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2216 }
2217 if (isSerialChannel)
2218 {
2219 // get serial number
2220 item = (TObjString*) tokens->At(cur_num_item++);
2221 serial_number = item->GetString().Atoi();
2222 // get channel number
2223 item = (TObjString*) tokens->At(cur_num_item++);
2224 channel_number = item->GetString().Atoi();
2225 }
2226
2227 int iter = 0, num = count_required-6;
2228 GemMapStructure* pValues = new GemMapStructure[size_arr];
2229 for (; iter < size_arr; iter++)
2230 {
2231 pValues[iter].serial = (unsigned int) ((TObjString*) tokens->At(num++))->GetString().Atoll();
2232 pValues[iter].id = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2233 pValues[iter].station = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2234 pValues[iter].channel_low = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2235 pValues[iter].channel_high = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2236 pValues[iter].hotZone = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2237 }
2238 tokens->Delete();
2239
2240 if (isSerialChannel)
2241 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2242parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2243 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2244parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2245
2246 delete [] pValues;
2247 break;
2248 }
2249 case GemPedestalArrayType:
2250 {
2251 int count_required = 4, size_arr = value_count/4;
2252 if (isSerialChannel)
2253 count_required++, count_required++;
2254
2255 if ((value_count < count_required) || (((value_count-count_required+4) % 4) != 0))
2256 {
2257 cout<<"Warning: the count of parameters should be greater 4 or 6 ([serial] [channel] values@6)
2258and must be divisible by 4"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2259 }
2260 if (isSerialChannel)
2261 {
2262 // get serial number
2263 item = (TObjString*) tokens->At(cur_num_item++);
2264 serial_number = item->GetString().Atoi();
2265 // get channel number
2266 item = (TObjString*) tokens->At(cur_num_item++);
2267 channel_number = item->GetString().Atoi();
2268 }
2269
2270 int iter = 0, num = count_required-4;
2271 GemPedestalStructure* pValues = new GemPedestalStructure[size_arr];
2272 for (; iter < size_arr; iter++)
2273 {
2274 pValues[iter].serial = (unsigned int) ((TObjString*) tokens->At(num++))->GetString().Atoll();
2275 pValues[iter].channel = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2276 pValues[iter].pedestal = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2277 pValues[iter].noise = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2278 }
2279 tokens->Delete();
2280
2281 if (isSerialChannel)
2282 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2283parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2284 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2285parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2286
2287 delete [] pValues;
2288 break;
2289 }
2290 case TriggerMapArrayType:
2291 {
2292 int count_required = 3, size_arr = value_count/3;
2293 if (isSerialChannel)
2294 count_required++, count_required++;
2295
2296 if ((value_count < count_required) || (((value_count-count_required+3) % 3) != 0))
2297 {
2298 cout<<"Warning: the count of parameters should be greater 3 or 5 ([serial] [channel] values@3)
2299and must be divisible by 3"<<endl<<"The current line will be skipped!"<<endl; tokens->Delete(); continue;
2300 }
2301 if (isSerialChannel)
2302 {
2303 // get serial number
2304 item = (TObjString*) tokens->At(cur_num_item++);
2305 serial_number = item->GetString().Atoi();
2306 // get channel number
2307 item = (TObjString*) tokens->At(cur_num_item++);
2308 channel_number = item->GetString().Atoi();
2309 }
2310
2311 int iter = 0, num = count_required-3;
2312 TriggerMapStructure* pValues = new TriggerMapStructure[size_arr];
2313 for (; iter < size_arr; iter++)
2314 {
2315 pValues[iter].serial = (unsigned int) ((TObjString*) tokens->At(num++))->GetString().Atoll();
2316 pValues[iter].slot = (unsigned int) ((TObjString*) tokens->At(num++))->GetString().Atoll();
2317 pValues[iter].channel = ((TObjString*) tokens->At(num++))->GetString().Atoi();
2318 }
2319 tokens->Delete();
2320
2321 if (isSerialChannel)
2322 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2323parameter_name,start_period, start_run, end_period, end_run, serial_number, channel_number, pValues, size_arr); else
2324 pDetectorParameter = UniDetectorParameter::CreateDetectorParameter(detector_name,
2325parameter_name,start_period, start_run, end_period, end_run, pValues, size_arr);
2326
2327 delete [] pValues;
2328 break;
2329 }
2330 default:
2331 {
2332 cout<<"Error: the type of parameter ("<<parameter_name<<") is not supported for parsing (txt)
2333now"<<endl; continue;
2334 }
2335 }// switch (parameter_type)
2336
2337 // clean memory
2338 if (pDetectorParameter)
2339 delete pDetectorParameter;
2340 }
2341
2342 txtFile.close();
2343 delete connDb;
2344
2345 return 0;
2346}*/
int i
Definition P4_F32vec4.h:22
long Long_t
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
TObject * ReadObject(const TClass *cl) override
Int_t WriteObject(const T *objptr, Bool_t cacheReuse=kTRUE)
static TObject * ConvertFromJSON(const char *str)
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Int_t Length() const
char * Buffer() const
virtual void SetOwner(Bool_t enable=kTRUE)
const char * AsSQLString() const
UInt_t Convert(Bool_t toGMT=kFALSE) const
void Add(TObject *obj) override
static TClass * Class()
virtual TSQLStatement * Statement(const char *, Int_t=100)
virtual const char * GetString(Int_t)
virtual Bool_t SetBinary(Int_t, void *, Long_t, Long_t=0x1000)
virtual Bool_t NextIteration()=0
virtual Bool_t NextResultRow()=0
virtual Int_t GetNumAffectedRows()
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 Process()=0
virtual Bool_t SetInt(Int_t, Int_t)
virtual Bool_t SetNull(Int_t)
virtual Bool_t StoreResult()=0
TDatime GetDatime(Int_t)
virtual Bool_t GetBinary(Int_t, void *&, Long_t &)
const char * Data() const
static TString Format(const char *fmt,...)
static UniConnection * Open()
TSQLServer * GetSQLServer()
int SetStart(int start_period, int start_run)
set start period and run of the current parameter value
int SetValue(vector< UniValue * > parameter_value)
set value to detector parameter presented by an array
static int WriteObjectBinary(const char *detector_name, const char *parameter_name, int start_period, int start_run, int end_period, int end_run, TObject *ptr_object)
write ROOT object as a binary parameter to the Database from start run to end one
static int WriteObjectJSON(const char *detector_name, const char *parameter_name, int start_period, int start_run, int end_period, int end_run, TObject *ptr_object)
write ROOT object as a JSON parameter to the Database from start run to end one
enumValueType GetParameterType()
get parameter type of the current parameter value
int SetValueKey(int value_key)
set value key of the current detector parameter
int SetDetectorName(TString detector_name)
set detector name of the current detector parameter
void GetStart(int &start_period, int &start_run)
get start period and run of the current parameter value
UniConnection * connectionDB
connection to the database
static int ReadObjectBinary(const char *detector_name, const char *parameter_name, int period_number, int run_number, TObject *&ptr_object)
read ROOT object as a binary parameter from from the Database for the selected run
Long_t sz_parameter_value
size of parameter value
int SetExpiryDate(TDatime *expiry_date)
set expiry date of the current detector parameter
TString GetParameterName()
get parameter name of the current parameter value
void GetEnd(int &end_period, int &end_run)
get end period and run of the current parameter value
UniValue * GetValue()
get value of detector parameter presented by a single value
int SetEnd(int end_period, int end_run)
set end period and run of the current parameter value
static int DeleteDetectorParameter(int value_id)
delete detector parameter from the database
unsigned char * blob_parameter_value
parameter value
int SetParameterId(int parameter_id)
set parameter id of the current detector parameter
static TObjArray * Search(UniSearchCondition &search_condition)
get parameters' values corresponding to the specified single condition and set owner for search_condi...
int GetValue(vector< UniValue * > &parameter_value)
get value of detector parameter presented by an array
int SetEndPeriod(int end_period)
set end period of the current detector parameter
static int WriteFile(const char *detector_name, const char *parameter_name, int start_period, int start_run, int end_period, int end_run, const char *file_path)
write a whole file with parameter value (with given detector and parameter names) to the Database fro...
TString str_detector_name
detector name
int SetEndRun(int end_run)
set end run of the current detector parameter
int SetStartRun(int start_run)
set start run of the current detector parameter
void Print()
print information about current detector parameter
int SetUNC(unsigned char *p_parameter_value, Long_t size_parameter_value)
int i_parameter_id
parameter id
static int PrintAll()
print all detector parameters
UniDetectorParameter(UniConnection *db_connect, int value_id, TString detector_name, int parameter_id, int start_period, int start_run, int end_period, int end_run, int value_key, unsigned char *parameter_value, Long_t size_parameter_value, TDatime *expiry_date)
int SetStartPeriod(int start_period)
set start period of the current detector parameter
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
static int CheckDetectorParameterExists(int value_id)
check detector parameter exists in the database: 1- true, 0 - false, <0 - database operation error
static int ReadFile(const char *detector_name, const char *parameter_name, int period_number, int run_number, const char *file_path)
read a whole file with parameter value (with given detector and parameter names) from the Database fo...
TDatime * ts_expiry_date
expiry date
static UniDetectorParameter * CreateDetectorParameter(TString detector_name, int parameter_id, int start_period, int start_run, int end_period, int end_run, int value_key, unsigned char *parameter_value, Long_t size_parameter_value, TDatime *expiry_date)
add new detector parameter to the database
int SetParameterValue(unsigned char *parameter_value, Long_t size_parameter_value)
set parameter value of the current detector parameter
unsigned char * GetUNC(enumValueType enum_parameter_type=UndefinedType)
Parse detector parameter's values and write them to the database: txtFile - path to the text file wit...
int i_start_period
start period
static int ReadObjectJSON(const char *detector_name, const char *parameter_name, int period_number, int run_number, TObject *&ptr_object)
read ROOT object as a JSON parameter from from the Database for the selected run
TString GetParameterName()
get parameter name of the current parameter
static bool CheckAndGetParameterID(TSQLServer *db_server, TString parameter_name, enumValueType enum_parameter_type, int &parameter_id)
static UniParameter * GetParameter(int parameter_id)
get parameter from the database
int GetParameterType()
get parameter type of the current parameter
static int GetFirstRunNumber(int period_number)
get first run number for a selected period
static int GetLastRunNumber(int period_number)
get last run number for a selected period
enumConditions GetCondition()
unsigned int GetUIntValue()
unsigned char * value
virtual enumValueType GetType()=0
virtual void ReadValue(unsigned char *source)=0
virtual void WriteValue(unsigned char *destination)=0
virtual size_t GetStorageSize()=0
enumValueType
@ UndefinedType
UniValue * CreateParameterValue(enumValueType parameter_type)