Blame view

src/ParamOutputImpl/Download/FileWriter.hh 6.31 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * FileWriter.hh
 *
 *  Created on: 02 oct. 2014
 *      Author: AKKA
 */

#ifndef FILEWRITER_HH_
#define FILEWRITER_HH_

#include "VisitorOfParamData.hh"
#include "DownloadProperties.hh"
#include "Parameter.hh"
#include "ParamMgr.hh"
093107ce   Benjamin Renard   Fix order of miss...
15
16
17
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"
fbe3c2bb   Benjamin Renard   First commit
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
#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"
897858c8   Benjamin Renard   Support multi TT ...
50
#define REQUEST_TTNAME       "REQUEST_TIMETABLE_NAME"
fbe3c2bb   Benjamin Renard   First commit
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

//Info keys for interval bloc
#define INTERVAL_START "INTERVAL_START"
#define INTERVAL_STOP  "INTERVAL_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
	 */
4f3abe6a   Benjamin Renard   Give the possibil...
98
	virtual bool isInfoInSeparateFile(bool separateInfoFile, bool onlyOneInterval, OutputStructure outputStructure)=0;
fbe3c2bb   Benjamin Renard   First commit
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

	/*
	 * @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,
897858c8   Benjamin Renard   Support multi TT ...
114
			int timeResolution, std::string outputParams, std::string ttName) = 0;
fbe3c2bb   Benjamin Renard   First commit
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

	/*
	 * @brief Write a parameters info bloc in current opened file
	 */
	virtual bool writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
			std::string currentParamId = "") = 0;

	/*
	 * @brief Write an interval info bloc in current opened file
	 */
	virtual bool writeIntervalInfo(std::string startTime, std::string stopTime) = 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 Prepare file to receive next data record
	 */
	virtual bool goToNextRecord(std::string paramId) = 0;

	/*
	 * @brief File finalization - Highly dependent of the file format
	 */
	virtual bool finalize(bool isInfoFile = false) = 0;

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;
	  }
	};

	/*
093107ce   Benjamin Renard   Fix order of miss...
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
	 * @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;
		}
	};

	/*
fbe3c2bb   Benjamin Renard   First commit
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
	 * @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;
};

} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */

#endif /* FILEWRITER_HH_ */