32 vector<structParseSchema>& vecElements,
41 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"skip") != 0)
42 skip_count = atoi((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"skip"));
46 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"delimiter") != 0) {
47 string delimiter_string = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"delimiter");
48 if (delimiter_string[0] ==
'\\') {
49 switch (delimiter_string[1]) {
51 delimiter_char =
'\t';
56 delimiter_char = delimiter_string[0];
61 for (xmlNodePtr cycle_child = cur_schema_node->children; cycle_child; cycle_child = cycle_child->next) {
62 TString strAction = (
char*)xmlGetProp(cycle_child, (
unsigned char*)
"action");
63 TString column_name = (
char*)xmlGetProp(cycle_child, (
unsigned char*)
"column_name");
64 TString statement_type = (
char*)xmlGetProp(cycle_child, (
unsigned char*)
"type");
68 if (strAction ==
"skip") {
71 vecElements.push_back(par);
72 }
else if (strAction ==
"update") {
76 vecElements.push_back(par);
79 else if (strAction ==
"write")
83 vecElements.push_back(par);
86 else if (strAction ==
"parse")
92 if ((
char*)xmlGetProp(cycle_child, (
unsigned char*)
"start_index") != 0)
93 start_index = atoi((
char*)xmlGetProp(cycle_child, (
unsigned char*)
"start_index"));
94 TString parse_type = (
char*)xmlGetProp(cycle_child, (
unsigned char*)
"parse_type");
95 TString delimiter = (
char*)xmlGetProp(cycle_child, (
unsigned char*)
"delimiter");
96 structParseRow row(column_name, statement_type,
true, start_index, parse_type, delimiter);
99 vecElements.push_back(par);
102 else if (strAction ==
"multi")
107 for (xmlNodePtr cycle_sub_child = cycle_child->children; cycle_sub_child;
108 cycle_sub_child = cycle_sub_child->next)
110 strAction = (
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"action");
111 column_name = (
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"column_name");
112 statement_type = (
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"type");
114 if (strAction ==
"write") {
117 }
else if (strAction ==
"parse") {
119 if ((
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"start_index") != 0)
120 start_index = atoi((
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"start_index"));
121 TString parse_type = (
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"parse_type");
122 TString delimiter = (
char*)xmlGetProp(cycle_sub_child, (
unsigned char*)
"delimiter");
123 structParseRow row(column_name, statement_type,
true, start_index, parse_type, delimiter);
128 vecElements.push_back(par);
220 for (
size_t i = 0;
i < schema.
vecRows.size();
i++) {
221 token = write_string;
224 unsigned char* pArray =
nullptr;
225 Long_t size_array = -1;
238 for (last_digit = 0; last_digit < token.length(); last_digit++) {
239 if (!isdigit(token[last_digit]))
245 token = token.substr(0, last_digit - 1);
251 istringstream token_stream(token);
254 while (getline(token_stream, subtoken, row.
strDelimiter[0])) {
255 int cur_int = atoi(subtoken.c_str());
256 vecInt.push_back(cur_int);
259 int size_int = vecInt.size();
260 int* pIntArray =
new int[size_int];
261 for (
int j = 0; j < size_int; j++)
262 pIntArray[j] = vecInt[j];
263 size_array = size_int *
sizeof(int);
265 pArray =
new unsigned char[size_array];
266 memcpy(pArray, pIntArray, size_array);
273 istringstream token_stream(token);
275 vector<double> vecDouble;
276 while (getline(token_stream, subtoken, row.
strDelimiter[0])) {
277 double cur_double = atof(subtoken.c_str());
279 vecDouble.push_back(cur_double);
283 int size_double = vecDouble.size();
284 double* pDoubleArray =
new double[size_double];
285 for (
int j = 0; j < size_double; j++)
286 pDoubleArray[j] = vecDouble[j];
287 size_array = size_double *
sizeof(double);
289 pArray =
new unsigned char[size_array];
290 memcpy(pArray, pDoubleArray, size_array);
291 delete[] pDoubleArray;
298 stmt->SetInt(count, atoi(token.c_str()));
299 cout <<
"SetInt: " << token << endl;
305 cout <<
"SetHex: " << token << endl;
312 stmt->SetDouble(count, atof(token.c_str()));
313 cout <<
"SetDouble: " << token << endl;
317 stmt->SetString(count, token.c_str());
318 cout <<
"SetString: " << token << endl;
322 TDatime
d(token.c_str());
323 stmt->SetDatime(count,
d);
324 cout <<
"SetDatime: " << token << endl;
328 cout <<
"SetBinary: " << (
void*)pArray <<
" with size: " << size_array << endl;
329 stmt->SetLargeObject(count, (
void*)pArray, size_array);
380 xmlDocPtr docXML = xmlReadFile(xmlName,
nullptr, 0);
382 cout <<
"ERROR: reading XML file '" << xmlName <<
"' was failed" << endl;
387 xmlDocPtr docSchema = xmlReadFile(schemaPath,
nullptr, 0);
389 cout <<
"ERROR: reading schema file '" << schemaPath <<
"' was failed" << endl;
394 xmlNodePtr cur_xml_node = xmlDocGetRootElement(docXML);
395 xmlNodePtr cur_schema_node = xmlDocGetRootElement(docSchema);
396 if (!cur_schema_node) {
397 cout <<
"ERROR: schema of XML parsing is empty" << endl;
399 xmlFreeDoc(docSchema);
402 if (strcmp((
char*)cur_schema_node->name,
"uniparser") != 0) {
403 cout <<
"ERROR: it is not 'uniparser' scheme: " << (
char*)cur_schema_node->name << endl;
405 xmlFreeDoc(docSchema);
408 cur_schema_node = cur_schema_node->children;
412 if (connDb ==
nullptr) {
414 xmlFreeDoc(docSchema);
419 string strTableName =
"";
421 while (cur_schema_node) {
425 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name") != 0) {
426 strTableName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name");
427 cout <<
"Current database table: " << strTableName << endl;
430 if (strcmp((
char*)cur_schema_node->name,
"search") == 0) {
431 string strSearchName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"name");
433 cur_xml_node =
findNodeByName(cur_xml_node, strSearchName.c_str());
434 if (cur_xml_node ==
nullptr) {
435 cout <<
"ERROR: end of the XML document was reached while parsing (search for)" << endl;
438 xmlFreeDoc(docSchema);
442 cout <<
"Current node after search: " << (
char*)cur_xml_node->name << endl;
443 }
else if (strcmp((
char*)cur_schema_node->name,
"move") == 0) {
444 xmlAttr* attribute = cur_schema_node->properties;
445 while (attribute && attribute->name && attribute->children) {
446 if (strcmp((
char*)attribute->name,
"down") == 0) {
447 xmlChar* value = xmlNodeListGetString(cur_schema_node->doc, attribute->children, 1);
449 int count = atoi((
char*)value);
450 for (
int i = 0;
i < count;
i++) {
451 cur_xml_node = cur_xml_node->children;
452 if (cur_xml_node->type != XML_ELEMENT_NODE)
453 cur_xml_node = cur_xml_node->next;
455 if (cur_xml_node ==
nullptr) {
456 cout <<
"ERROR: end of the XML document was reached while parsing (move - down)" << endl;
460 xmlFreeDoc(docSchema);
468 attribute = attribute->next;
471 cout <<
"Current node after move: " << (
char*)cur_xml_node->name << endl;
474 else if (strcmp((
char*)cur_schema_node->name,
"cycle") == 0)
476 TString strChildName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"child");
479 int skip_count, column_count;
481 vector<structParseSchema> vecElements;
485 if (column_count == 0) {
486 cout <<
"ERROR: no columns were chosen for insert or update" << endl;
489 xmlFreeDoc(docSchema);
493 cout <<
"SQL code: " << sql << endl;
495 TSQLStatement* stmt = db_server->Statement(sql);
498 int cycle_counter = 0;
499 for (cur_xml_node = cur_xml_node->children; cur_xml_node; cur_xml_node = cur_xml_node->next) {
500 if (strcmp((
char*)cur_xml_node->name, strChildName.Data()))
503 if (skip_count > 0) {
508 stmt->NextIteration();
519 cout <<
"Cur node: " << cur_xml_node->name << endl;
520 for (xmlNodePtr cycle_child = cur_xml_node->children; cycle_child; cycle_child = cycle_child->next,
i++)
522 cout <<
"cycle_child node: " << cycle_child->name << endl;
527 TString xml_child_value = (
char*)cycle_child->children->content;
528 string token = xml_child_value.Data();
538 cur_schema_node = cur_schema_node->next;
543 xmlFreeDoc(docSchema);
551 csvFile.open(csvName, ios::in);
552 if (!csvFile.is_open()) {
553 cout <<
"ERROR: reading CSV file '" << csvName <<
"' was failed" << endl;
558 xmlDocPtr docSchema = xmlReadFile(schemaPath,
nullptr, 0);
560 cout <<
"ERROR: reading schema file '" << schemaPath <<
"' was failed" << endl;
564 xmlNodePtr cur_schema_node = xmlDocGetRootElement(docSchema);
565 if (!cur_schema_node) {
566 cout <<
"ERROR: schema of XML parsing is empty" << endl;
567 xmlFreeDoc(docSchema);
570 if (strcmp((
char*)cur_schema_node->name,
"uniparser") != 0) {
571 cout <<
"ERROR: it is not 'uniparser' scheme: " << (
char*)cur_schema_node->name << endl;
572 xmlFreeDoc(docSchema);
575 cur_schema_node = cur_schema_node->children;
579 if (connDb ==
nullptr)
584 string strTableName =
"", cur_line;
585 while (cur_schema_node) {
589 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name") != 0) {
590 strTableName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name");
591 cout <<
"Current database table: " << strTableName << endl;
594 if (strcmp((
char*)cur_schema_node->name,
"search") == 0) {
595 string strSearchName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"name");
598 else if (strcmp((
char*)cur_schema_node->name,
"cycle") == 0)
600 int skip_count, column_count;
602 vector<structParseSchema> vecElements;
609 cout <<
"SQL code: " << sql << endl;
611 for (
int i = 0;
i < skip_count;
i++)
612 getline(csvFile, cur_line);
614 TSQLStatement* stmt = db_server->Statement(sql);
617 int cycle_counter = 0;
618 while (getline(csvFile, cur_line)) {
623 string trim_line =
trim(cur_line);
625 istringstream line_stream(trim_line);
627 stmt->NextIteration();
639 while (getline(line_stream, token,
';')) {
656 cur_schema_node = cur_schema_node->next;
661 xmlFreeDoc(docSchema);
669 txtFile.open(txtName, ios::in);
670 if (!txtFile.is_open()) {
671 cout <<
"ERROR: reading TXT file '" << txtName <<
"' was failed" << endl;
676 xmlDocPtr docSchema = xmlReadFile(schemaPath,
nullptr, 0);
678 cout <<
"ERROR: reading schema file '" << schemaPath <<
"' was failed" << endl;
682 xmlNodePtr cur_schema_node = xmlDocGetRootElement(docSchema);
683 if (!cur_schema_node) {
684 cout <<
"ERROR: schema of XML parsing is empty" << endl;
685 xmlFreeDoc(docSchema);
688 if (strcmp((
char*)cur_schema_node->name,
"uniparser") != 0) {
689 cout <<
"ERROR: it is not 'uniparser' scheme: " << (
char*)cur_schema_node->name << endl;
690 xmlFreeDoc(docSchema);
693 cur_schema_node = cur_schema_node->children;
697 if (connDb ==
nullptr)
703 string strTableName =
"", cur_line;
704 while (cur_schema_node) {
705 cout <<
"Current schema node: " << cur_schema_node->name << endl;
708 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name") != 0) {
709 strTableName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name");
710 cout <<
"Current database table: " << strTableName << endl;
713 if (strcmp((
char*)cur_schema_node->name,
"skip") == 0) {
714 int skip_line_count = 0;
715 string strLineCount = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"line_count");
716 if (strLineCount !=
"")
717 skip_line_count = atoi(strLineCount.c_str());
719 for (
int i = 0;
i < skip_line_count;
i++)
720 getline(txtFile, cur_line);
723 if (strcmp((
char*)cur_schema_node->name,
"search") == 0) {
724 string strSearchName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"name");
727 else if (strcmp((
char*)cur_schema_node->name,
"cycle") == 0)
729 int skip_count, column_count;
731 vector<structParseSchema> vecElements;
738 cout <<
"SQL code: " << sql << endl;
740 for (
int i = 0;
i < skip_count;
i++)
741 getline(txtFile, cur_line);
743 TSQLStatement* stmt = db_server->Statement(sql);
746 int cycle_counter = 0;
747 while (getline(txtFile, cur_line)) {
748 string trim_line =
trim(cur_line);
754 istringstream line_stream(cur_line);
756 stmt->NextIteration();
768 while (getline(line_stream, token, delimiter_char)) {
787 cur_schema_node = cur_schema_node->next;
792 xmlFreeDoc(docSchema);
800 txtFile.open(txtName, ios::in);
801 if (!txtFile.is_open()) {
802 cout <<
"ERROR: reading TXT file '" << txtName <<
"' was failed" << endl;
807 xmlDocPtr docSchema = xmlReadFile(schemaPath,
nullptr, 0);
809 cout <<
"ERROR: reading schema file '" << schemaPath <<
"' was failed" << endl;
813 xmlNodePtr cur_schema_node = xmlDocGetRootElement(docSchema);
814 if (!cur_schema_node) {
815 cout <<
"ERROR: schema of XML parsing is empty" << endl;
816 xmlFreeDoc(docSchema);
819 if (strcmp((
char*)cur_schema_node->name,
"UniParser_schema") != 0) {
820 cout <<
"ERROR: it is not a UniParser schema" << endl;
821 xmlFreeDoc(docSchema);
824 cur_schema_node = cur_schema_node->children;
828 if (connDb ==
nullptr)
832 string strTableName =
"";
833 int skip_line_count = 0;
834 while (cur_schema_node) {
836 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name") != 0) {
837 strTableName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name");
838 cout <<
"Current database table: " << strTableName << endl;
841 if (strcmp((
char*)cur_schema_node->name,
"skip") == 0) {
842 string strLineCount = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"line_count");
843 if (strLineCount !=
"")
844 skip_line_count = atoi(strLineCount.c_str());
847 cur_schema_node = cur_schema_node->next;
851 for (
int i = 0;
i < skip_line_count;
i++)
852 getline(txtFile, cur_line);
854 while (getline(txtFile, cur_line)) {
856 string reduce_line =
reduce(cur_line);
858 cout <<
"Current run and count line: " << reduce_line << endl;
859 int run_number = -1, row_count = -1;
860 istringstream line_stream(reduce_line);
864 while (getline(line_stream, token,
' ')) {
866 run_number = atoi(token.c_str());
868 row_count = atoi(token.c_str());
874 vector<UniValue*> arr;
875 for (
int i = 0;
i < row_count;
i++) {
876 getline(txtFile, cur_line);
877 cout <<
"Current run: " << run_number <<
", row: " <<
i <<
", line: " << cur_line << endl;
878 reduce_line =
reduce(cur_line);
880 line_stream.str(reduce_line);
884 while (getline(line_stream, token,
' ')) {
886 slot_number = atoi(token.c_str());
889 size_t index_sym = token.find_first_of(
'-');
890 if (index_sym == string::npos) {
891 int channel_number = atoi(token.c_str());
892 if (channel_number == 0) {
899 st->
value2 = channel_number;
902 string strFirst = token.substr(0, index_sym);
903 string strSecond = token.substr(index_sym + 1, token.length() - index_sym - 1);
904 int num_first = atoi(strFirst.c_str());
905 int num_second = atoi(strSecond.c_str());
906 for (
int j = num_first; j <= num_second; j++) {
920 if (getline(txtFile, cur_line)) {
921 reduce_line =
trim(cur_line,
" \t\r");
922 if (reduce_line !=
"") {
923 cout <<
"CRITICAL ERROR: file format is not correct, current line:" << reduce_line << endl;
941 "DCH1",
"noise", period_number, run_number, period_number, run_number,
943 if (pDetectorParameter ==
nullptr)
947 for (
size_t i = 0;
i < arr.size();
i++)
949 if (pDetectorParameter)
950 delete pDetectorParameter;
961 TSQLServer* source_db = TSQLServer::Connect(
"pgsql://nc13.jinr.ru/bmn_elog",
"login",
"password");
962 if (source_db ==
nullptr) {
963 cout <<
"ERROR: source database connection was not established (nc13.jinr.ru) for bmn_elog" << endl;
967 TString sql_source = TString::Format(
"select record_id, field_comment "
969 TSQLStatement* stmt_source = source_db->Statement(sql_source);
973 if (!stmt_source->Process()) {
974 cout <<
"ERROR: getting records from the database has been failed" << endl;
983 stmt_source->StoreResult();
985 TSQLServer* dest_db = TSQLServer::Connect(
"pgsql://nc13.jinr.ru/bmn_elog",
"login",
"password");
986 if (dest_db ==
nullptr) {
987 cout <<
"ERROR: destination database connection was not established (nc13.jinr.ru) for bmn_elog" << endl;
992 while (stmt_source->NextResultRow()) {
993 if (stmt_source->IsNull(1))
996 int record_id = stmt_source->GetInt(0);
997 TString field_comment = stmt_source->GetString(1);
1000 size_t beg_pos, end_pos;
1001 string field_lower(field_comment.Data()), sp57 =
"", vkm2 =
"";
1003 transform(field_lower.begin(), field_lower.end(), field_lower.begin(), ::tolower);
1005 size_t ind = field_lower.find(
"sp-57");
1006 if (ind != string::npos) {
1009 iField = atoi(sp57.c_str());
1011 if (field_lower[end_pos + 1] !=
'a') {
1012 cout <<
"ERROR: field is not ended with A" << field_lower << endl;
1016 TString sql_dest = TString::Format(
"update record_ "
1018 "where record_id = $2");
1019 TSQLStatement* stmt_dest = dest_db->Statement(sql_dest);
1021 stmt_dest->NextIteration();
1022 stmt_dest->SetInt(0, iField);
1023 stmt_dest->SetInt(1, record_id);
1026 if (!stmt_dest->Process()) {
1027 cout <<
"ERROR: updating information has been failed" << endl;
1038 ind = field_lower.find(
"vkm2", ind);
1039 if (ind != string::npos) {
1042 iField = atoi(vkm2.c_str());
1044 if (field_lower[end_pos + 1] !=
'a') {
1045 cout <<
"ERROR: field is not ended with A" << field_lower << endl;
1049 TString sql_dest = TString::Format(
"update record_ "
1051 "where record_id = $2");
1052 TSQLStatement* stmt_dest = dest_db->Statement(sql_dest);
1054 stmt_dest->NextIteration();
1055 stmt_dest->SetInt(0, iField);
1056 stmt_dest->SetInt(1, record_id);
1059 if (!stmt_dest->Process()) {
1060 cout <<
"ERROR: updating information has been failed" << endl;
1080 vector<structParseValue*>& parse_values,
1081 vector<structParseSchema>& vecElements,
1084 gSystem->ExpandPathName(txtName);
1085 gSystem->ExpandPathName(schemaPath);
1088 txtFile.open(txtName.Data(), ios::in);
1089 if (!txtFile.is_open()) {
1091 cout <<
"ERROR: reading TXT file '" << txtName <<
"' was failed" << endl;
1096 xmlDocPtr docSchema = xmlReadFile(schemaPath.Data(),
nullptr, 0);
1099 cout <<
"ERROR: reading schema file '" << schemaPath <<
"' was failed" << endl;
1103 xmlNodePtr cur_schema_node = xmlDocGetRootElement(docSchema);
1104 if (!cur_schema_node) {
1106 cout <<
"ERROR: schema of XML parsing is empty" << endl;
1107 xmlFreeDoc(docSchema);
1110 if (strcmp((
char*)cur_schema_node->name,
"uniparser") != 0) {
1112 cout <<
"ERROR: it is not 'uniparser' scheme: " << (
char*)cur_schema_node->name << endl;
1113 xmlFreeDoc(docSchema);
1116 cur_schema_node = cur_schema_node->children;
1119 string strTableName =
"", cur_line;
1120 TDatime dtSpillPrevious;
1121 while (cur_schema_node) {
1123 cout <<
"Current schema node: " << cur_schema_node->name << endl;
1126 if ((
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name") != 0) {
1127 strTableName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"table_name");
1129 cout <<
"Current database table: " << strTableName << endl;
1132 if (strcmp((
char*)cur_schema_node->name,
"skip") == 0) {
1133 int skip_line_count = 0;
1134 string strLineCount = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"line_count");
1135 if (strLineCount !=
"")
1136 skip_line_count = atoi(strLineCount.c_str());
1138 for (
int i = 0;
i < skip_line_count;
i++)
1139 getline(txtFile, cur_line);
1142 if (strcmp((
char*)cur_schema_node->name,
"search") == 0) {
1143 string strSearchName = (
char*)xmlGetProp(cur_schema_node, (
unsigned char*)
"name");
1146 else if (strcmp((
char*)cur_schema_node->name,
"cycle") == 0)
1148 int skip_count, column_count;
1149 char delimiter_char;
1153 for (
int i = 0;
i < skip_count;
i++)
1154 getline(txtFile, cur_line);
1157 int cycle_counter = 0;
1158 bool notFirstLine =
false, isSkipLines =
false;
1159 while (getline(txtFile, cur_line)) {
1161 string reduce_line =
reduce(cur_line);
1163 cout <<
"Current line: " << reduce_line << endl;
1165 if (reduce_line ==
"")
1169 istringstream line_stream(reduce_line);
1173 TString strDate =
"", strTime =
"", strSpillEnd =
"";
1177 while (getline(line_stream, token, delimiter_char)) {
1178 if (
i >= vecElements.size()) {
1180 cout <<
"WARNING: Some columns were not parsed (starting with " << token <<
")" << endl;
1187 cout <<
"schema.isSkip: " << schema.
isSkip << endl;
1192 cout <<
"The current type of the column '" << schema.
vecRows[0].strColumnName
1193 <<
"': " << schema.
vecRows[0].strStatementType << endl;
1195 if (schema.
vecRows[0].strStatementType ==
"datetime") {
1196 strDate = token.c_str();
1197 TPRegexp date_prefix(
"^[0-9][0-9]?[.][0-9][0-9]?[.][0-9][0-9][0-9]?[0-9]?");
1198 if (!strDate.Contains(date_prefix)) {
1199 TString strSQLDate = dtSpillPrevious.AsSQLString();
1200 strDate = TString::Format(
"%s.%s.%s", strSQLDate(8, 2).Data(), strSQLDate(5, 2).Data(),
1201 strSQLDate(0, 4).Data());
1203 cout <<
"WARNING: recovery date: " << strDate << endl;
1205 getline(line_stream, token, delimiter_char);
1207 strTime = token.c_str();
1208 TPRegexp time_prefix(
"^[0-9][0-9]?[:][0-9][0-9]?[:][0-9][0-9]?");
1209 if (!strTime.Contains(time_prefix)) {
1210 strTime =
"00:00:00";
1212 getline(line_stream, token, delimiter_char);
1215 schema = vecElements[
i];
1222 if (schema.
vecRows[0].strStatementType ==
"int") {
1223 st->
arrValues.push_back(atoi(token.c_str()));
1225 if (schema.
vecRows[0].strStatementType ==
"double") {
1226 st->
arrValues.push_back(atof(token.c_str()));
1229 cout <<
"ERROR: type of the column is not supported: "
1230 << schema.
vecRows[0].strStatementType << endl;
1238 strSpillEnd = TString::Format(
"%s %s", strDate.Data(), strTime.Data());
1239 tm tmbuf[1] = {{0}};
1240 strptime(strSpillEnd.Data(),
"%d.%m.%Y %H:%M:%S", tmbuf);
1241 TDatime dtSpillEnd(tmbuf->tm_year, tmbuf->tm_mon + 1, tmbuf->tm_mday, tmbuf->tm_hour, tmbuf->tm_min,
1244 if ((notFirstLine) && (dtSpillPrevious > dtSpillEnd)) {
1245 if ((!isSkipLines) && (iVerbose > 0))
1247 <<
"ERROR: The time sequence of the lines is corrupted. The following lines is skipped:"
1249 cout << reduce_line << endl;
1256 cout <<
"Skipped fragment is finished" << endl << endl;
1257 isSkipLines =
false;
1260 dtSpillPrevious = dtSpillEnd;
1261 notFirstLine =
true;
1266 parse_values.push_back(st);
1273 cur_schema_node = cur_schema_node->next;
1277 xmlFreeDoc(docSchema);
1323 csvFile.open(csvName, ios::in);
1324 if (!csvFile.is_open()) {
1325 cout <<
"ERROR: reading CSV file '" << csvName <<
"' was failed" << endl;
1330 if (connDb ==
nullptr)
1333 if (elog_server ==
nullptr) {
1334 cout <<
"ERROR: ELOG connection was not established" << endl;
1338 TSQLStatement* stmt =
nullptr;
1341 int skip_line = 1, updated_count = 0;
1343 while (getline(csvFile, cur_line)) {
1346 if (skip_line > 0) {
1352 string trim_line =
trim(cur_line);
1353 istringstream line_stream(trim_line);
1356 string token, record_id =
"", record_date =
"", author =
"", record_type =
"", subject =
"", run_number =
"",
1357 shift_leader =
"", trigger_info =
"", daq_status =
"", magnet_field =
"", beam =
"",
1358 record_comment =
"";
1359 int index = 0, iError = 0;
1360 while (getline(line_stream, token, separate_symbol)) {
1366 record_date = token;
1369 author =
trim(token,
"\"");
1372 record_type =
trim(token,
"\"");
1377 subject =
trim(token,
"\"");
1380 run_number =
trim(token,
"\"");
1383 shift_leader =
trim(token,
"\"");
1386 trigger_info =
trim(token,
"\"");
1389 daq_status =
trim(token,
"\"");
1392 magnet_field =
trim(token,
"\"");
1395 beam =
trim(token,
"\"");
1398 record_comment =
trim(token,
"\"");
1401 cout <<
"ERROR: more tokens separated by '" << separate_symbol <<
"' for record_id: " << record_id
1412 int iRecordId = -1, iAuthor = -1, iRecordType = -1, iRunNumber = -1, iLastRunNumber = -1, iShiftLeader = -1,
1416 cout <<
"ERROR: record id is not number: " << record_id << endl;
1419 iRecordId = atoi(record_id.c_str());
1420 if (iRecordId < 1) {
1421 cout <<
"ERROR: record id should be greater zero: " << iRecordId << endl;
1425 cout <<
"RECORD ID: " << iRecordId << endl;
1428 if (record_date ==
"") {
1429 cout <<
"ERROR: record date is empty: " << record_date << endl;
1435 TString strAuthorLower = author;
1436 strAuthorLower.ToLower();
1437 if ((strAuthorLower ==
"shift") || (strAuthorLower ==
"none"))
1440 TString sql_author = TString::Format(
"select person_id "
1442 "where position(lower(person_name) in lower('%s')) > 0",
1444 stmt = elog_server->Statement(sql_author);
1446 if (!stmt->Process()) {
1447 cout <<
"ERROR: getting author from the database has been failed: " << author << endl;
1453 stmt->StoreResult();
1456 if (!stmt->NextResultRow()) {
1457 cout <<
"ERROR: author was not found in the database: " << author << endl;
1462 iAuthor = stmt->GetInt(0);
1467 string subject_lower = subject, type_lower = record_type;
1468 transform(subject_lower.begin(), subject_lower.end(), subject_lower.begin(), ::tolower);
1469 transform(type_lower.begin(), type_lower.end(), type_lower.begin(), ::tolower);
1472 if (type_lower ==
"other") {
1473 ind = subject_lower.find(
"new run");
1474 if (ind != string::npos) {
1475 type_lower =
"new run";
1476 if (subject_lower.length() == 7)
1480 TString sql_type = TString::Format(
"select type_id "
1482 "where lower(type_text) = lower('%s')",
1483 type_lower.c_str());
1484 stmt = elog_server->Statement(sql_type);
1486 if (!stmt->Process()) {
1487 cout <<
"ERROR: getting type from the database has been failed: " << record_type << endl;
1493 stmt->StoreResult();
1496 if (!stmt->NextResultRow()) {
1497 cout <<
"ERROR: type was not found in the database: " << record_type << endl;
1502 iRecordType = stmt->GetInt(0);
1506 string strRunNumber = run_number, strLastRunNumber =
"";
1507 transform(strRunNumber.begin(), strRunNumber.end(), strRunNumber.begin(), ::tolower);
1508 if (strRunNumber ==
"none")
1511 if (strRunNumber !=
"") {
1512 if (strRunNumber.substr(0, 3) ==
"run")
1513 strRunNumber = strRunNumber.substr(3);
1514 ind = strRunNumber.find_first_of(
'-');
1515 if (ind != string::npos) {
1516 strLastRunNumber = strRunNumber.substr(ind + 1);
1518 cout <<
"ERROR: last run number is not number: " << run_number << endl;
1521 iLastRunNumber = atoi(strLastRunNumber.c_str());
1522 if (iLastRunNumber < 1) {
1523 cout <<
"ERROR: last run number should be greater than zero: " << iLastRunNumber << endl;
1526 strRunNumber = strRunNumber.substr(0, ind);
1530 cout <<
"ERROR: run number is not number: " << run_number << endl;
1533 iRunNumber = atoi(strRunNumber.c_str());
1534 if (iRunNumber < 1) {
1535 cout <<
"ERROR: run number should be greater than zero: " << iRunNumber << endl;
1539 if ((iLastRunNumber > 0) && (iLastRunNumber <= iRunNumber)) {
1540 cout <<
"ERROR: last run number (" << iLastRunNumber <<
") should be greater than first run number ("
1541 << iRunNumber <<
")." << endl;
1547 TString strLeaderLower = shift_leader;
1548 strLeaderLower.ToLower();
1549 if ((strLeaderLower ==
"shift") || (strLeaderLower ==
"none"))
1551 if (shift_leader !=
"") {
1552 TString sql_leader = TString::Format(
"select person_id "
1554 "where position(lower(person_name) in lower('%s')) > 0",
1555 shift_leader.c_str());
1556 stmt = elog_server->Statement(sql_leader);
1558 if (!stmt->Process()) {
1559 cout <<
"ERROR: getting shift leader from the database has been failed: " << shift_leader << endl;
1565 stmt->StoreResult();
1568 if (!stmt->NextResultRow()) {
1569 cout <<
"ERROR: shift leader was not found in the database: " << shift_leader << endl;
1574 iShiftLeader = stmt->GetInt(0);
1579 TString strTriggerLower = trigger_info;
1580 strTriggerLower.ToLower();
1581 if (strTriggerLower ==
"none")
1583 if (trigger_info !=
"") {
1584 TString sql_trigger = TString::Format(
"select trigger_id "
1586 "where lower(trigger_info) = lower('%s')",
1587 trigger_info.c_str());
1588 stmt = elog_server->Statement(sql_trigger);
1590 if (!stmt->Process()) {
1591 cout <<
"ERROR: getting trigger from the database has been failed: " << trigger_info << endl;
1597 stmt->StoreResult();
1600 if (!stmt->NextResultRow()) {
1601 cout <<
"ERROR: trigger was not found in the database: " << trigger_info << endl;
1606 iTriggerInfo = stmt->GetInt(0);
1612 size_t beg_pos, end_pos;
1613 string field_lower = magnet_field, sp41 =
"", sp57 =
"", vkm2 =
"", field_mv =
"";
1614 int iSP41 = -1, iVKM2 = -1;
1615 double dVoltage = -1;
1616 transform(field_lower.begin(), field_lower.end(), field_lower.begin(), ::tolower);
1620 ind = field_lower.find(
"sp-41");
1621 if (ind != string::npos) {
1629 iSP41 = atoi(sp41.c_str());
1631 cout <<
"ERROR: SP-41 field can't be negative: " << iSP41 << endl;
1636 ind = field_lower.find(
"vkm2");
1637 if (ind != string::npos) {
1642 iVKM2 = atoi(vkm2.c_str());
1644 cout <<
"ERROR: VKM2 field can't be negative: " << iVKM2 << endl;
1649 ind = field_lower.find(
"mv");
1650 if (ind != string::npos) {
1653 if (field_mv.empty()) {
1654 cout <<
"ERROR: no field voltage before 'mV' found: " << field_lower <<
" for record id: " << record_id
1659 if (field_mv !=
"") {
1660 dVoltage = atof(field_mv.c_str());
1661 if (dVoltage < -1) {
1662 cout <<
"ERROR: VKM2 field can't be less or equal -1: " << dVoltage << endl;
1669 double dEnergy = -1;
1670 string beam_lower = beam;
1671 transform(beam_lower.begin(), beam_lower.end(), beam_lower.begin(), ::tolower);
1672 size_t found, next_found;
1673 found = beam_lower.find(
"gev");
1674 if (found != std::string::npos) {
1675 next_found = beam_lower.find(
"gev", found + 1);
1676 if (next_found != std::string::npos) {
1677 cout <<
"ERROR: more than one 'gev' found: " << beam <<
" for record id: " << record_id << endl;
1681 end_pos = found - 1;
1683 if (energy.empty()) {
1684 cout <<
"ERROR: no energy before 'gev' found: " << beam <<
" for record id: " << record_id << endl;
1687 dEnergy = atof(energy.c_str());
1689 cout <<
"ERROR: energy should be greater than 0: " << dEnergy << endl;
1695 string strBeam =
"", strTarget =
"", strTargetWidth =
"";
1696 double dTargetWidth = -1;
1708 for (
size_t i = 0;
i < beam_lower.length();
i++) {
1709 if (strBeam.empty()) {
1710 switch (beam_lower[
i]) {
1727 switch (beam_lower[
i]) {
1773 if (strTarget !=
"") {
1774 ind = beam_lower.find(
"mm",
i);
1775 if (ind != string::npos) {
1778 if (strTargetWidth.empty()) {
1779 cout <<
"ERROR: no target width before 'mm' found: " << beam_lower
1780 <<
" for record id: " << record_id << endl;
1784 if (strTargetWidth !=
"") {
1785 dTargetWidth = atof(strTargetWidth.c_str());
1786 if (dTargetWidth < 0) {
1787 cout <<
"ERROR: target field can't be less or equal 0: " << dTargetWidth << endl;
1796 TString strComment =
"";
1797 if (subject !=
"") {
1798 strComment += TString::Format(
"%s", subject.c_str());
1799 if (record_comment !=
"")
1802 strComment += record_comment;
1806 TString sql_insert = TString::Format(
"insert into log_record(record_date, author, record_type, run_number, "
1807 "shift_leader, trigger_config, daq_status, sp_41, "
1808 "beam, energy, target, target_width, record_comment) "
1809 "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)");
1810 stmt = elog_server->Statement(sql_insert);
1811 stmt->NextIteration();
1813 stmt->SetDatime(cur_index++, dtRecordDate);
1816 stmt->SetNull(cur_index++);
1818 stmt->SetInt(cur_index++, iAuthor);
1823 if (iRecordType < 0)
1824 stmt->SetNull(cur_index++);
1826 stmt->SetInt(cur_index++, iRecordType);
1832 stmt->SetNull(cur_index++);
1834 stmt->SetInt(cur_index++, iRunNumber);
1839 if (iShiftLeader < 0)
1840 stmt->SetNull(cur_index++);
1842 stmt->SetInt(cur_index++, iShiftLeader);
1847 if (iTriggerInfo < 0)
1848 stmt->SetNull(cur_index++);
1850 stmt->SetInt(cur_index++, iTriggerInfo);
1855 if (daq_status ==
"")
1856 stmt->SetNull(cur_index++);
1858 stmt->SetString(cur_index++, daq_status.c_str());
1861 stmt->SetNull(cur_index++);
1863 stmt->SetInt(cur_index++, iSP41);
1869 stmt->SetNull(cur_index++);
1871 stmt->SetString(cur_index++, strBeam.c_str());
1873 stmt->SetNull(cur_index++);
1875 stmt->SetDouble(cur_index++, dEnergy);
1876 if (strTarget ==
"")
1877 stmt->SetNull(cur_index++);
1879 stmt->SetString(cur_index++, strTarget.c_str());
1880 if (dTargetWidth <= 0)
1881 stmt->SetNull(cur_index++);
1883 stmt->SetDouble(cur_index++, (Double_t)dTargetWidth);
1888 if (strComment ==
"")
1889 stmt->SetNull(cur_index++);
1891 stmt->SetString(cur_index++, strComment);
1902 if (!stmt->Process()) {
1903 cout <<
"ERROR: inserting a new Elog record to the ELog Database has been failed" << endl;
1910 if (iLastRunNumber > 0)
1912 }
while ((iLastRunNumber > 0) && (iRunNumber <= iLastRunNumber));
1917 return updated_count;