7#include "TSQLStatement.h"
20UniDetectorParameter::UniDetectorParameter(
UniConnection* db_connect,
22 TString detector_name,
29 unsigned char* parameter_value,
30 Long_t size_parameter_value,
33 connectionDB = db_connect;
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;
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;
53 if (blob_parameter_value)
54 delete[] blob_parameter_value;
56 delete ts_expiry_date;
67 unsigned char* parameter_value,
68 Long_t size_parameter_value,
72 if (connDb ==
nullptr)
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);
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)
94 stmt->SetDatime(8, *expiry_date);
97 if (!stmt->Process()) {
98 cout <<
"ERROR: inserting new detector parameter to the Database has been failed" << endl;
108 TSQLStatement* stmt_last =
109 db_server->Statement(
"SELECT currval(pg_get_serial_sequence('detector_parameter','value_id'))");
112 if (stmt_last->Process()) {
114 stmt_last->StoreResult();
117 if (!stmt_last->NextResultRow()) {
118 cout <<
"ERROR: no last ID in DB!" << endl;
122 value_id = stmt_last->GetInt(0);
126 cout <<
"ERROR: getting last ID has been failed!" << endl;
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;
140 tmp_start_run = start_run;
142 tmp_end_period = end_period;
144 tmp_end_run = end_run;
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;
155 tmp_expiry_date =
new TDatime(*expiry_date);
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);
166 if (connDb ==
nullptr)
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",
176 TSQLStatement* stmt = db_server->Statement(sql);
179 if (!stmt->Process()) {
180 cout <<
"ERROR: getting detector parameter from the database has been failed" << endl;
191 if (!stmt->NextResultRow()) {
192 cout <<
"ERROR: detector parameter was not found in the database" << endl;
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);
208 tmp_start_run = stmt->GetInt(4);
210 tmp_end_period = stmt->GetInt(5);
212 tmp_end_run = stmt->GetInt(6);
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;
221 tmp_expiry_date =
nullptr;
223 tmp_expiry_date =
new TDatime(stmt->GetDatime(9));
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);
236 if (connDb ==
nullptr)
241 TString sql = TString::Format(
"select 1 "
242 "from detector_parameter "
243 "where value_id = %d",
245 TSQLStatement* stmt = db_server->Statement(sql);
248 if (!stmt->Process()) {
249 cout <<
"ERROR: getting detector parameter from the database has been failed" << endl;
260 if (!stmt->NextResultRow()) {
276 if (connDb ==
nullptr)
281 TString sql = TString::Format(
"delete from detector_parameter "
282 "where value_id = $1");
283 TSQLStatement* stmt = db_server->Statement(sql);
285 stmt->NextIteration();
286 stmt->SetInt(0, value_id);
289 if (!stmt->Process()) {
290 cout <<
"ERROR: deleting detector parameter from the dataBase has been failed" << endl;
306 if (connDb ==
nullptr)
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);
317 if (!stmt->Process()) {
318 cout <<
"ERROR: getting all 'detector parameters' from the dataBase has been failed" << endl;
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: ";
356 cout << stmt->GetDatime(9).AsSQLString();
370 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
381 stmt->NextIteration();
382 stmt->SetString(0, detector_name);
383 stmt->SetInt(1, i_value_id);
386 if (!stmt->Process()) {
387 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
393 str_detector_name = detector_name;
402 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
413 stmt->NextIteration();
414 stmt->SetInt(0, parameter_id);
415 stmt->SetInt(1, i_value_id);
418 if (!stmt->Process()) {
419 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
425 i_parameter_id = parameter_id;
434 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
445 stmt->NextIteration();
446 stmt->SetInt(0, start_period);
447 stmt->SetInt(1, i_value_id);
450 if (!stmt->Process()) {
451 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
457 i_start_period = start_period;
466 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
477 stmt->NextIteration();
478 stmt->SetInt(0, start_run);
479 stmt->SetInt(1, i_value_id);
482 if (!stmt->Process()) {
483 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
489 i_start_run = start_run;
498 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
509 stmt->NextIteration();
510 stmt->SetInt(0, end_period);
511 stmt->SetInt(1, i_value_id);
514 if (!stmt->Process()) {
515 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
521 i_end_period = end_period;
530 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
536 TString sql = TString::Format(
"update detector_parameter "
538 "where value_id = $2");
539 TSQLStatement* stmt = db_server->Statement(sql);
541 stmt->NextIteration();
542 stmt->SetInt(0, end_run);
543 stmt->SetInt(1, i_value_id);
546 if (!stmt->Process()) {
547 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
562 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
573 stmt->NextIteration();
574 stmt->SetInt(0, value_key);
575 stmt->SetInt(1, i_value_id);
578 if (!stmt->Process()) {
579 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
585 i_value_key = value_key;
594 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
605 stmt->NextIteration();
606 stmt->SetBinary(0, parameter_value, size_parameter_value, 0x4000000);
607 stmt->SetInt(1, i_value_id);
610 if (!stmt->Process()) {
611 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
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);
630 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
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);
641 stmt->NextIteration();
642 if (expiry_date ==
nullptr)
645 stmt->SetDatime(0, *expiry_date);
646 stmt->SetInt(1, i_value_id);
649 if (!stmt->Process()) {
650 cout <<
"ERROR: updating information about detector parameter has been failed" << endl;
657 delete ts_expiry_date;
658 if (expiry_date ==
nullptr)
659 ts_expiry_date =
nullptr;
661 ts_expiry_date =
new TDatime(*expiry_date);
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;
685 if (enum_parameter_type > -1) {
687 cout <<
"CRITICAL ERROR: Connection object is null" << endl;
694 TString sql = TString::Format(
"select parameter_name, parameter_type "
696 "where parameter_id = %d",
698 TSQLStatement* stmt = db_server->Statement(sql);
701 if (!stmt->Process()) {
702 cout <<
"CRITICAL ERROR: getting record with parameter from 'parameter_' table has been failed" << endl;
710 if (!stmt->NextResultRow()) {
711 cout <<
"CRITICAL ERROR: the parameter with id '" << i_parameter_id <<
"' was not found" << endl;
716 TString parameter_name = stmt->GetString(0);
717 int parameter_type = stmt->GetInt(1);
720 if (parameter_type != enum_parameter_type) {
721 cout <<
"CRITICAL ERROR: the parameter with name '" << parameter_name
722 <<
"' is not corresponding the given type: "
724 << parameter_type <<
", but user type - " << enum_parameter_type << endl;
729 return blob_parameter_value;
736 cout <<
"Connection object is null" << endl;
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");
747 TSQLStatement* stmt = db_server->Statement(sql);
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);
760 if (!stmt->Process()) {
761 cout <<
"ERROR: updating the detector parameter has been failed" << endl;
766 if (blob_parameter_value)
767 delete[] blob_parameter_value;
768 blob_parameter_value = p_parameter_value;
769 sz_parameter_value = size_parameter_value;
777 TString parameter_name,
782 unsigned char* p_parameter_value,
783 Long_t size_parameter_value,
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))))
790 cout <<
"ERROR: end run should be after or the same as start run" << endl;
795 if (connDb ==
nullptr)
800 int parameter_id = -1;
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);
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);
827 if (!stmt->Process()) {
828 cout <<
"ERROR: inserting new parameter value to the database has been failed" << endl;
839 TSQLStatement* stmt_last =
840 db_server->Statement(
"SELECT currval(pg_get_serial_sequence('detector_parameter','value_id'))");
842 if (stmt_last->Process()) {
844 stmt_last->StoreResult();
847 if (!stmt_last->NextResultRow()) {
848 cout <<
"ERROR: no last ID in the Database for the parameter value has been found!" << endl;
852 last_id = stmt_last->GetInt(0);
856 cout <<
"ERROR: getting last ID for new parameter value has been failed!" << endl;
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);
869 TString parameter_name,
874 vector<UniValue*> parameter_value,
877 if (parameter_value.size() < 1) {
878 cout <<
"ERROR: The length of the parameter array should be greater zero" << endl;
881 enumValueType parameter_type = parameter_value[0]->GetType();
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;
890 size_parameter_value += parameter_value[
i]->GetStorageSize();
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();
904 start_run = first_run;
907 end_period = start_period;
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;
920 return pDetectorParameter;
925 TString parameter_name,
933 if (parameter_value ==
nullptr) {
934 cout <<
"ERROR: the parameter value must not be nullptr" << endl;
941 unsigned char* p_parameter_value =
new unsigned char[size_parameter_value];
942 parameter_value->
WriteValue(p_parameter_value);
947 start_run = first_run;
950 end_period = start_period;
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;
963 return pDetectorParameter;
968 TString parameter_name,
975 if (connDb ==
nullptr)
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());
993 sql +=
" and expiry_date is null";
994 TSQLStatement* stmt = db_server->Statement(sql);
997 if (!stmt->Process()) {
998 cout <<
"ERROR: getting record from the Database has been failed" << endl;
1005 stmt->StoreResult();
1008 if (!stmt->NextResultRow()) {
1009 cout <<
"ERROR: parameter value was not found in the Condition Database" << endl;
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);
1024 tmp_start_run = stmt->GetInt(4);
1026 tmp_end_period = stmt->GetInt(5);
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;
1036 tmp_expiry_date =
new TDatime(stmt->GetDatime(8));
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);
1047 TString parameter_name,
1052 TDatime* usage_time,
1056 if (connDb ==
nullptr)
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";
1068 sql +=
" and expiry_date >= $8 and expiry_date < $9";
1069 TSQLStatement* stmt = db_server->Statement(sql);
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);
1086 if (!stmt->Process()) {
1087 cout <<
"ERROR: deleting parameter value from the Database has been failed" << endl;
1094 if (stmt->GetNumAffectedRows() == 0) {
1095 cout <<
"WARNING: parameter value was not found in the Condition Database for deletion" << endl;
1109 unsigned char* p_parameter_value =
GetUNC();
1110 if (p_parameter_value ==
nullptr)
1113 Long_t full_size = sz_parameter_value;
1114 while (full_size > 0) {
1117 pParameterValue->
ReadValue(p_parameter_value);
1120 parameter_value.push_back(pParameterValue);
1129 unsigned char* p_parameter_value =
GetUNC();
1130 if (p_parameter_value ==
nullptr)
1134 parameter_value->
ReadValue(p_parameter_value);
1136 return parameter_value;
1142 if (parameter_value.size() < 1) {
1143 cout <<
"ERROR: The length of the parameter array should be greater zero" << endl;
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];
1154 unsigned char* tmp_pointer = p_parameter_value;
1155 for (
size_t i = 0;
i < parameter_value.size();
i++) {
1157 tmp_pointer += parameter_value[
i]->GetStorageSize();
1160 int res_code =
SetUNC(p_parameter_value, size_parameter_value);
1161 if (res_code != 0) {
1162 delete[] p_parameter_value;
1172 if (parameter_value ==
nullptr) {
1173 cout <<
"ERROR: the parameter value must not be nullptr" << endl;
1179 unsigned char* p_parameter_value =
new unsigned char[size_parameter_value];
1180 parameter_value->
WriteValue(p_parameter_value);
1182 int res_code =
SetUNC(p_parameter_value, size_parameter_value);
1183 if (res_code != 0) {
1184 delete[] p_parameter_value;
1194 const char* parameter_name,
1199 const char* file_path)
1201 TString strFilePath(file_path);
1202 gSystem->ExpandPathName(strFilePath);
1204 FILE* cur_file = fopen(strFilePath.Data(),
"rb");
1205 if (cur_file ==
nullptr) {
1206 cout <<
"ERROR: opening file: " << strFilePath <<
" was failed" << endl;
1210 fseek(cur_file, 0, SEEK_END);
1214 cout <<
"ERROR: getting file size: " << strFilePath <<
" was failed" << endl;
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;
1226 size_t bytes_read = fread(buffer, 1,
file_size, cur_file);
1228 cout <<
"ERROR: reading file: " << strFilePath <<
", got " << bytes_read <<
" bytes of " <<
file_size << endl;
1239 pValue->
value = buffer;
1241 detector_name, parameter_name, start_period, start_run, end_period, end_run, pValue);
1242 if (pParameterValue ==
nullptr) {
1249 delete pParameterValue;
1257 const char* parameter_name,
1260 const char* file_path)
1264 if (pDetectorParameter ==
nullptr)
1268 FILE* cur_file = fopen(file_path,
"wb");
1269 if (cur_file ==
nullptr) {
1270 cout <<
"ERROR: creating file: " << file_path <<
" has been failed!" << endl;
1272 delete pDetectorParameter;
1276 unsigned char* buffer = pValue->
value;
1277 if (buffer ==
nullptr) {
1278 cout <<
"ERROR: getting binary parameter array" << endl;
1280 delete pDetectorParameter;
1284 size_t parameter_size = pValue->
size;
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
1305 TObjArray* arrayResult =
nullptr;
1306 search_conditions.SetOwner(kTRUE);
1309 if (connDb ==
nullptr) {
1310 cout <<
"ERROR: the connection to the Unified Condition Database was failed" << endl;
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");
1320 TString strCondition;
1321 bool isFirst =
true;
1322 TIter next(&search_conditions);
1329 strCondition +=
"lower(detector_name) ";
1332 strCondition +=
"lower(parameter_name) ";
1335 strCondition +=
"start_period ";
1338 strCondition +=
"start_run ";
1341 strCondition +=
"end_period ";
1344 strCondition +=
"end_run ";
1347 cout <<
"ERROR: the column in the search condition was not defined, the condition is skipped" << endl;
1353 strCondition +=
"< ";
1356 strCondition +=
"<= ";
1359 strCondition +=
"= ";
1362 strCondition +=
"<> ";
1365 strCondition +=
"> ";
1368 strCondition +=
">= ";
1371 strCondition +=
"like ";
1374 strCondition +=
"is null ";
1377 strCondition +=
"is not null ";
1380 cout <<
"ERROR: the comparison operator in the search condition was not defined, the condition is "
1393 strCondition += Form(
"%d", curCondition->
GetIntValue());
1396 strCondition += Form(
"%u", curCondition->
GetUIntValue());
1402 strCondition += Form(
"lower('%s')", curCondition->
GetStringValue().Data());
1405 strCondition += Form(
"'%s'", curCondition->
GetDatimeValue().AsSQLString());
1408 cout <<
"ERROR: the value type in the search condition was not found, the condition is skipped" << endl;
1418 sql += strCondition;
1421 TSQLStatement* stmt = db_server->Statement(sql);
1424 if (!stmt->Process()) {
1425 cout <<
"ERROR: getting runs from the Unified Condition Database has been failed" << endl;
1433 stmt->StoreResult();
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;
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);
1454 tmp_start_run = stmt->GetInt(4);
1456 tmp_end_period = stmt->GetInt(5);
1458 tmp_end_run = stmt->GetInt(6);
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;
1469 tmp_expiry_date =
new TDatime(stmt->GetDatime(9));
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));
1478 arrayResult->SetOwner(kTRUE);
1484 TObjArray search_conditions;
1485 search_conditions.Add((TObject*)&search_condition);
1487 return Search(search_conditions);
1494 if (pCurParameter ==
nullptr) {
1495 cout <<
"ERROR: parameter with current ID was not found" << endl;
1501 delete pCurParameter;
1509 if (pCurParameter ==
nullptr) {
1510 cout <<
"ERROR: parameter with current ID was not found" << endl;
1516 delete pCurParameter;
1523 start_period = i_start_period;
1524 start_run = i_start_run;
1532 end_period = i_end_period;
1533 end_run = i_end_run;
1541 if (!connectionDB) {
1542 cout <<
"ERROR: Connection object is null" << endl;
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);
1553 stmt->NextIteration();
1554 stmt->SetInt(0, start_period);
1555 stmt->SetInt(1, start_run);
1556 stmt->SetInt(2, i_value_id);
1559 if (!stmt->Process()) {
1560 cout <<
"ERROR: updating the record has been failed" << endl;
1566 i_start_period = start_period;
1567 i_start_run = start_run;
1576 if (!connectionDB) {
1577 cout <<
"ERROR: Connection object is null" << endl;
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);
1588 stmt->NextIteration();
1589 stmt->SetInt(0, end_period);
1590 stmt->SetInt(1, end_run);
1591 stmt->SetInt(2, i_value_id);
1594 if (!stmt->Process()) {
1595 cout <<
"ERROR: updating the record has been failed" << endl;
1601 i_end_period = end_period;
1602 i_end_run = end_run;
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)
1614 txtFile.open(text_file, ios::in);
1615 if (!txtFile.is_open())
1617 cout<<"Error: opening TXT file '"<<text_file<<"' was failed"<<endl;
1621 // open connection to database
1622 UniConnection* connDb = UniConnection::Open();
1623 if (connDb == nullptr)
1626 TSQLServer* db_server = connDb->GetSQLServer();
1629 while (getline(txtFile, cur_line))
1631 //remove duplicates of whitespaces and tabs
1632 TString reduce_line = reduce(cur_line);
1634 if (reduce_line[0] == '#')
1638 //ss.str(reduce_line);
1640 // get detector object from 'detector_' table
1641 TString sql = TString::Format(
1642 "select detector_name "
1644 "where lower(detector_name) = lower('%s'')", detector_name.Data());
1645 TSQLStatement* stmt = db_server->Statement(sql);
1647 // get table record from DB
1648 if (!stmt->Process())
1650 cout<<"Error: getting record with detector from 'detector_' table has been failed"<<endl;
1654 stmt->StoreResult();
1656 // check detector with the given name is exist
1657 if (!stmt->NextResultRow())
1659 cout<<"Error: the detector with name '"<<detector_name<<"' was not found"<<endl;
1664 detector_name = stmt->GetString(0);
1668 // get parameter object from 'parameter_' table
1669 sql = TString::Format(
1670 "select parameter_id, parameter_name, parameter_type "
1672 "where lower(parameter_name) = lower('%s')", parameter_name.Data());
1673 stmt = db_server->Statement(sql);
1675 // get table record from DB
1676 if (!stmt->Process())
1678 cout<<"Error: getting record with parameter from 'parameter_' table has been failed"<<endl;
1683 stmt->StoreResult();
1685 // extract row with parameter
1686 if (!stmt->NextResultRow())
1688 cout<<"Error: the parameter with name '"<<parameter_name<<"' was not found"<<endl;
1693 //int parameter_id = stmt->GetInt(0);
1694 parameter_name = stmt->GetString(1);
1695 int parameter_type = stmt->GetInt(2);
1699 TObjArray* tokens = reduce_line.Tokenize("\t ");
1701 int value_count = tokens->GetEntriesFast();
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)
1710 int count_required = 1;
1711 if (isSerialChannel) count_required++, count_required++;
1713 if (value_count != count_required)
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;
1718 if (isSerialChannel)
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();
1727 item = (TObjString*) tokens->At(cur_num_item++);
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);
1741 int count_required = 1;
1742 if (isSerialChannel) count_required++, count_required++;
1744 if (value_count != count_required)
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;
1749 if (isSerialChannel)
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();
1758 item = (TObjString*) tokens->At(cur_num_item++);
1761 int value = item->GetString().Atoi();
1764 if (!item->GetString().IsDigit())
1766 cout<<"Error: the parameter value is not integer: '"<<item<<"'"<<endl;
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);
1781 int count_required = 1;
1782 if (isSerialChannel) count_required++, count_required++;
1784 if (value_count != count_required)
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;
1789 if (isSerialChannel)
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();
1798 item = (TObjString*) tokens->At(cur_num_item++);
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);
1812 int count_required = 2, size_arr = value_count/2;
1813 if (isSerialChannel)
1815 count_required++, count_required++;
1819 if ((value_count < count_required) || ((value_count % 2) != 0))
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;
1824 if (isSerialChannel)
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();
1834 int iter = 0, num = count_required-2;
1835 IIStructure* pValues = new IIStructure[size_arr];
1836 for (; iter < size_arr; iter++)
1838 pValues[iter].int_1 = ((TObjString*) tokens->At(num++))->GetString().Atoi();
1839 pValues[iter].int_2 = ((TObjString*) tokens->At(num++))->GetString().Atoi();
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);
1854 int count_required = 1, size_arr = value_count;
1855 if (isSerialChannel)
1857 count_required++, count_required++;
1858 size_arr--, size_arr--;
1861 if (value_count < count_required)
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;
1866 if (isSerialChannel)
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();
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();
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);
1891 case DoubleArrayType:
1893 int count_required = 1, size_arr = value_count;
1894 if (isSerialChannel)
1896 count_required++, count_required++;
1897 size_arr--, size_arr--;
1900 if (value_count < count_required)
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;
1905 if (isSerialChannel)
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();
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();
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);
1932 int count_required = 1, size_arr = value_count;
1933 if (isSerialChannel)
1935 count_required++, count_required++;
1936 size_arr--, size_arr--;
1939 if (value_count < count_required)
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;
1944 if (isSerialChannel)
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();
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();
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);
1969 case DchMapArrayType:
1971 int count_required = 6, size_arr = value_count/6;
1972 if (isSerialChannel)
1973 count_required++, count_required++;
1975 if ((value_count < count_required) || (((value_count-count_required+6) % 6) != 0))
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;
1980 if (isSerialChannel)
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();
1990 int iter = 0, num = count_required-6;
1991 DchMapStructure* pValues = new DchMapStructure[size_arr];
1992 for (; iter < size_arr; iter++)
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();
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);
2012 case GemMapArrayType:
2014 int count_required = 6, size_arr = value_count/6;
2015 if (isSerialChannel)
2016 count_required++, count_required++;
2018 if ((value_count < count_required) || (((value_count-count_required+6) % 6) != 0))
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;
2023 if (isSerialChannel)
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();
2033 int iter = 0, num = count_required-6;
2034 GemMapStructure* pValues = new GemMapStructure[size_arr];
2035 for (; iter < size_arr; iter++)
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();
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);
2055 case GemPedestalArrayType:
2057 int count_required = 4, size_arr = value_count/4;
2058 if (isSerialChannel)
2059 count_required++, count_required++;
2061 if ((value_count < count_required) || (((value_count-count_required+4) % 4) != 0))
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;
2066 if (isSerialChannel)
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();
2076 int iter = 0, num = count_required-4;
2077 GemPedestalStructure* pValues = new GemPedestalStructure[size_arr];
2078 for (; iter < size_arr; iter++)
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();
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);
2096 case TriggerMapArrayType:
2098 int count_required = 3, size_arr = value_count/3;
2099 if (isSerialChannel)
2100 count_required++, count_required++;
2102 if ((value_count < count_required) || (((value_count-count_required+3) % 3) != 0))
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;
2107 if (isSerialChannel)
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();
2117 int iter = 0, num = count_required-3;
2118 TriggerMapStructure* pValues = new TriggerMapStructure[size_arr];
2119 for (; iter < size_arr; iter++)
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();
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);
2138 cout<<"Error: the type of parameter ("<<parameter_name<<") is not supported for parsing (txt)
2139now"<<endl; continue;
2141 }// switch (parameter_type)
2144 if (pDetectorParameter)
2145 delete pDetectorParameter;
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 * > ¶meter_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)
virtual ~UniDetectorParameter()
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 ¶meter_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()
@ conditionGreaterOrEqual
unsigned int GetUIntValue()
UniValue * CreateParameterValue(enumValueType parameter_type)
virtual enumValueType GetType()=0
virtual void ReadValue(unsigned char *source)=0
virtual void WriteValue(unsigned char *destination)=0
virtual size_t GetStorageSize()=0