FileWriter.hh
7.87 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
* FileWriter.hh
*
* Created on: 02 oct. 2014
* Author: AKKA
*/
#ifndef FILEWRITER_HH_
#define FILEWRITER_HH_
#include "VisitorOfParamData.hh"
#include "DownloadProperties.hh"
#include "OutputFormatTime.hh"
#include "Parameter.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"
#include "ParameterIndexesTool.hh"
#include <string>
namespace AMDA
{
namespace ParamOutputImpl
{
namespace Download
{
namespace FileWriter
{
// Enumerate that's define type of a data in a file
typedef enum
{
DT_NONE,
DT_FLOAT,
DT_SHORT,
DT_INT,
DT_DOUBLE,
DT_LONGDOUBLE,
DT_LOGICAL,
DT_TIME
} FileDataType;
// Info keys for AMDA bloc
#define AMDA_ABOUT "AMDA_ABOUT"
#define AMDA_VERSION "AMDA_VERSION"
#define AMDA_ACKNOWLEDGEMENT "AMDA_ACKNOWLEDGEMENT"
// Info keys for request bloc
#define REQUEST_STRUCTURE "REQUEST_STRUCTURE"
#define REQUEST_TIMEFORMAT "REQUEST_TIME_FORMAT"
#define REQUEST_TIMERES "REQUEST_TIME_RESOLUTION"
#define REQUEST_OUTPUTPARAMS "REQUEST_OUTPUT_PARAMS"
#define REQUEST_TTNAME "REQUEST_TIMETABLE_NAME"
// Info keys for interval bloc
#define INTERVAL_START "INTERVAL_START"
#define INTERVAL_STOP "INTERVAL_STOP"
// Info keys when several interval blocs *Furkan*
#define INTERVAL_MIN_START "INTERVAL_MIN_START"
#define INTERVAL_MAX_STOP "INTERVAL_MAX_STOP"
/**
* @class FileWriter
* @brief Abstract class use to define a file format writer.
* @details
*/
class FileWriter
{
public:
/*
* @brief Constructor
*/
FileWriter(AMDA::Parameters::ParameterManager &pParameterManager);
/*
* @brief Destruction
*/
virtual ~FileWriter(void);
/*
* @brief Return extension for the file format
*/
virtual std::string getExtension(void) = 0;
/*
* @brief Return File creation. Close the previous opened file if necessary
*/
virtual bool createNewFile(std::string filePath) = 0;
/*
* @brief Close the current opened file
*/
virtual void closeFile(void) = 0;
/*
* @brief Add an output parameter in the file
*/
virtual bool addParameter(ParamProperties *paramProp, AMDA::Common::ParameterIndexComponentList &indexList,
FileDataType type, bool isFirstParam, int dim1Size = 1, int dim2Size = 1) = 0;
/*
* @brief Function use to know if info must be write in a separate file
*/
virtual bool isInfoInSeparateFile(bool separateInfoFile, bool onlyOneInterval, OutputStructure outputStructure) = 0;
/*
* @brief Write an error in current opened file
*/
virtual bool writeError(std::string msg) = 0;
/*
* @brief Write an AMDA info bloc in current opened file
*/
virtual bool writeAMDAInfo(std::string version, std::string createdby, std::string acknowledgement) = 0;
/*
* @brief Write a request info bloc in current opened file
*/
virtual bool writeRequestInfo(std::string structure, std::string timeFormat,
int timeResolution, std::string outputParams, std::string ttName) = 0;
/*
* @brief Write a parameters info bloc in current opened file
*/
virtual bool writeParamsInfo(ParamPropertiesList ¶mPropertiesList, OutputStructure outputStructure,
std::string currentParamId = "") = 0;
/*
* @brief Write a parameters table info bloc in current opened file
*/
virtual bool writeTableParamsInfo(std::vector<std::string> tableParams, int level) = 0;
/*
* @brief Write an interval info bloc in current opened file
*/
virtual bool writeIntervalInfo(std::string startTime, std::string stopTime, bool isSeveralIntervals) = 0;
/*
* @brief Write a time data in current opened file
*/
virtual bool writeTimeData(std::string paramId, double data, OutputFormatTime timeFormat, bool isFirstParam) = 0;
/*
* @brief Write a float data in current opened file
*/
virtual bool writeFloatData(std::string paramId, int varIndex, float data, bool precision) = 0;
/*
* @brief Write a short data in current opened file
*/
virtual bool writeShortData(std::string paramId, int varIndex, short data, bool precision) = 0;
/*
* @brief Write a int data in current opened file
*/
virtual bool writeIntData(std::string paramId, int varIndex, int data, bool precision) = 0;
/*
* @brief Write a double data in current opened file
*/
virtual bool writeDoubleData(std::string paramId, int varIndex, double data, bool precision) = 0;
/*
* @brief Write a long double data in current opened file
*/
virtual bool writeLongDoubleData(std::string paramId, int varIndex, long double data, bool precision) = 0;
/*
* @brief Write a logical data in current opened file
*/
virtual bool writeLogicalData(std::string paramId, int varIndex, AMDA::Parameters::LogicalData data, bool precision) = 0;
/*
* @brief Flush data in current opened file
*/
virtual bool flushData(std::string paramId, bool isFirstParam) = 0;
/*
* @brief Prepare file to receive next data record
*/
virtual bool goToNextRecord(std::string paramId, bool isFirstParam) = 0;
/*
* @brief File finalization - Highly dependent of the file format
*/
virtual bool finalize(bool isInfoFile = false) = 0;
void setTimeFormat(OutputFormatTime outputFormatTime)
{
switch (outputFormatTime)
{
case OutputFormatTime::FORMAT_OUTPUT_TIME_DOUBLE:
case OutputFormatTime::FORMAT_OUTPUT_TIME_MS:
_outputFormatTime = "SECS FROM 1970-01-01";
break;
default:
_outputFormatTime = "Time UT";
break;
}
}
protected:
/*
* @brief Call back function used to sort ParamInfo list by id
*/
struct cmpParamInfoStruct
{
bool operator()(std::pair<std::string, AMDA::Info::ParamInfoSPtr> const &lhs, std::pair<std::string, AMDA::Info::ParamInfoSPtr> const &rhs) const
{
return lhs.first > rhs.first;
}
};
/*
* @brief Call back function used to sort DatasetInfo list by id
*/
struct cmpDatasetInfoStruct
{
bool operator()(std::pair<std::string, AMDA::Info::DataSetInfoSPtr> const &lhs, std::pair<std::string, AMDA::Info::DataSetInfoSPtr> const &rhs) const
{
return lhs.first > rhs.first;
}
};
/*
* @brief Call back function used to sort InstrumentInfo list by id
*/
struct cmpInstrumentInfoStruct
{
bool operator()(std::pair<std::string, AMDA::Info::InstrumentInfoSPtr> const &lhs, std::pair<std::string, AMDA::Info::InstrumentInfoSPtr> const &rhs) const
{
return lhs.first > rhs.first;
}
};
/*
* @brief Call back function used to sort MissionInfo list by id
*/
struct cmpMissionInfoStruct
{
bool operator()(std::pair<std::string, AMDA::Info::MissionInfoSPtr> const &lhs, std::pair<std::string, AMDA::Info::MissionInfoSPtr> const &rhs) const
{
return lhs.first > rhs.first;
}
};
/*
* @brief recursive function to sort parameters info in two list: one for base parameters,
* and the other one for derived parameters
* Parameters info are ordered by id
*/
void sortParametersInfoByType(std::string crtParamId,
std::set<std::pair<std::string, AMDA::Info::ParamInfoSPtr>, cmpParamInfoStruct> &baseParamsInfoList,
std::set<std::pair<std::string, AMDA::Info::ParamInfoSPtr>, cmpParamInfoStruct> &derivedParamsInfoList);
AMDA::Parameters::ParameterManager &_parameterManager;
std::string _outputFormatTime;
};
} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */
#endif /* FILEWRITER_HH_ */