ParamParser.cc
8.06 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* ParamParser.cc
*
* Created on: Oct 6, 2014
* Author: m.mazel
*/
#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "ParamParser.hh"
#include "ParamTableNode.hh"
#include "StatusDefNode.hh"
#include "InfoLogger.hh"
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace Info {
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter name node
*/
class ParamNameNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setName((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter short name node
*/
class ParamShortNameNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setShortName((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter components node
*/
class ParamComponentsNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setComponents((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter units node
*/
class ParamUnitsNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setUnits((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter coordinates system node
*/
class ParamCoordinatesSystemNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setCoordinatesSystem((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter tensor order node
*/
class ParamTensorOrderNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setTensorOrder(atoi((const char*)pNode->children->content));
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter SI Conversion node
*/
class ParamSiConversionNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setSiConversion((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter fill value node
*/
class ParamFillValueNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0')) {
double fillVal = atof((const char*)pNode->children->content);
pParamInfo->setFillValue(fillVal);
pParamInfo->setOriginalFillValue(fillVal);
}
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter UCD node
*/
class ParamUcdNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setUcd((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter dataset id node
*/
class ParamDatasetIdNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setDatasetId((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parameter instrument id node
*/
class ParamInstrumentIdNode : public NodeCfg
{
public:
void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
ParamInfo* pParamInfo = pContext.get<ParamInfo*>();
if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
pParamInfo->setInstrumentId((const char*)pNode->children->content);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Info node of a parameter
*/
class ParamInfoNode : public NodeGrpCfg {
public:
ParamInfoNode () : NodeGrpCfg() {
getChildList()["name"] = NodeCfgSPtr(new ParamNameNode);
getChildList()["short_name"] = NodeCfgSPtr(new ParamShortNameNode);
getChildList()["components"] = NodeCfgSPtr(new ParamComponentsNode);
getChildList()["units"] = NodeCfgSPtr(new ParamUnitsNode);
getChildList()["coordinates_system"] = NodeCfgSPtr(new ParamCoordinatesSystemNode);
getChildList()["tensor_order"] = NodeCfgSPtr(new ParamTensorOrderNode);
getChildList()["si_conversion"] = NodeCfgSPtr(new ParamSiConversionNode);
getChildList()["table"]=NodeCfgSPtr(new ParamTableNode());
getChildList()["fill_value"] = NodeCfgSPtr(new ParamFillValueNode);
getChildList()["ucd"] = NodeCfgSPtr(new ParamUcdNode);
getChildList()["status_def"] = NodeCfgSPtr(new StatusDefNode);
getChildList()["dataset_id"] = NodeCfgSPtr(new ParamDatasetIdNode);
getChildList()["instrument_id"] = NodeCfgSPtr(new ParamInstrumentIdNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_INFO(gLogger, "ParamInfoNode::proceed");
// Proceed nodes
NodeGrpCfg::proceed(pNode, pContext);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Constructor of the info parser of a parameter
*/
ParamParser::ParamParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,true)
{
// read ParamInfo node
NodeGrpCfg* lRequestNode = new NodeGrpCfg();
getXmlConfiguratorMap()["param"] = RootNodeCfgSPtr(lRequestNode);
lRequestNode->getChildList()["info"] = NodeCfgSPtr(new ParamInfoNode);
}
///////////////////////////////////////////////////////////////////////////////
/*
* @brief Parse info
*/
boost::shared_ptr<ParamInfo> ParamParser::parse (const std::string& paramId,
const std::string& paramFile) {
LOG4CXX_INFO(gLogger, "ParamParser::parse parsing " << paramFile);
AMDA::Parameters::CfgContext ctx;
boost::shared_ptr<ParamInfo> paramInfo (new ParamInfo);
paramInfo->setId(paramId);
ctx.push<ParamInfo *>(paramInfo.get());
// Check schema validity and parse xml file
try {
XMLConfigurator::proceed(paramFile.c_str(), ctx, true);
}
catch (...) {
LOG4CXX_INFO(gLogger, "ParamParser::parse error while parsing file " << paramFile);
// Return a null ptr to ParamInfo
return ParamInfoSPtr();
}
return paramInfo;
}
} /* namespace Info */
} /* namespace AMDA */