StatisticNode.cc
7.99 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
/*
* StatisticNode.cc
*
* Created on: 04 nov 2014
* Author: AKKA
*/
#include <string.h>
// Parameters module includes
#include "ServicesServer.hh"
#include "Parameter.hh"
#include "FileConfigurator.hh"
#include "ParameterManager.hh"
#include "TimeTable.hh"
#include "AsciiWriter.hh"
#include "InternalXMLWriter.hh"
#include "VOTableWriter.hh"
#include "PostProcessingNode.hh"
// XMLConfigurator module includes
#include "Constant.hh"
// Statistic output
#include "StatisticNode.hh"
#include "StatisticOutput.hh"
using namespace AMDA::Parameters;
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace ParamOutputImpl {
namespace Statistic {
class TimeFormatNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "TimeFormatNode::proceed")
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
if (strcmp ((const char*)pNode->children->content, "ISO") == 0) {
statisticProperties->setTimeFormat(TimeTableCatalog::TimeTable::TIME_FORMAT::YYYYMMDDThhmmssmsk);
} else {
ERROR_EXCEPTION("Time Format not supported : " << (const char*)pNode->children->content);
}
}
};
class FileFormatNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed")
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
if (strcmp ((const char*)pNode->children->content, "ASCII") == 0) {
statisticProperties->setFileFormatKey(TimeTableCatalog::AsciiWriter::FORMAT);
} else if (strcmp ((const char*)pNode->children->content, "XML") == 0) {
statisticProperties->setFileFormatKey(TimeTableCatalog::InternalXMLWriter::FORMAT);
} else if (strcmp ((const char*)pNode->children->content, "VOT") == 0) {
statisticProperties->setFileFormatKey(TimeTableCatalog::VOTableWriter::FORMAT);
} else {
ERROR_EXCEPTION("File Format not supported : " << (const char*)pNode->children->content);
}
}
};
class FileNameNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "FileNameNode::proceed")
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
statisticProperties->setFileName((const char*) pNode->children->content);
}
};
class OutputStructureNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "OutputStructureNode::proceed")
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
if (strcmp ((const char*)pNode->children->content, "one-file") == 0) {
statisticProperties->setOutputStructure(OutputStructure::ONE_FILE);
} else if (strcmp ((const char*)pNode->children->content, "one-file-per-parameter") == 0) {
statisticProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_PARAMETER);
} else {
ERROR_EXCEPTION("Output structure not supported : " << (const char*)pNode->children->content);
}
}
};
class FunctionArgumentNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "FunctionArgumentNode::proceed")
FunctionProperties *functionProperties = pContext.get<FunctionProperties *>();
xmlChar *lArgName = xmlGetProp(pNode, (const xmlChar *) "name");
xmlChar *lValName = xmlGetProp(pNode, (const xmlChar *) "value");
if ((lArgName != NULL) && (lValName != NULL))
functionProperties->addArgument((const char*) lArgName, (const char*) lValName);
if (lArgName)
xmlFree(lArgName);
if (lValName)
xmlFree(lValName);
}
};
class FunctionNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
FunctionNode(void) : NodeGrpCfg() {
getChildList()["argument"] = NodeCfgSPtr(new FunctionArgumentNode());
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "FunctionNode::proceed")
ParamProperties *paramProperties = pContext.get<ParamProperties *>();
xmlChar *lFuncName = xmlGetProp(pNode, (const xmlChar *) "name");
if (lFuncName == NULL) {
ERROR_EXCEPTION(
AMDA::XMLConfigurator::ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@name")
}
FunctionProperties* functionProperties = new FunctionProperties();
functionProperties->setName((const char*) lFuncName);
xmlFree(lFuncName);
paramProperties->addFunctionProperties(functionProperties);
CfgContext lContext;
lContext.push<FunctionProperties *>(functionProperties);
NodeGrpCfg::proceed(pNode, lContext);
}
};
class ParamNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
ParamNode(void) : NodeGrpCfg() {
getChildList()["function"] = NodeCfgSPtr(new FunctionNode());
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "ParamNode::proceed");
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
xmlChar *lParamId = xmlGetProp(pNode, (const xmlChar *) "id");
if (lParamId == NULL) {
ERROR_EXCEPTION(
AMDA::XMLConfigurator::ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << AMDA::XMLConfigurator::PARAMNAME)
}
ParamProperties* paramProperties = new ParamProperties();
paramProperties->setId((const char*) lParamId);
xmlFree(lParamId);
xmlChar *lParamIndex = xmlGetProp(pNode, (const xmlChar *) "index");
if (lParamIndex != NULL) {
paramProperties->setIndex(atoi( (const char*) lParamIndex));
xmlFree(lParamIndex);
}
CfgContext lContext;
lContext.push<ParamProperties *>(paramProperties);
NodeGrpCfg::proceed(pNode, lContext);
statisticProperties->addParamProperties(paramProperties);
}
};
class ParamsNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
ParamsNode(void) : NodeGrpCfg() {
getChildList()["param"] = NodeCfgSPtr(new ParamNode());
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "ParamsNode::proceed");
StatisticProperties *statisticProperties = pContext.get<StatisticProperties *>();
CfgContext lContext;
lContext.push<StatisticProperties *>(statisticProperties);
NodeGrpCfg::proceed(pNode, lContext);
}
};
StatisticNode::StatisticNode(void) : NodeGrpCfg() {
getChildList()["timeFormat"] = NodeCfgSPtr(new TimeFormatNode());
getChildList()["fileFormat"] = NodeCfgSPtr(new FileFormatNode());
getChildList()["outputStructure"] = NodeCfgSPtr(new OutputStructureNode());
getChildList()["fileName"] = NodeCfgSPtr(new FileNameNode());
getChildList()["params"] = NodeCfgSPtr(new ParamsNode());
getChildList()["postProcess"]=NodeCfgSPtr(new postprocessing::PostProcessingNode<StatisticOutput>());
}
void StatisticNode::proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "StatisticNode::proceed");
ParameterManager* lParameterManager = pContext.get<ParameterManager*>();
ParamOutput *lParamOutputTmp;
CfgContext lContext;
StatisticOutput* lstatisticOutput = new StatisticOutput(*lParameterManager);
lContext.push<StatisticOutput *>(lstatisticOutput);
lContext.push<StatisticProperties *>(&lstatisticOutput->getStatisticProperties());
lParamOutputTmp = lstatisticOutput;
ParamOutputSPtr lParamOutput(lParamOutputTmp);
NodeGrpCfg::proceed(pNode, lContext);
lParameterManager->getParamOutputList().push_back(lParamOutput);
}
} // namespace Statistic
} // namespace ParamOutputImpl
} // namespace AMDA