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