BmnRoot
Loading...
Searching...
No Matches
UniParser.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------
2// ----- Functions to parse TXT, XML, CSV files and write the values to the database -----
3// ----- Created 18/08/15 by K. Gertsenberger -----
4// -----------------------------------------------------------------------------------------
5//
6// It uses *.xslt scheme with rules to parse given format:
7// <skip line_count=""/> - skip given count of text lines in file
8// <search name="tag name"/> - search tag with given name
9// <move down="recursively child number"/> - move to child tag recursively
10// <cycle child="parent name" table_name="database table to write parsing values" delimiter="delimeters between
11// elements" skip="number of skipping text lines">
12// - cycle for elements separated by delimiters and write them to the database (childs of parent with given name if it
13// was set)
14// <element action=["skip", "update", "write", "multi", "parse"], where:
15// action="skip" - skip current element
16// action="update" column_name="database column name" type="type name"/> - update database table row with database
17// column name being equal the cuurent element action="write" column_name="database column name" type="type name"/> -
18// convert current element to the given type (int, double, string, datetime, hex, binary) and write to the given
19// database table column action="multi"> <subelement action...> <subelement action...> ... </element> action="parse"
20// start_index="parse from start symbol" parse_type=["counter" - current element number from 1, "value:fixed_value",
21// "parsed type name + 'int_array' or 'double_array'"] delimiter="delimeter symbol if parsed array"
22// column_name="database column name" type="C++ type"/>
23// - converted value from start symbol (default, 0) OR special values to write to the database table column
24// action="parse" parse_type=["counter" - current element number from 1, "value:fixed_value"] column_name="database
25// column name" type="type name"/> - special values to write to the database table column
26// </cycle>
27// possible data types: "int", "hex", "double", "string", "datetime", "binary"
28
29#ifndef UNIPARSER_H
30#define UNIPARSER_H 1
31
32#include "TDatime.h"
33#include "TObjArray.h"
34#include "TString.h"
35
36#include <boost/any.hpp>
37#include <vector>
38using namespace std;
39
40struct structParseRow
41{
42 TString strColumnName;
43 // int, hex, double, string, datetime, binary
44 TString strStatementType;
45 bool isParse;
46 int iStartIndex;
47 TString strParseType;
48 TString strDelimiter;
49
50 structParseRow(TString column_name,
51 TString statement_type,
52 bool is_parse = false,
53 int start_index = 0,
54 TString parse_type = "",
55 TString delimiter = "")
56 {
57 strColumnName = column_name;
58 strStatementType = statement_type;
59 isParse = is_parse;
60 iStartIndex = start_index;
61 strParseType = parse_type;
62 strDelimiter = delimiter;
63 }
64};
65
67{
68 // skip element
69 bool isSkip;
70 bool isUpdate;
71 vector<structParseRow> vecRows;
72
74 structParseSchema(bool is_skip, TString column_name = "", TString statement_type = "")
75 {
76 isUpdate = false;
77 isSkip = is_skip;
78 if (is_skip == false) {
79 structParseRow row(column_name, statement_type);
80 vecRows.push_back(row);
81 }
82 }
84 {
85 if (isSkip == false)
86 vecRows.clear();
87 }
88};
89
91{
92 TDatime dtSpillEnd;
93 vector<boost::any> arrValues;
94};
95
96class UniParser
97{
98 public:
100 virtual ~UniParser();
101
102 // common parsing functions for the most cases
103 int ParseXml2Db(TString xmlName, TString schemaPath, bool isUpdate = false);
104 int ParseCsv2Db(TString csvName, TString schemaPath, bool isUpdate = false);
105 int ParseTxt2Db(TString txtName, TString schemaPath, bool isUpdate = false);
106
107 // parse text file not in a common format (should be rewritten to a common case later)
108 int ParseTxtNoise2Db(int period_number, TString txtName, TString schemaPath);
109
110 // parse DB fields to write to other fields (temporary function)
112
113 // parse text file to structure with values
114 int ParseTxt2Struct(TString txtName,
115 TString schemaPath,
116 vector<structParseValue*>& parse_values,
117 vector<structParseSchema>& vecElements,
118 int iVerbose = 1);
119
120 // save text ELOG of the BM@N experiemnt in CSV format to new Elog DB (temporary function)
121 int ConvertElogCsv(TString csvName = "parse_schemes/elog.csv", char separate_symbol = ';');
122
123 ClassDef(UniParser, 1)
124};
125
126#endif
int ParseTxtNoise2Db(int period_number, TString txtName, TString schemaPath)
int ParseTxt2Db(TString txtName, TString schemaPath, bool isUpdate=false)
int ConvertElogCsv(TString csvName="parse_schemes/elog.csv", char separate_symbol=';')
int ParseCsv2Db(TString csvName, TString schemaPath, bool isUpdate=false)
virtual ~UniParser()
int ParseXml2Db(TString xmlName, TString schemaPath, bool isUpdate=false)
int ParseTxt2Struct(TString txtName, TString schemaPath, vector< structParseValue * > &parse_values, vector< structParseSchema > &vecElements, int iVerbose=1)
int ParseDb2Db()
STL namespace.
TString strStatementType
Definition UniParser.h:44
TString strParseType
Definition UniParser.h:47
TString strColumnName
Definition UniParser.h:42
structParseRow(TString column_name, TString statement_type, bool is_parse=false, int start_index=0, TString parse_type="", TString delimiter="")
Definition UniParser.h:50
TString strDelimiter
Definition UniParser.h:48
structParseSchema(bool is_skip, TString column_name="", TString statement_type="")
Definition UniParser.h:74
vector< structParseRow > vecRows
Definition UniParser.h:71
TDatime dtSpillEnd
Definition UniParser.h:92
vector< boost::any > arrValues
Definition UniParser.h:93