Blame view

src/Info/ParamParser.cc 8.06 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * 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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
29
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
30
31
32
33
34
35
36
37
38
39
40
41
42
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
43
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
44
45
46
47
48
49
50
51
52
53
54
55
56
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
57
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
58
59
60
61
62
63
64
65
66
67
68
69
70
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
71
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
72
73
74
75
76
77
78
79
80
81
82
83
84
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
85
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
86
87
88
89
90
91
92
93
94
95
96
97
98
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
99
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
100
101
102
103
104
105
106
107
108
109
110
111
112
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
113
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
114
115
116
117
118
119
120
121
122
123
124
125
126
		  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*>();
6d3dba6e   Benjamin Renard   Fix bug with fill...
127
128
129
130
131
	  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);
	  }
fbe3c2bb   Benjamin Renard   First commit
132
133
134
135
136
137
138
139
140
141
142
143
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Parameter UCD node
 */
class ParamUcdNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  ParamInfo* pParamInfo =  pContext.get<ParamInfo*>();
9f1b707e   Benjamin Renard   Fix tests used to...
144
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
145
146
147
148
149
150
151
152
153
154
155
156
157
		  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*>();
9f1b707e   Benjamin Renard   Fix tests used to...
158
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
fbe3c2bb   Benjamin Renard   First commit
159
160
161
162
163
164
		  pParamInfo->setDatasetId((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
8c8ac7bf   Benjamin Renard   Write mission/ins...
165
166
167
168
169
170
171
 * @brief Parameter instrument id node
 */
class ParamInstrumentIdNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  ParamInfo* pParamInfo =  pContext.get<ParamInfo*>();
9f1b707e   Benjamin Renard   Fix tests used to...
172
	  if (pNode->children && pNode->children->content && (pNode->children->content [0] != '\0'))
8c8ac7bf   Benjamin Renard   Write mission/ins...
173
174
175
176
177
178
179
		  pParamInfo->setInstrumentId((const char*)pNode->children->content);
  }
};


///////////////////////////////////////////////////////////////////////////////
/*
fbe3c2bb   Benjamin Renard   First commit
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
 * @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);
8c8ac7bf   Benjamin Renard   Write mission/ins...
198
		getChildList()["instrument_id"] = NodeCfgSPtr(new ParamInstrumentIdNode);
fbe3c2bb   Benjamin Renard   First commit
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
	}

	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 {
48d596b2   brenard   Do not log an err...
236
		XMLConfigurator::proceed(paramFile.c_str(), ctx, true);
fbe3c2bb   Benjamin Renard   First commit
237
238
239
240
241
242
243
244
245
246
247
	}
	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 */