DataSetParser.cc
7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* DataSetParser.cc
*
* Created on: Oct 6, 2014
* Author: m.mazel
*/
#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "DataSetParser.hh"
#include "InfoLogger.hh"
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace Info {
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset name node
*/
class DataSetNameNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setName((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset description node
*/
class DataSetDescriptionNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setDescription((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset source node
*/
class DataSetSourceNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setSource((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset global start node
*/
class DataSetGlobalStartNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setGlobalStart((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset global stop node
*/
class DataSetGlobalStopNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setGlobalStop((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset min sampling node
*/
class DataSetMinSamplingNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setMinSampling(atoi ((const char*)pNode->children->content));
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset max sampling node
*/
class DataSetMaxSamplingNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setMaxSampling(atoi ((const char*)pNode->children->content));
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset caveats node
*/
class DataSetCaveatsNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setCaveats((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset acknowledgement node
*/
class DataSetAcknowledgementNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setAcknowledgement((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset instrument id node
*/
class DataSetInstrumentIdNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
if ((pNode->children != NULL) && (pNode->children->content != NULL))
pDataSetInfo->setInstrumentId((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset info node
*/
class DataSetInfoNode : public NodeGrpCfg {
public:
DataSetInfoNode () : NodeGrpCfg() {
getChildList()["name"] = NodeCfgSPtr(new DataSetNameNode);
getChildList()["description"] = NodeCfgSPtr(new DataSetDescriptionNode);
getChildList()["source"] = NodeCfgSPtr(new DataSetSourceNode);
getChildList()["global_start"] = NodeCfgSPtr(new DataSetGlobalStartNode);
getChildList()["global_stop"] = NodeCfgSPtr(new DataSetGlobalStopNode);
getChildList()["min_sampling"] = NodeCfgSPtr(new DataSetMinSamplingNode);
getChildList()["max_sampling"] = NodeCfgSPtr(new DataSetMaxSamplingNode);
getChildList()["caveats"] = NodeCfgSPtr(new DataSetCaveatsNode);
getChildList()["acknowledgement"] = NodeCfgSPtr(new DataSetAcknowledgementNode);
getChildList()["instrument_id"] = NodeCfgSPtr(new DataSetInstrumentIdNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_INFO(gLogger, "DataSetInfoNode::proceed");
DataSetInfo* pDataSetInfo = pContext.get<DataSetInfo*>();
// read dataset id
xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "id");
if (value) {
pDataSetInfo->setId ((const char*) value);
xmlFree(value);
}
// Proceed nodes
NodeGrpCfg::proceed(pNode, pContext);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Dataset node parser
*/
DataSetParser::DataSetParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,true)
{
// DatasetInfo root node
getXmlConfiguratorMap()["dataset"] = RootNodeCfgSPtr(new DataSetInfoNode ());
}
boost::shared_ptr<DataSetInfo> DataSetParser::parse (const std::string& dataSetFile) {
LOG4CXX_INFO(gLogger, "DataSetParser::parse parsing " << dataSetFile);
AMDA::Parameters::CfgContext ctx;
boost::shared_ptr<DataSetInfo> dataSetInfo (new DataSetInfo ());
ctx.push<DataSetInfo *>(dataSetInfo.get());
// Check schema validity and parse xml file
try {
if (!XMLConfigurator::proceed(dataSetFile.c_str(), ctx, true)) {
return DataSetInfoSPtr();
}
}
catch (...) {
LOG4CXX_INFO(gLogger, "DataSetParser::parse error while parsing file " << dataSetFile);
// Return a null ptr to DataSetInfo
return DataSetInfoSPtr();
}
return dataSetInfo;
}
} /* namespace Info */
} /* namespace AMDA */