DownloadNode.cc
7.28 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
/*
* DownloadNode.cc
*
* Created on: Oct 31, 2012
* Author: f.casimir
*/
#include <string.h>
// Common module includes
#include "OutputFormatTime.hh"
// Parameters module includes
#include "ServicesServer.hh"
#include "Parameter.hh"
#include "FileConfigurator.hh"
#include "ParameterManager.hh"
// XMLConfigurator module includes
#include "Constant.hh"
// Download module includes
#include "DownloadLogger.hh"
#include "DownloadOutput.hh"
#include "DownloadNode.hh"
#include "DownloadParamNode.hh"
#include "PostProcessingNode.hh"
using namespace AMDA::Parameters;
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
class TimeFormatNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "TimeFormatNode::proceed")
DownloadProperties *downloadProperties = pContext.get<DownloadProperties *>();
if (strcmp ((const char*)pNode->children->content, "DD") == 0) {
downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_DD);
} else if (strcmp ((const char*)pNode->children->content, "ISO") == 0) {
downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_ISO);
} else if (strcmp ((const char*)pNode->children->content, "DOUBLE") == 0) {
downloadProperties->setTimeFormat(FORMAT_OUTPUT_TIME_DOUBLE);
} 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")
DownloadProperties *downloadProperties = pContext.get<DownloadProperties *>();
if (strcmp ((const char*)pNode->children->content, "ASCII") == 0) {
downloadProperties->setFileFormat(ASCII_FILE_FORMAT);
} else if (strcmp ((const char*)pNode->children->content, "CDF") == 0) {
downloadProperties->setFileFormat(CDF_FILE_FORMAT);
} else if (strcmp ((const char*)pNode->children->content, "NETCDF") == 0) {
downloadProperties->setFileFormat(NETCDF_FILE_FORMAT);
} else if (strcmp ((const char*)pNode->children->content, "JSON") == 0) {
downloadProperties->setFileFormat(JSON_FILE_FORMAT);
if (!downloadProperties->getPrecision())
{
LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed - Precision output is forced for JSON format");
downloadProperties->setPrecision(true);
}
} else if (strcmp ((const char*)pNode->children->content, "VOT") == 0) {
downloadProperties->setFileFormat(VOT_FILE_FORMAT);
if (!downloadProperties->getPrecision())
{
LOG4CXX_DEBUG(gLogger, "FileFormatNode::proceed - Precision output is forced for VOTable format");
downloadProperties->setPrecision(true);
}
} 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")
DownloadProperties *downloadProperties = pContext.get<DownloadProperties *>();
downloadProperties->setFileName((const char*) pNode->children->content);
}
};
class TimeResolutionNode: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "TimeResolutionNode::proceed")
DownloadProperties *downloadProperties = pContext.get<DownloadProperties *>();
downloadProperties->setTimeResolution(atoi((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")
DownloadProperties *downloadProperties = pContext.get<DownloadProperties *>();
if (strcmp ((const char*)pNode->children->content, "one-file") == 0) {
downloadProperties->setOutputStructure(OutputStructure::ONE_FILE);
} else if (strcmp ((const char*)pNode->children->content, "one-file-refparam") == 0) {
downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_REFPARAM);
} else if (strcmp ((const char*)pNode->children->content, "one-file-per-interval") == 0) {
downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_INTERVAL);
} else if (strcmp ((const char*)pNode->children->content, "one-file-per-interval-refparam") == 0) {
downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_INTERVAL_REFPARAM);
} else if (strcmp ((const char*)pNode->children->content, "one-file-per-parameter-per-interval") == 0) {
downloadProperties->setOutputStructure(OutputStructure::ONE_FILE_PER_PARAMETER_PER_INTERVAL);
} else {
ERROR_EXCEPTION("Output structure not supported : " << (const char*)pNode->children->content);
}
xmlChar* value = NULL;
// -- separateInfoFile
value = xmlGetProp(pNode, (const xmlChar *) "separateInfoFile");
if (value != NULL) {
downloadProperties->setSeparateInfoFile( strcmp((char*)value,"true") == 0);
xmlFree(value);
}
}
};
DownloadNode::DownloadNode() : NodeGrpCfg() {
/*
<download>
<timeFormat>ISO</timeFormat>
<fileFormat>ASCII</fileFormat>
<fileName>result</fileName>
<param id='imf'/>
<param id='dst'/>
<timeResolution>600</timeResolution>
<outputStructure>one-file</outputStructure>
</download>
*/
getChildList()["timeFormat"] = NodeCfgSPtr(new TimeFormatNode());
getChildList()["fileFormat"] = NodeCfgSPtr(new FileFormatNode());
getChildList()["fileName"]=NodeCfgSPtr(new FileNameNode());
getChildList()["param"]=NodeCfgSPtr(new DownloadParamNode());
getChildList()["timeResolution"]=NodeCfgSPtr(new TimeResolutionNode());
getChildList()["outputStructure"]=NodeCfgSPtr(new OutputStructureNode());
getChildList()["postProcess"]=NodeCfgSPtr(new postprocessing::PostProcessingNode<DownloadOutput>());
}
void DownloadNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "DownloadNode::proceed: '" << pNode->name << "' node")
ParameterManager* lParameterManager = pContext.get<ParameterManager*>();
ParamOutput *lParamOutputTmp;
CfgContext lContext;
DownloadOutput* ldownloadOutput = new DownloadOutput(*lParameterManager);
xmlChar* lPrecision = xmlGetProp(pNode, (const xmlChar *) "precision");
ldownloadOutput->getDownloadProperties().setPrecision(!(lPrecision == NULL || strcmp((const char *)lPrecision, "false") == 0));
if (lPrecision)
xmlFree(lPrecision);
lParamOutputTmp = ldownloadOutput;
lContext.push<DownloadOutput*>(ldownloadOutput);
lContext.push<DownloadProperties *>(&ldownloadOutput->getDownloadProperties());
ParamOutputSPtr lParamOutput(lParamOutputTmp);
NodeGrpCfg::proceed(pNode, lContext);
lParameterManager->getParamOutputList().push_back(lParamOutput);
}
} // namespace Download
} // namespace ParamOutputImpl
} // namespace AMDA