BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
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>
38
using namespace
std
;
39
40
struct
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
66
struct
structParseSchema
67
{
68
// skip element
69
bool
isSkip
;
70
bool
isUpdate
;
71
vector<structParseRow>
vecRows
;
72
73
structParseSchema
() {
isUpdate
=
false
; }
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
}
83
~structParseSchema
()
84
{
85
if
(
isSkip
==
false
)
86
vecRows
.clear();
87
}
88
};
89
90
struct
structParseValue
91
{
92
TDatime
dtSpillEnd
;
93
vector<boost::any>
arrValues
;
94
};
95
96
class
UniParser
97
{
98
public
:
99
UniParser
();
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)
111
int
ParseDb2Db
();
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
ClassDef
#define ClassDef(name, id)
TDatime.h
TObjArray.h
TString.h
TDatime
TString
UniParser::ParseTxtNoise2Db
int ParseTxtNoise2Db(int period_number, TString txtName, TString schemaPath)
Definition
UniParser.cxx:797
UniParser::ParseTxt2Db
int ParseTxt2Db(TString txtName, TString schemaPath, bool isUpdate=false)
Definition
UniParser.cxx:666
UniParser::~UniParser
virtual ~UniParser()
Definition
UniParser.cxx:29
UniParser::ConvertElogCsv
int ConvertElogCsv(TString csvName="parse_schemes/elog.csv", char separate_symbol=';')
Definition
UniParser.cxx:1320
UniParser::ParseCsv2Db
int ParseCsv2Db(TString csvName, TString schemaPath, bool isUpdate=false)
Definition
UniParser.cxx:548
UniParser::ParseXml2Db
int ParseXml2Db(TString xmlName, TString schemaPath, bool isUpdate=false)
Definition
UniParser.cxx:377
UniParser::ParseTxt2Struct
int ParseTxt2Struct(TString txtName, TString schemaPath, vector< structParseValue * > &parse_values, vector< structParseSchema > &vecElements, int iVerbose=1)
Definition
UniParser.cxx:1078
UniParser::ParseDb2Db
int ParseDb2Db()
Definition
UniParser.cxx:959
UniParser::UniParser
UniParser()
Definition
UniParser.cxx:27
std
Definition
json.hpp:4446
structParseRow
Definition
UniParser.h:41
structParseRow::isParse
bool isParse
Definition
UniParser.h:45
structParseRow::strStatementType
TString strStatementType
Definition
UniParser.h:44
structParseRow::strParseType
TString strParseType
Definition
UniParser.h:47
structParseRow::strColumnName
TString strColumnName
Definition
UniParser.h:42
structParseRow::structParseRow
structParseRow(TString column_name, TString statement_type, bool is_parse=false, int start_index=0, TString parse_type="", TString delimiter="")
Definition
UniParser.h:50
structParseRow::strDelimiter
TString strDelimiter
Definition
UniParser.h:48
structParseRow::iStartIndex
int iStartIndex
Definition
UniParser.h:46
structParseSchema::structParseSchema
structParseSchema()
Definition
UniParser.h:73
structParseSchema::structParseSchema
structParseSchema(bool is_skip, TString column_name="", TString statement_type="")
Definition
UniParser.h:74
structParseSchema::vecRows
vector< structParseRow > vecRows
Definition
UniParser.h:71
structParseSchema::~structParseSchema
~structParseSchema()
Definition
UniParser.h:83
structParseSchema::isUpdate
bool isUpdate
Definition
UniParser.h:70
structParseSchema::isSkip
bool isSkip
Definition
UniParser.h:69
structParseValue
Definition
UniParser.h:91
structParseValue::dtSpillEnd
TDatime dtSpillEnd
Definition
UniParser.h:92
structParseValue::arrValues
vector< boost::any > arrValues
Definition
UniParser.h:93
database
tools
UniParser.h
Generated on
for BmnRoot by
1.17.0