Blame view

src/ParamOutputImpl/Download/DownloadOutput.cc 80.8 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * DownloadOutput.cc
 *
 *  Created on: 03 oct. 2014
 *      Author: AKKA
 */

#include "DownloadOutput.hh"
#include "FileWriterASCIITabular.hh"
#include "FileWriterASCIIJson.hh"
#include "FileWriterASCIIVOTable.hh"
#include "FileWriterCDF.hh"
#include "Helper.hh"
3e19e9d5   Hacene SI HADJ MOHAND   completly vriable...
14
#include "Process.hh"
fbe3c2bb   Benjamin Renard   First commit
15
16
17
#include "Properties.hh"
#include "TimeUtil.hh"
#include "AMDA-Kernel_Config.hh"
5a7c3896   Hacene SI HADJ MOHAND   adding tableParam...
18
#include "Parameter.hh"
79366e37   Hacene SI HADJ MOHAND   trying to add ful...
19
#include <algorithm>
fbe3c2bb   Benjamin Renard   First commit
20
21
22
23
24
25
26
27
28
#include "TimeTable.hh"
#include "TimeTableCatalogFactory.hh"

#include "ServicesServer.hh"
#include "TimeInterval.hh"

#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>

7929a8a9   Benjamin Renard   CDF writer optimi...
29
30
using namespace std::chrono;

1a6e8df3   Erdogan Furkan   7875 - time inter...
31
32
33
34
namespace AMDA
{
    namespace ParamOutputImpl
    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
35
36
37
38

        /**
         * @brief Implement ParamOutput to download parameters data in files.
         */
1a6e8df3   Erdogan Furkan   7875 - time inter...
39
40
41
42
43
44
45
46
47
48
49
        namespace Download
        {

            DownloadOutput::DownloadOutput(AMDA::Parameters::ParameterManager &pParameterManager) : VisitorOfParamData(),
                                                                                                    ParamOutput(pParameterManager),
                                                                                                    _downloadProperties(),
                                                                                                    _fileWriter(NULL),
                                                                                                    _currentParamId(""),
                                                                                                    _firstParamId(""),
                                                                                                    _currentIntervalIndex(0)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
50
            }
fbe3c2bb   Benjamin Renard   First commit
51

1a6e8df3   Erdogan Furkan   7875 - time inter...
52
53
            DownloadOutput::~DownloadOutput()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
54
55
56
57
58
59
60
                if (_fileWriter != NULL)
                    delete _fileWriter;
            }

            /**
             * @overload DataClient::establishConnection()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
61
62
            void DownloadOutput::establishConnection()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
63
64
                LOG4CXX_DEBUG(_logger, "DownloadOutput::establishConnection");

1a6e8df3   Erdogan Furkan   7875 - time inter...
65
                // Create the file writer
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
66
67
                createFileWriter();

1a6e8df3   Erdogan Furkan   7875 - time inter...
68
69
70
                // create all needed parameters
                try
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
71
72
                    _currentTimeInterval = _parameterManager.getInputIntervals()->begin();
                    createParameters();
1a6e8df3   Erdogan Furkan   7875 - time inter...
73
74
75
                }
                catch (...)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
76
77
78
79
                    LOG4CXX_ERROR(_logger, "DownloadOutput::establishConnection - It's impossible to create parameters");
                    throw;
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
80
81
82
                // open connection for all needed parameters
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
83
84
                    LOG4CXX_DEBUG(_logger, "DownloadOutput::establishConnection - " << paramProperties->getOutputId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
85
86
                    try
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
87
88
89
90
91
                        _parameterManager.getParameter(paramProperties->getOutputId())->openConnection(this);

                        AMDA::Parameters::ParameterSPtr param = _parameterManager.getParameter(paramProperties->getOriginalId());

                        AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramProperties->getOriginalId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
92
93
94
95
96
97
98
99
100
101
                        // adding tableParams
                        std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>> tables = paramInfo->getTables();
                        if (!tables.empty())
                        {
                            for (auto table : tables)
                            {
                                if (table.second != nullptr)
                                {
                                    if (table.second->isVariable(&_parameterManager))
                                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
102
103
                                        std::map<std::string, std::string> tableParamIds = table.second->getTableParams(&_parameterManager);
                                        if (!tableParamIds.empty())
1a6e8df3   Erdogan Furkan   7875 - time inter...
104
105
                                            for (auto tableParamId : tableParamIds)
                                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
106
                                                AMDA::Parameters::ParameterSPtr tableParam = _parameterManager.getParameter(tableParamId.second);
1a6e8df3   Erdogan Furkan   7875 - time inter...
107
108
                                                if ((_downloadProperties.getTimeResolution() > 0) && (_downloadProperties.getOutputStructure() != ONE_FILE_PER_PARAMETER_PER_INTERVAL))
                                                {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
109
110
                                                    // Use resampled table param
                                                    tableParam = _parameterManager.getSampledParameter(
1a6e8df3   Erdogan Furkan   7875 - time inter...
111
112
113
114
                                                        tableParamId.second,
                                                        "classic",
                                                        _downloadProperties.getTimeResolution(),
                                                        tableParam->getGapThreshold(), true);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
115
                                                }
1a6e8df3   Erdogan Furkan   7875 - time inter...
116
                                                tableParam->openConnection(this);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
117
                                            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
118
119
                                    }
                                }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
120
                            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
121
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
122
123
124
                    }
                    catch (...)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
125
126
127
                        LOG4CXX_ERROR(_logger, "DownloadOutput::establishConnection - It's impossible to open connection for " << paramProperties->getOutputId());
                        std::string filePath = getFilePath(_fileWriter->getExtension());
                        if (_fileWriter->createNewFile(filePath))
1a6e8df3   Erdogan Furkan   7875 - time inter...
128
                            _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
129
130
131
                        throw;
                    }
                }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
132
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
133

1a6e8df3   Erdogan Furkan   7875 - time inter...
134
135
            void DownloadOutput::addAditionalDownloadParams(std::string paramId, bool isFullVariable)
            {
295de3cf   Hacene SI HADJ MOHAND   in progress
136
                AMDA::Parameters::ParameterSPtr pParam = _parameterManager.getParameter(paramId);
6aeb2611   Hacene SI HADJ MOHAND   resloving some pl...
137
                if (pParam == NULL || _downloadProperties.getParamPropertiesFromOriginalId(paramId) != NULL)
a3eb6f22   Hacene SI HADJ MOHAND   clen up
138
139
                    return;
                AMDA::Info::ParamInfoSPtr processInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramId);
1a6e8df3   Erdogan Furkan   7875 - time inter...
140
141
142
143
144
                if (isFullVariable || (pParam->isTableIndexParam() && processInfo->getProcessInfo().empty()))
                {
                    if ((_downloadProperties.getTimeResolution() > 0) && (_downloadProperties.getOutputStructure() != ONE_FILE_PER_PARAMETER_PER_INTERVAL))
                    {
                        // Use resampled table param
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
145
                        pParam = _parameterManager.getSampledParameter(
1a6e8df3   Erdogan Furkan   7875 - time inter...
146
147
148
149
                            paramId,
                            "classic",
                            _downloadProperties.getTimeResolution(),
                            pParam->getGapThreshold(), true);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
150
                    }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
151
                    pParam->openConnection(this);
1a6e8df3   Erdogan Furkan   7875 - time inter...
152
                    ParamProperties *paramProperties = new ParamProperties();
a3eb6f22   Hacene SI HADJ MOHAND   clen up
153
                    paramProperties->setOriginalId(paramId);
ecf2e147   Benjamin Renard   Use resampled tab...
154
                    paramProperties->setOutputId(pParam->getId());
a3eb6f22   Hacene SI HADJ MOHAND   clen up
155
156
                    _downloadProperties.addParamProperties(paramProperties);
                    pParam->init(this, _timeIntervalList);
a3eb6f22   Hacene SI HADJ MOHAND   clen up
157
158
                }
                AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramId);
1a6e8df3   Erdogan Furkan   7875 - time inter...
159
                const std::vector<std::string> &paramLinkedParams = paramInfo->getLinkedParamList();
a3eb6f22   Hacene SI HADJ MOHAND   clen up
160
161
                for (auto pId : paramLinkedParams)
                    addAditionalDownloadParams(pId, false);
295de3cf   Hacene SI HADJ MOHAND   in progress
162
            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
163
164
165
166

            /**
             * @overload ParamOutput::init()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
167
168
            void DownloadOutput::init()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
169
170
                LOG4CXX_DEBUG(_logger, "DownloadOutput::init");

1a6e8df3   Erdogan Furkan   7875 - time inter...
171
172
173
174
175
176
                // init too small intervals process map
                if (isNeedToGenerateTooSmallIntervalFile())
                {
                    for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                    {
                        // get original parameter pointer
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
177
178
                        AMDA::Parameters::ParameterSPtr param = _parameterManager.getParameter(paramProperties->getOriginalId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
179
180
181
                        // get mean statistic process associated to this parameter
                        AMDA::Parameters::StatisticProcess *process = AMDA::Parameters::ServicesServer::getInstance()->getStatisticProcess(
                            "mean", *param.get(), -1);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
182

1a6e8df3   Erdogan Furkan   7875 - time inter...
183
                        // establish connection
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
184
185
                        process->establishConnection();

1a6e8df3   Erdogan Furkan   7875 - time inter...
186
                        // push process to the map
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
187
188
189
                        _tooSmallIntervalProcessMap[paramProperties->getOriginalId()].reset(process);
                    }
                }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
190

1a6e8df3   Erdogan Furkan   7875 - time inter...
191
192
193
194
195
196
                // init all needed parameters
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                {
                    try
                    {
                        // init parameter
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
197
198
199
                        LOG4CXX_DEBUG(gLogger, "DownloadOutput::init - " << paramProperties->getOutputId());
                        _parameterManager.getParameter(paramProperties->getOutputId())->init(this, _timeIntervalList);

a3eb6f22   Hacene SI HADJ MOHAND   clen up
200
                        AMDA::Parameters::ParameterSPtr param = _parameterManager.getParameter(paramProperties->getOriginalId());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
201
202

                        AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramProperties->getOriginalId());
a3eb6f22   Hacene SI HADJ MOHAND   clen up
203

1a6e8df3   Erdogan Furkan   7875 - time inter...
204
205
206
207
                        // adding tableParams
                        std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>> tables = paramInfo->getTables();
                        if (!tables.empty())
                        {
aa269fc9   Hacene SI HADJ MOHAND   ok for constant t...
208
                            _tableParamsList.push_back(paramProperties->getOriginalId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
209
210
211
212
                            for (auto table : tables)
                            {
                                if (table.second != nullptr && table.second->isVariable(&_parameterManager))
                                {
a3eb6f22   Hacene SI HADJ MOHAND   clen up
213
214
                                    std::map<std::string, std::string> tableParamIds = table.second->getTableParams(&_parameterManager);
                                    if (!tableParamIds.empty())
1a6e8df3   Erdogan Furkan   7875 - time inter...
215
216
                                        for (auto tableParamId : tableParamIds)
                                        {
a3eb6f22   Hacene SI HADJ MOHAND   clen up
217
218
219
                                            AMDA::Parameters::ParameterSPtr tableParam = _parameterManager.getParameter(tableParamId.second);
                                            if (tableParam == NULL)
                                                continue;
1a6e8df3   Erdogan Furkan   7875 - time inter...
220
221
222
                                            if ((_downloadProperties.getTimeResolution() > 0) && (_downloadProperties.getOutputStructure() != ONE_FILE_PER_PARAMETER_PER_INTERVAL))
                                            {
                                                // Use resampled table param
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
223
                                                tableParam = _parameterManager.getSampledParameter(
1a6e8df3   Erdogan Furkan   7875 - time inter...
224
225
226
227
                                                    tableParamId.second,
                                                    "classic",
                                                    _downloadProperties.getTimeResolution(),
                                                    tableParam->getGapThreshold(), true);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
228
                                            }
1a6e8df3   Erdogan Furkan   7875 - time inter...
229
230
231
                                            tableParam->init(this, _timeIntervalList);
                                            if (table.second->isFullVariable(&_parameterManager))
                                            {
ecf2e147   Benjamin Renard   Use resampled tab...
232
                                                addAditionalDownloadParams(tableParam->getId(), true);
1a6e8df3   Erdogan Furkan   7875 - time inter...
233
234
235
                                            }
                                            else
                                            {
ecf2e147   Benjamin Renard   Use resampled tab...
236
                                                _tableParamsList.push_back(tableParam->getId());
a3eb6f22   Hacene SI HADJ MOHAND   clen up
237
                                            }
ecf2e147   Benjamin Renard   Use resampled tab...
238
                                            AMDA::Info::ParamInfoSPtr tableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParam->getId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
239
240
                                            for (auto linkedParamId : tableInfo->getLinkedParamList())
                                            {
a3eb6f22   Hacene SI HADJ MOHAND   clen up
241
242
243
                                                addAditionalDownloadParams(linkedParamId, false);
                                            }
                                        }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
244
245
246
                                }
                            }
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
247
248
249
                    }
                    catch (...)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
250

1a6e8df3   Erdogan Furkan   7875 - time inter...
251
                        LOG4CXX_ERROR(_logger, "DownloadOutput::init : Error to init parameter " << paramProperties->getOutputId());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
252
253
                        std::string filePath = getFilePath(_fileWriter->getExtension());
                        if (_fileWriter->createNewFile(filePath))
1a6e8df3   Erdogan Furkan   7875 - time inter...
254
                            _fileWriter->writeError("Init Error.\nIt's impossible to initialize parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
255
256
257
                        throw;
                    }
                }
1a6e8df3   Erdogan Furkan   7875 - time inter...
258
259
260
261
262
                // init processes for too small intervals
                if (isNeedToGenerateTooSmallIntervalFile())
                {
                    for (auto process : _tooSmallIntervalProcessMap)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
263
264
265
266
267
268
269
270
                        process.second->init(_timeIntervalListTooSmall);
                    }
                }
            }

            /**
             * @overload ParamOutput::apply()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
271
272
            void DownloadOutput::apply()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
273
274
                LOG4CXX_DEBUG(_logger, "DownloadOutput::apply");

1a6e8df3   Erdogan Furkan   7875 - time inter...
275
276
                if (_fileWriter == NULL)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
277
278
279
280
                    LOG4CXX_ERROR(_logger, "DownloadOutput::apply : No file writer defined");
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
281
                // Working flags
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
282
                bool separateInfoFile = _fileWriter->isInfoInSeparateFile(
1a6e8df3   Erdogan Furkan   7875 - time inter...
283
284
285
                    _downloadProperties.getSeparateInfoFile(),
                    _timeIntervalList->size() == 1,
                    _downloadProperties.getOutputStructure());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
286

1a6e8df3   Erdogan Furkan   7875 - time inter...
287
288
                try
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
289
                    bool isFirstInterval = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
290
291
292
                    // Intervals loop
                    while (_currentTimeInterval != _timeIntervalList->end())
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
293
294
                        _currentParamId = "";
                        _currentIntervalIndex = _currentTimeInterval->_index;
1a6e8df3   Erdogan Furkan   7875 - time inter...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
                        // apply sequence in relation to the output structure
                        switch (_downloadProperties.getOutputStructure())
                        {
                        case ONE_FILE:
                        case ONE_FILE_REFPARAM:
                            applyOneFileStructure(separateInfoFile, isFirstInterval);
                            break;
                        case ONE_FILE_PER_INTERVAL:
                        case ONE_FILE_PER_INTERVAL_REFPARAM:
                            applyOneFilePerInterval(separateInfoFile, isFirstInterval);
                            break;
                        case ONE_FILE_PER_PARAMETER_PER_INTERVAL:
                            applyOneFilePerParameterPerInterval(separateInfoFile, isFirstInterval);
                            break;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
309
310
311
312
                        }

                        isFirstInterval = false;
                        ++_currentTimeInterval;
1a6e8df3   Erdogan Furkan   7875 - time inter...
313
                        // Finalize the data write in the case of a ONE_FILE or ONE_FILE_REFPARAM structure when last interval is treated
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
314
                        if ((_currentTimeInterval == _timeIntervalList->end()) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
315
316
                            ((_downloadProperties.getOutputStructure() == ONE_FILE) ||
                             (_downloadProperties.getOutputStructure() == ONE_FILE_REFPARAM)))
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
317
318
319
320
                            _fileWriter->finalize();
                    }
                    _fileWriter->closeFile();

1a6e8df3   Erdogan Furkan   7875 - time inter...
321
                    // build too small interval file if needed
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
322
323
                    if (isNeedToGenerateTooSmallIntervalFile())
                        buildTooSmallIntervalCatalog();
1a6e8df3   Erdogan Furkan   7875 - time inter...
324
325
                    if (!_tableParamsList.empty())
                    {
65414a1c   Hacene SI HADJ MOHAND   working for mav
326
                        std::string filePath = getTableInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
327
328
                        if (!_fileWriter->createNewFile(filePath))
                        {
65414a1c   Hacene SI HADJ MOHAND   working for mav
329
330
331
332
                            LOG4CXX_ERROR(_logger, "DownloadOutput::apply : Cannot create table info file " << filePath);
                            BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                        }
                        _files.push_back(filePath);
1a6e8df3   Erdogan Furkan   7875 - time inter...
333
                        // write info
65414a1c   Hacene SI HADJ MOHAND   working for mav
334
                        writeAMDAInfo();
a3eb6f22   Hacene SI HADJ MOHAND   clen up
335
336
                        _fileWriter->writeTableParamsInfo(_tableParamsList, 0);
                        _fileWriter->finalize(true);
65414a1c   Hacene SI HADJ MOHAND   working for mav
337
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
338
339
340
                }
                catch (...)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
341
342
343
344
                    _fileWriter->closeFile();
                    LOG4CXX_ERROR(_logger, "DownloadOutput::apply : Error to apply output");
                    throw;
                }
b17b9ebc   Benjamin Renard   Another fix for #...
345
            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
346
347
348
349

            /*
             * @brief Apply structure for "one-file"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
350
351
            void DownloadOutput::applyOneFileStructure(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
352
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFileStructure");
1a6e8df3   Erdogan Furkan   7875 - time inter...
353
354
355
356
357
358
                // create a data file
                if (isFirstInterval)
                {
                    if (separateInfoFile)
                    {
                        // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
359
                        std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
360
361
                        if (!_fileWriter->createNewFile(filePath))
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
362
363
364
365
                            LOG4CXX_ERROR(_logger, "DownloadOutput::applyOneFilePerInterval : Cannot create info file " << filePath);
                            BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                        }
                        _files.push_back(filePath);
1a6e8df3   Erdogan Furkan   7875 - time inter...
366
                        // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
367
368
369
370
371
                        writeInfo(false, false, true);
                    }

                    createNewDataFile();
                }
1a6e8df3   Erdogan Furkan   7875 - time inter...
372
                // write data for each parameters
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
373
374
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                    getParameterDataFromServer(paramProperties->getOutputId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
375
376
377
378
379
380
381
                // write info
                if (isFirstInterval)
                {
                    if (!separateInfoFile)
                    {
                        // write all info
                        writeInfo(true, false, false);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
382
383
                    }
                }
b17b9ebc   Benjamin Renard   Another fix for #...
384
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
385

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
386
387
388
            /*
             * @brief Apply structure for "one-file-per-interval"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
389
390
            void DownloadOutput::applyOneFilePerInterval(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
391
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFilePerInterval");
1a6e8df3   Erdogan Furkan   7875 - time inter...
392
                // create new output file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
393
394
395
396
397
                createNewDataFile();
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                    getParameterDataFromServer(paramProperties->getOutputId());

                _currentParamId = "";
1a6e8df3   Erdogan Furkan   7875 - time inter...
398
399
400
                if (separateInfoFile)
                {
                    // write only interval info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
401
                    writeInfo(true, true, false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
402
403
404
405
                }
                else
                {
                    // write all info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
406
407
408
                    writeInfo(true, false, false);
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
409
                // finalize data write
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
410
411
                _fileWriter->finalize();

1a6e8df3   Erdogan Furkan   7875 - time inter...
412
413
414
                if (separateInfoFile && isFirstInterval)
                {
                    // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
415
                    std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
416
417
                    if (!_fileWriter->createNewFile(filePath))
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
418
419
420
421
422
                        LOG4CXX_ERROR(_logger, "DownloadOutput::applyOneFilePerInterval : Cannot create info file " << filePath);
                        BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                    }
                    _files.push_back(filePath);

1a6e8df3   Erdogan Furkan   7875 - time inter...
423
                    // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
424
425
426
                    writeInfo(false, false, true);
                }
            }
16bdce87   Benjamin Renard   correction All in...
427

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
428
429
430
            /*
             * @brief Apply structure for "one-file-per-parameter-per-interval"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
431
432
            void DownloadOutput::applyOneFilePerParameterPerInterval(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
433
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFilePerParameterPerInterval");
1a6e8df3   Erdogan Furkan   7875 - time inter...
434
435
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
436
                    _currentParamId = paramProperties->getOutputId();
1a6e8df3   Erdogan Furkan   7875 - time inter...
437
                    // create output file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
438
                    createNewDataFile();
1a6e8df3   Erdogan Furkan   7875 - time inter...
439
                    // force first parameter id
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
440
441
                    _firstParamId = paramProperties->getOutputId();

1a6e8df3   Erdogan Furkan   7875 - time inter...
442
                    // write data
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
443
444
                    getParameterDataFromServer(paramProperties->getOutputId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
445
446
447
                    if (separateInfoFile)
                    {
                        // write only interval info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
448
                        writeInfo(true, true, false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
449
450
451
452
                    }
                    else
                    {
                        // write all info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
453
454
455
                        writeInfo(true, false, false);
                    }

1a6e8df3   Erdogan Furkan   7875 - time inter...
456
                    // finalize data write
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
457
458
                    _fileWriter->finalize();

1a6e8df3   Erdogan Furkan   7875 - time inter...
459
460
461
                    if (separateInfoFile && isFirstInterval)
                    {
                        // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
462
                        std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
463
464
                        if (!_fileWriter->createNewFile(filePath))
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
465
466
467
468
469
                            LOG4CXX_ERROR(_logger, "DownloadOutput::applyOneFilePerParameterPerInterval : Cannot create info file " << filePath);
                            BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                        }
                        _files.push_back(filePath);

1a6e8df3   Erdogan Furkan   7875 - time inter...
470
                        // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
471
472
473
474
                        writeInfo(false, false, true);
                    }
                }
            }
fbe3c2bb   Benjamin Renard   First commit
475

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
476
            void DownloadOutput::writeInfo(bool isWriteIntervalInfo,
1a6e8df3   Erdogan Furkan   7875 - time inter...
477
478
479
                                           bool isWriteOnlyIntervalInfo,
                                           bool isFinalizeInfoFile)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
480
481
482
                char *hideHeader;
                if ((hideHeader = getenv("HIDE_HEADER_FILE")) != NULL)
                    if (strcmp(hideHeader, "true") == 0)
1a6e8df3   Erdogan Furkan   7875 - time inter...
483
                        return; // hide header for validation tests
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
484

1a6e8df3   Erdogan Furkan   7875 - time inter...
485
486
                if (!isWriteOnlyIntervalInfo)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
487
488
489
490
491
492
493
494
495
496
                    writeAMDAInfo();
                    writeRequestInfo();
                    writeParamInfo();
                }
                if (isWriteIntervalInfo)
                    writeIntervalInfo();

                if (isFinalizeInfoFile)
                    _fileWriter->finalize(true);
            }
fbe3c2bb   Benjamin Renard   First commit
497

1a6e8df3   Erdogan Furkan   7875 - time inter...
498
499
            void DownloadOutput::writeTableInfo()
            {
fbe3c2bb   Benjamin Renard   First commit
500

1a6e8df3   Erdogan Furkan   7875 - time inter...
501
                // writeTableInfo(); comme
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
502
            }
fbe3c2bb   Benjamin Renard   First commit
503

1a6e8df3   Erdogan Furkan   7875 - time inter...
504
505
            void DownloadOutput::writeAMDAInfo(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
506
                std::string version = AMDA_Kernel_VERSION;
fbe3c2bb   Benjamin Renard   First commit
507

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
508
509
510
                char *hideVersion;
                if ((hideVersion = getenv("HIDE_VERSION")) != NULL)
                    if (strcmp(hideVersion, "true") == 0)
1a6e8df3   Erdogan Furkan   7875 - time inter...
511
                        version = "none-for-test"; // hide version number for tests
fbe3c2bb   Benjamin Renard   First commit
512

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
513
                AMDA::helpers::Properties lProperties("amda.properties");
fbe3c2bb   Benjamin Renard   First commit
514

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
515
516
                std::string createdby = lProperties["createdby"];
                std::string acknowledgement = lProperties["acknowledgement"];
fbe3c2bb   Benjamin Renard   First commit
517

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
518
519
                _fileWriter->writeAMDAInfo(version, createdby, acknowledgement);
            }
fbe3c2bb   Benjamin Renard   First commit
520

1a6e8df3   Erdogan Furkan   7875 - time inter...
521
522
            void DownloadOutput::writeRequestInfo(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
523
524
525
526
527
                std::string structure = ouputStructureToStr[_downloadProperties.getOutputStructure()];
                std::string timeFormat = ouputFormatTimeToStr[_downloadProperties.getTimeFormat()];

                std::stringstream outputParams;
                bool firstParam = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
528
529
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
530
531
532
533
534
535
536
                    if (!firstParam)
                        outputParams << ",";
                    firstParam = false;
                    outputParams << paramProperties->getOriginalId();
                }

                _fileWriter->writeRequestInfo(structure, timeFormat, _downloadProperties.getTimeResolution(),
1a6e8df3   Erdogan Furkan   7875 - time inter...
537
                                              outputParams.str(), _currentTimeInterval->_ttName);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
538
            }
fbe3c2bb   Benjamin Renard   First commit
539

1a6e8df3   Erdogan Furkan   7875 - time inter...
540
541
            void DownloadOutput::writeIntervalInfo(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
542
543
                std::stringstream startTime, stopTime;
                TimeUtil::formatTimeDateInIso(_currentTimeInterval->_startTime, startTime);
a6431512   Erdogan Furkan   Correction et ada...
544
                if (_timeIntervalList->size() > 1 && (_downloadProperties.getOutputStructure()== ONE_FILE || _downloadProperties.getOutputStructure()== ONE_FILE_REFPARAM ))
1a6e8df3   Erdogan Furkan   7875 - time inter...
545
546
547
548
549
550
                {
                    DownloadOutput::isSeveralIntervals = true;
                    _parseTimeInterval = _timeIntervalList->end();
                    _parseTimeInterval--;
                    TimeUtil::formatTimeDateInIso(_parseTimeInterval->_stopTime, stopTime);
                }
a6431512   Erdogan Furkan   Correction et ada...
551
                else
1a6e8df3   Erdogan Furkan   7875 - time inter...
552
553
554
555
556
                {
                    DownloadOutput::isSeveralIntervals = false;
                    TimeUtil::formatTimeDateInIso(_currentTimeInterval->_stopTime, stopTime);
                }
                _fileWriter->writeIntervalInfo(startTime.str(), stopTime.str(), isSeveralIntervals);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
557
            }
fbe3c2bb   Benjamin Renard   First commit
558

1a6e8df3   Erdogan Furkan   7875 - time inter...
559
560
            void DownloadOutput::writeParamInfo()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
561
                _fileWriter->writeParamsInfo(_downloadProperties.getParamPropertiesList(),
1a6e8df3   Erdogan Furkan   7875 - time inter...
562
                                             _downloadProperties.getOutputStructure(), _currentParamId);
a3eb6f22   Hacene SI HADJ MOHAND   clen up
563
                ;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
564
            }
fbe3c2bb   Benjamin Renard   First commit
565

1a6e8df3   Erdogan Furkan   7875 - time inter...
566
567
            bool DownloadOutput::isNeedToGenerateTooSmallIntervalFile()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
568
569
                return (_timeIntervalListTooSmall->empty() == false);
            }
fbe3c2bb   Benjamin Renard   First commit
570

1a6e8df3   Erdogan Furkan   7875 - time inter...
571
572
            void DownloadOutput::buildTooSmallIntervalCatalog(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
573
574
575
576
577
                if (!isNeedToGenerateTooSmallIntervalFile())
                    return;

                LOG4CXX_DEBUG(_logger, "DownloadOutput::buildTooSmallIntervalCatalog");

1a6e8df3   Erdogan Furkan   7875 - time inter...
578
                // build small intervals catalog file name
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
579
580
581
                std::ostringstream catalogName;
                catalogName << _timeIntervalListTooSmall->begin()->_ttName << "_" << _samplingValue << "_smallIntervals";

1a6e8df3   Erdogan Furkan   7875 - time inter...
582
                // create small intervals catalog file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
583
584
585
586
587
588
589
590
591
592
593
594

                _smallIntervalsCatalog._name = catalogName.str();

                if (getenv("HIDE_AMDA_DATE") != NULL)
                    _smallIntervalsCatalog._creationDate = 0;
                else
                    _smallIntervalsCatalog._creationDate = std::time(0);

                std::ostringstream description;
                description << "Time intervals are less than requested timeResolution (" << _samplingValue << ")";
                _smallIntervalsCatalog._description.push_back(description.str());

1a6e8df3   Erdogan Furkan   7875 - time inter...
595
                // add interval index description
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
596
                TimeTableCatalog::ParameterDescription indexDesc(
1a6e8df3   Erdogan Furkan   7875 - time inter...
597
598
599
600
601
602
603
604
                    "index",
                    "Interval index",
                    "1",
                    TimeTableCatalog::ParameterDescription::ParameterType::Integer,
                    "",
                    "Interval index in input TimeTable",
                    "meta.number",
                    "");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
605
606
                _smallIntervalsCatalog.addParameterDescription(indexDesc);

1a6e8df3   Erdogan Furkan   7875 - time inter...
607
                // compute mean processes for each small inetrvals and store results in the catalog file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
608
                AMDA::Parameters::TimeIntervalList::iterator currentTooSmallTimeInterval = _timeIntervalListTooSmall->begin();
1a6e8df3   Erdogan Furkan   7875 - time inter...
609
610
                while (currentTooSmallTimeInterval != _timeIntervalListTooSmall->end())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
611
612
                    TimeTableCatalog::TimeInterval crtInterval(currentTooSmallTimeInterval->_startTime, currentTooSmallTimeInterval->_stopTime);

1a6e8df3   Erdogan Furkan   7875 - time inter...
613
                    // push index for this time interval
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
614
615
616
617
                    std::vector<std::string> crtIndex;
                    crtIndex.push_back(std::to_string(currentTooSmallTimeInterval->_index));
                    crtInterval.addParameterData(std::string("index"), crtIndex);

1a6e8df3   Erdogan Furkan   7875 - time inter...
618
619
                    for (auto process : _tooSmallIntervalProcessMap)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
620
621
                        std::vector<std::string> crtResult;
                        std::vector<std::string> crtCoverage;
1a6e8df3   Erdogan Furkan   7875 - time inter...
622
                        // compute the mean
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
623
624
                        process.second->compute(crtResult, crtCoverage);

1a6e8df3   Erdogan Furkan   7875 - time inter...
625
626
627
                        if (currentTooSmallTimeInterval == _timeIntervalListTooSmall->begin())
                        {
                            // add mean processes description to the catalog
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
628
629
630
631
632
                            std::string name = "mean(";
                            name += process.first;
                            name += ")";

                            TimeTableCatalog::ParameterDescription desc(
1a6e8df3   Erdogan Furkan   7875 - time inter...
633
634
635
636
637
638
639
640
                                process.first,
                                name,
                                process.second->getResultDimDefinition(),
                                TimeTableCatalog::ParameterDescription::ParameterType::Double,
                                "",
                                "Mean of the parameter in the interval",
                                process.second->getUCD(),
                                "");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
641
642
643
                            _smallIntervalsCatalog.addParameterDescription(desc);
                        }

1a6e8df3   Erdogan Furkan   7875 - time inter...
644
                        // push result for this time interval
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
645
646
647
                        crtInterval.addParameterData(process.first, crtResult);
                    }

1a6e8df3   Erdogan Furkan   7875 - time inter...
648
                    // add interval to the catalog
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
649
650
                    _smallIntervalsCatalog.addInterval(crtInterval);

1a6e8df3   Erdogan Furkan   7875 - time inter...
651
                    // go to the next too small interval
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
652
653
654
                    ++currentTooSmallTimeInterval;
                }
            }
fbe3c2bb   Benjamin Renard   First commit
655

1a6e8df3   Erdogan Furkan   7875 - time inter...
656
657
658
            void DownloadOutput::terminate(void)
            {
                // write the catalog file
fbe3c2bb   Benjamin Renard   First commit
659

1a6e8df3   Erdogan Furkan   7875 - time inter...
660
661
                if (isNeedToGenerateTooSmallIntervalFile())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
662
663
                    std::string ttPath = _timeIntervalList->begin()->_ttPath;
                    _smallIntervalsCatalog.write(_workPath,
1a6e8df3   Erdogan Furkan   7875 - time inter...
664
665
                                                 TimeTableCatalog::TimeTableCatalogFactory::getInstance().getReaderType(ttPath));
                    // add the catalog file to the output files list
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
666
667
668
                    boost::filesystem::path ttp(ttPath);
                    _files.push_back(_smallIntervalsCatalog._name + ttp.extension().string());
                }
fbe3c2bb   Benjamin Renard   First commit
669

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
670
671
                ParamOutput::terminate();
            }
fbe3c2bb   Benjamin Renard   First commit
672

1a6e8df3   Erdogan Furkan   7875 - time inter...
673
674
            void DownloadOutput::createNewDataFile(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
675
                std::string filePath = getFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
676
677
                if (!_fileWriter->createNewFile(filePath))
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
678
679
680
681
682
683
                    LOG4CXX_ERROR(_logger, "DownloadOutput::createNewDataFile : Cannot create output file " << filePath);
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                }
                _files.push_back(filePath);
                _paramDefinedInFile.clear();
            }
fbe3c2bb   Benjamin Renard   First commit
684

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
685
686
687
            /*
             * @brief Create parameters in relation with the download properties
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
688
689
            void DownloadOutput::createParameters(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
690
691
                LOG4CXX_DEBUG(_logger, "DownloadOutput::createParameters");

1a6e8df3   Erdogan Furkan   7875 - time inter...
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
                switch (_downloadProperties.getOutputStructure())
                {
                case ONE_FILE:
                case ONE_FILE_REFPARAM:
                case ONE_FILE_PER_INTERVAL:
                case ONE_FILE_PER_INTERVAL_REFPARAM:
                    if (_downloadProperties.getParamPropertiesList().size() == 1)
                    {
                        // only one paramter defined in the request
                        try
                        {
                            // get original parameter
                            AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(
                                _downloadProperties.getParamPropertiesList()[0]->getOriginalId());

                            if (_downloadProperties.getTimeResolution() == 0)
                            {
                                // only one parameter and no time resolution defined => keep original parameter
                                _downloadProperties.getParamPropertiesList()[0]->setOutputId(
                                    _downloadProperties.getParamPropertiesList()[0]->getOriginalId());
                                _firstParamId = _downloadProperties.getParamPropertiesList()[0]->getOriginalId();
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
713
                            }
1a6e8df3   Erdogan Furkan   7875 - time inter...
714
715
716
717
718
719
720
721
722
723
724
725
                            else
                            {
                                // only one parameter but time resolution defined => resample the parameter
                                AMDA::Parameters::ParameterSPtr resampledParam = _parameterManager.getSampledParameter(
                                    originalParam->getId(),
                                    "classic",
                                    _downloadProperties.getTimeResolution(),
                                    originalParam->getGapThreshold(), true);
                                // set the resampled parameter id
                                _downloadProperties.getParamPropertiesList()[0]->setOutputId(resampledParam->getId());
                                _firstParamId = resampledParam->getId();
                                _samplingValue = _downloadProperties.getTimeResolution();
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
726
                            }
1a6e8df3   Erdogan Furkan   7875 - time inter...
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
                        }
                        catch (...)
                        {
                            std::string filePath = getFilePath(_fileWriter->getExtension());
                            if (_fileWriter->createNewFile(filePath))
                                _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + _downloadProperties.getParamPropertiesList()[0]->getOriginalId() + "\".");
                            throw;
                        }
                    }
                    else
                    {
                        double samplingTime = _downloadProperties.getTimeResolution();
                        if ((samplingTime == 0) &&
                            ((_downloadProperties.getOutputStructure() == ONE_FILE) ||
                             (_downloadProperties.getOutputStructure() == ONE_FILE_PER_INTERVAL)))
                        {
                            // no time resolution defined with outputStructure ONE_FILE or ONE_FILE_PER_PARAMETER_PER_INTERVAL
                            //=> get max parameters sampling time
                            for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                            {
                                try
                                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
749
                                    AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(paramProperties->getOriginalId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
750
751
752
753
                                    samplingTime = std::max(samplingTime, getSamplingInTreeParameter(originalParam));
                                }
                                catch (...)
                                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
754
755
                                    std::string filePath = getFilePath(_fileWriter->getExtension());
                                    if (_fileWriter->createNewFile(filePath))
1a6e8df3   Erdogan Furkan   7875 - time inter...
756
                                        _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
757
758
759
760
                                    throw;
                                }
                            }
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
761
762
763
764

                        _samplingValue = samplingTime;

                        // create resampled parameters for all parameters defined in the request
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
765
                        bool isFirstParam = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
766
767
768
769
770
771
                        AMDA::Parameters::ParameterSPtr firstParam;
                        for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                        {
                            try
                            {
                                // get original parameter
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
772
773
                                AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(paramProperties->getOriginalId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
                                // Create resampled parameter
                                AMDA::Parameters::ParameterSPtr resampledParam;
                                if (_samplingValue > 0)
                                {
                                    resampledParam = _parameterManager.getSampledParameter(
                                        paramProperties->getOriginalId(),
                                        "classic",
                                        samplingTime,
                                        originalParam->getGapThreshold(), true);

                                    // set the resampled parameter id
                                    paramProperties->setOutputId(resampledParam->getId());

                                    if (isFirstParam)
                                    {
                                        _firstParamId = resampledParam->getId();
                                        firstParam = resampledParam;
                                    }
                                }
                                else
                                {
                                    // use resampled parameter under first parameter time definition
                                    if (isFirstParam)
                                    {
                                        // first parameter => no resampling
                                        // set the original parameter id
                                        paramProperties->setOutputId(paramProperties->getOriginalId());
                                        _firstParamId = paramProperties->getOriginalId();
                                        firstParam = originalParam;
                                    }
                                    else
                                    {
                                        resampledParam = _parameterManager.getSampledParameterUnderRefParam(
                                            originalParam->getId(),
                                            firstParam->getId(), true);

                                        // set the resampled parameter id
                                        paramProperties->setOutputId(resampledParam->getId());
                                    }
                                }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
814
                                isFirstParam = false;
1a6e8df3   Erdogan Furkan   7875 - time inter...
815
816
817
                            }
                            catch (...)
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
818
819
                                std::string filePath = getFilePath(_fileWriter->getExtension());
                                if (_fileWriter->createNewFile(filePath))
1a6e8df3   Erdogan Furkan   7875 - time inter...
820
                                    _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
821
822
823
824
                                throw;
                            }
                        }
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
                    break;
                case ONE_FILE_PER_PARAMETER_PER_INTERVAL:
                {
                    bool isFirstParam = true;
                    for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                    {
                        try
                        {
                            // get original parameter
                            AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(paramProperties->getOriginalId());

                            paramProperties->setOutputId(paramProperties->getOriginalId());
                            if (isFirstParam)
                                _firstParamId = paramProperties->getOriginalId();
                            isFirstParam = false;
                        }
                        catch (...)
                        {
                            std::string filePath = getFilePath(_fileWriter->getExtension());
                            if (_fileWriter->createNewFile(filePath))
                                _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
                            throw;
                        }
                    }
                }
                break;
                default:
                    LOG4CXX_ERROR(_logger, "DownloadOutput::createParameters : Output structure not implemented");
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
854
855
856
857
858
859
                }
            }

            /*
             * @brief create file writer associated to the requested file format
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
860
861
            void DownloadOutput::createFileWriter(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
862
863
864
                if (_fileWriter != NULL)
                    delete _fileWriter;

1a6e8df3   Erdogan Furkan   7875 - time inter...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
                switch (_downloadProperties.getFileFormat())
                {
                case ASCII_FILE_FORMAT:
                    _fileWriter = new FileWriter::FileWriterASCIITabular(_parameterManager);
                    _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
                    break;
                case JSON_FILE_FORMAT:
                    _fileWriter = new FileWriter::FileWriterASCIIJson(_parameterManager);
                    _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
                    break;
                case VOT_FILE_FORMAT:
                    _fileWriter = new FileWriter::FileWriterASCIIVOTable(_parameterManager);
                    _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
                    break;
                case CDF_FILE_FORMAT:
                    _fileWriter = new FileWriter::FileWriterCDF(_parameterManager);
                    _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
                    break;
                default:
                    LOG4CXX_ERROR(_logger, "DownloadOutput::createFileWriter : File format not implemented");
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
886
887
888
889
890
891
                }
            }

            /*
             * @brief Get file path in relation with the sequence step
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
892
893
894
            std::string DownloadOutput::getFilePath(std::string extension, bool infoFile)
            {
                // create workspace dir if needed
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
895
                int ret = AMDA::Helpers::Helper::mkdir(_workPath.c_str());
1a6e8df3   Erdogan Furkan   7875 - time inter...
896
897
                if (ret)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
898
899
900
                    const size_t buflen = 250;
                    char buf[250];
                    LOG4CXX_ERROR(_logger,
1a6e8df3   Erdogan Furkan   7875 - time inter...
901
                                  "Create working directory \"" << _workPath << "\"error : " << strerror_r(ret, buf, buflen));
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
902
903
904
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
905
                // create full file path
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
906
907
908
909
910
911
                std::stringstream filePath;
                filePath << _workPath;

                filePath << "/";

                std::stringstream fileName;
1a6e8df3   Erdogan Furkan   7875 - time inter...
912
913
                if (_downloadProperties.getFileName().empty())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
914
                    fileName << "output-";
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
915

1a6e8df3   Erdogan Furkan   7875 - time inter...
916
                    // add parameters ids
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
917
                    bool firstParam = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
918
919
920
921
922
                    for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                    {
                        if (!_currentParamId.empty())
                        {
                            // add only current parameter id
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
923
924
925
                            if (_currentParamId != paramProperties->getOutputId())
                                continue;
                        }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
926

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
927
928
929
                        if (!firstParam)
                            fileName << "_";
                        firstParam = false;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
930

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
931
932
                        fileName << paramProperties->getOriginalId();

1a6e8df3   Erdogan Furkan   7875 - time inter...
933
934
935
                        // add indexes
                        for (auto index : paramProperties->getIndexDefList())
                        {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
936
937
938
939
940
                            boost::replace_all(index, "[", "");
                            boost::replace_all(index, "]", "");
                            boost::replace_all(index, "*", "x");
                            fileName << "_" << index;
                        }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
941
                    }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
942

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
943
                    std::stringstream fileNameSuffix;
1a6e8df3   Erdogan Furkan   7875 - time inter...
944
945
                    if (!infoFile)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
946
                        if ((_downloadProperties.getOutputStructure() != ONE_FILE) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
947
948
949
950
                            (_downloadProperties.getOutputStructure() != ONE_FILE_REFPARAM) &&
                            (_parameterManager.getInputIntervals()->size() != 1))
                        {
                            // add interval index
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
951
                            fileNameSuffix << "_" << _currentTimeInterval->_ttName;
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
952
                            fileNameSuffix << "_" << _currentIntervalIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
953
954
955
956
957
958
                        }
                        else
                        {
                            if (_currentTimeInterval->_ttName.empty())
                            {
                                // add start time
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
959
960
961
962
                                double lStartTime = _currentTimeInterval->_startTime;
                                char buffer[TIMELENGTH];
                                Double2DD_Time(buffer, lStartTime);
                                fileNameSuffix << "_" << buffer;
1a6e8df3   Erdogan Furkan   7875 - time inter...
963
964
965
966
                            }
                            else
                            {
                                // add TT name
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
967
968
                                fileNameSuffix << "_" << _currentTimeInterval->_ttName;
                            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
969
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
970
971
                    }
                    else
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
972
                        fileNameSuffix << "_info";
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
973

1a6e8df3   Erdogan Furkan   7875 - time inter...
974
975
976
                    // check fileName size
                    if (fileName.str().size() + extension.size() + 1 + fileNameSuffix.str().size() > 100)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
977
                        filePath << fileName.str().substr(0, 100 - extension.size() - 1 - fileNameSuffix.str().size()) << fileNameSuffix.str();
1a6e8df3   Erdogan Furkan   7875 - time inter...
978
979
980
                    }
                    else
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
981
982
                        filePath << fileName.str() << fileNameSuffix.str();
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
983
984
985
986
987
                }
                else
                {
                    if (!infoFile)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
988
                        if ((_downloadProperties.getOutputStructure() != ONE_FILE) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
989
990
991
992
993
994
995
996
997
998
999
1000
1001
                            (_downloadProperties.getOutputStructure() != ONE_FILE_REFPARAM) &&
                            (_parameterManager.getInputIntervals()->size() != 1))
                        {
                            std::stringstream fileNameSuffix;
                            // add interval index
                            fileNameSuffix << _currentIntervalIndex;
                            filePath << _downloadProperties.getFileName() << fileNameSuffix.str();
                        }
                        else
                            filePath << _downloadProperties.getFileName();
                    }
                    else
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1002
1003
                        filePath << _downloadProperties.getFileName() << "_info";
                    }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1004
1005
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
1006
                // add extension
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1007
1008
1009
1010
1011
1012
1013
1014
1015
                filePath << ".";
                filePath << extension;

                return filePath.str();
            }

            /*
             * @brief Get file info path in relation with the sequence step (only used if info is written is separate file)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1016
1017
            std::string DownloadOutput::getInfoFilePath(std::string extension)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1018
1019
                return getFilePath(extension, true);
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
1020
1021

            /*
65414a1c   Hacene SI HADJ MOHAND   working for mav
1022
             * @brief Get file info path in relation with the sequence step (only used if info is written is separate file)
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1023
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1024
1025
            std::string DownloadOutput::getTableInfoFilePath(std::string extension)
            {
a3eb6f22   Hacene SI HADJ MOHAND   clen up
1026
                std::string suffix = "_table";
65414a1c   Hacene SI HADJ MOHAND   working for mav
1027
                std::string path = getInfoFilePath(extension);
a3eb6f22   Hacene SI HADJ MOHAND   clen up
1028
1029
1030
                int pos = path.size() - extension.size() - 1;
                pos = std::max(pos, 0);
                path.insert(pos, suffix);
65414a1c   Hacene SI HADJ MOHAND   working for mav
1031
                return path;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1032
1033
            }

1a6e8df3   Erdogan Furkan   7875 - time inter...
1034
1035
1036
1037
            void DownloadOutput::getParameterDataFromServer(std::string paramId)
            {
                try
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1038
                    _currentParamId = paramId;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1039
1040
1041
1042
                    do
                    {
                        try
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1043
                            _paramDataIndexInfo = _parameterManager.getParameter(paramId)->getAsync(this).get();
1a6e8df3   Erdogan Furkan   7875 - time inter...
1044
1045
1046
                        }
                        catch (...)
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1047
1048
1049
                            BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                            throw;
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
1050
1051
1052
1053
                        if (_paramDataIndexInfo._nbDataToProcess > 0)
                        {
                            try
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1054
                                _parameterManager.getParameter(paramId)->getParamData(this)->accept(*this);
1a6e8df3   Erdogan Furkan   7875 - time inter...
1055
1056
1057
                            }
                            catch (AMDA::AMDA_exception &e)
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1058
1059
1060
1061
1062
                                e << AMDA::errno_code(AMDA_PARAM_OUTPUT_ERR);
                                throw;
                            }
                        }
                    } while (!_paramDataIndexInfo._noMoreTimeInt && !_paramDataIndexInfo._timeIntToProcessChanged);
1a6e8df3   Erdogan Furkan   7875 - time inter...
1063
1064
1065
1066
                }
                catch (...)
                {
                    _fileWriter->writeError("apply Error.\nIt's impossible to get or write data of  parameter: \"" + paramId + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1067
1068
1069
1070
1071
                    throw;
                }
            }

            void DownloadOutput::addParameterInFile(std::string paramId,
1a6e8df3   Erdogan Furkan   7875 - time inter...
1072
1073
1074
1075
1076
                                                    FileWriter::FileDataType type, bool isFirstParam, int dim1Size, int dim2Size)
            {
                if (!_paramDefinedInFile[paramId])
                {
                    ParamProperties *prop = _downloadProperties.getParamPropertiesFromOutputId(paramId);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1077
1078
1079
1080
1081
                    _fileWriter->addParameter(prop, _paramsIndexList[paramId], type, isFirstParam, dim1Size, dim2Size);
                }
                _paramDefinedInFile[paramId] = true;
            }

1a6e8df3   Erdogan Furkan   7875 - time inter...
1082
1083
            void DownloadOutput::buildParamIndexes(std::string paramId, int dim1Size, int dim2Size)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1084
                _paramsIndexList[paramId].clear();
1a6e8df3   Erdogan Furkan   7875 - time inter...
1085
1086
1087
1088
1089
1090
1091
1092
                for (auto paramProp : _downloadProperties.getParamPropertiesList())
                {
                    if (paramProp->getOutputId() == paramId)
                    {
                        for (auto indexDef : paramProp->getIndexDefList())
                        {
                            if (!AMDA::Common::ParameterIndexesTool::parse(indexDef, dim1Size, dim2Size, _paramsIndexList[paramId]))
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1093
                                ERROR_EXCEPTION(
1a6e8df3   Erdogan Furkan   7875 - time inter...
1094
                                    "DownloadOutput of: '" << paramId << "' index: " << indexDef << " out of range");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
                            }
                        }
                        break;
                    }
                }

                if (_paramsIndexList[paramId].empty())
                    AMDA::Common::ParameterIndexesTool::parse("", dim1Size, dim2Size, _paramsIndexList[paramId]);
            }

            /***************************** VISITORS ********************************/

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1110
1111
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1112
1113
1114
1115
1116
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_SHORT, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1117
1118
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1119
1120
1121
1122
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeShortData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1123
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1124
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1125
1126
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1127
1128
1129
1130
1131
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1132
1133
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1134
1135
1136
1137
1138
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_FLOAT, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1139
1140
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1141
1142
1143
1144
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeFloatData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1145
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1146
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1147
1148
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1149
1150
1151
1152
1153
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1154
1155
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1156
1157
1158
1159
1160
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_DOUBLE, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1161
1162
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1163
1164
1165
1166
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeDoubleData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1167
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1168
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1169
1170
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1171
1172
1173
1174
1175
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1176
1177
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireLongDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1178
1179
1180
1181
1182
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LONGDOUBLE, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1183
1184
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1185
1186
1187
1188
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeLongDoubleData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1189
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1190
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1191
1192
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1193
1194
1195
1196
1197
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1198
1199
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireInt *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1200
1201
1202
1203
1204
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_INT, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1205
1206
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1207
1208
1209
1210
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeIntData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1211
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1212
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1213
1214
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1215
1216
1217
1218
1219
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1220
1221
            void DownloadOutput::visit(AMDA::Parameters::ParamDataLogicalData *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1222
1223
1224
1225
1226
                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LOGICAL, isFirstParam);

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1227
1228
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1229
1230
1231
1232
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    _fileWriter->writeLogicalData(_currentParamId, 0, pParamData->get(index), _downloadProperties.getPrecision());
7929a8a9   Benjamin Renard   CDF writer optimi...
1233
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1234
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1235
1236
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1237
1238
1239
1240
1241
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1242
1243
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1244
1245
1246
1247
1248
1249
1250
1251
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_SHORT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1252
1253
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1254
1255
1256
1257
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1258
1259
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1260
1261
1262
                        _fileWriter->writeShortData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1263
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1264
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1265
1266
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1267
1268
1269
1270
1271
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1272
1273
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1274
1275
1276
1277
1278
1279
1280
1281
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_FLOAT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1282
1283
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1284
1285
1286
1287
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1288
1289
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1290
1291
1292
                        _fileWriter->writeFloatData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1293
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1294
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1295
1296
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1297
1298
1299
1300
1301
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1302
1303
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1304
1305
1306
1307
1308
1309
1310
1311
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_DOUBLE, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1312
1313
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1314
1315
1316
1317
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1318
1319
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1320
1321
1322
                        _fileWriter->writeDoubleData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1323
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1324
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1325
1326
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1327
1328
1329
1330
1331
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1332
1333
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DLongDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1334
1335
1336
1337
1338
1339
1340
1341
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LONGDOUBLE, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1342
1343
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1344
1345
1346
1347
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1348
1349
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1350
1351
1352
                        _fileWriter->writeLongDoubleData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1353
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1354
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1355
1356
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1357
1358
1359
1360
1361
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1362
1363
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DInt *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1364
1365
1366
1367
1368
1369
1370
1371
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_INT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1372
1373
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1374
1375
1376
1377
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1378
1379
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1380
1381
1382
                        _fileWriter->writeIntData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1383
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1384
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1385
1386
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1387
1388
1389
1390
1391
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1392
1393
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DLogicalData *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1394
1395
1396
1397
1398
1399
1400
1401
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LOGICAL, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1402
1403
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1404
1405
1406
1407
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1408
1409
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1410
1411
1412
                        _fileWriter->writeLogicalData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1413
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1414
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1415
1416
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1417
1418
1419
1420
1421
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1422
1423
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1424
1425
1426
1427
1428
1429
1430
1431
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_SHORT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1432
1433
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1434
1435
1436
1437
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1438
1439
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1440
1441
1442
1443
                        short val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeShortData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1444
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1445
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1446
1447
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1448
1449
1450
1451
1452
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1453
1454
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1455
1456
1457
1458
1459
1460
1461
1462
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_FLOAT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1463
1464
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1465
1466
1467
1468
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1469
1470
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1471
1472
1473
1474
                        float val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeFloatData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1475
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1476
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1477
1478
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1479
1480
1481
1482
1483
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1484
1485
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1486
1487
1488
1489
1490
1491
1492
1493
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_DOUBLE, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1494
1495
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1496
1497
1498
1499
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1500
1501
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1502
1503
1504
1505
                        double val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeDoubleData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1506
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1507
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1508
1509
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1510
1511
1512
1513
1514
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1515
1516
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DLongDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1517
1518
1519
1520
1521
1522
1523
1524
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LONGDOUBLE, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1525
1526
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1527
1528
1529
1530
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1531
1532
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1533
1534
1535
1536
                        long double val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeLongDoubleData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1537
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1538
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1539
1540
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1541
1542
1543
1544
1545
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1546
1547
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DInt *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1548
1549
1550
1551
1552
1553
1554
1555
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_INT, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1556
1557
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1558
1559
1560
1561
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1562
1563
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1564
1565
1566
1567
                        int val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeIntData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1568
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1569
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1570
1571
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1572
1573
1574
1575
1576
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1577
1578
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DLogicalData *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1579
1580
1581
1582
1583
1584
1585
1586
                if (_paramsIndexList[_currentParamId].empty())
                    buildParamIndexes(_currentParamId, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                bool isFirstParam = (_currentParamId == _firstParamId);

                addParameterInFile(_currentParamId, FileWriter::FileDataType::DT_LOGICAL, isFirstParam, pParamData->get(_paramDataIndexInfo._startIndex).getDim1Size(), pParamData->get(_paramDataIndexInfo._startIndex).getDim2Size());

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1587
1588
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1589
1590
1591
1592
                    if (pParamData->getTime(index) > _currentTimeInterval->_stopTime)
                        return;
                    _fileWriter->writeTimeData(_currentParamId, pParamData->getTime(index), _downloadProperties.getTimeFormat(), isFirstParam);
                    int varIndex = 0;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1593
1594
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1595
1596
1597
1598
                        AMDA::Parameters::LogicalData val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeLogicalData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1599
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1600
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1601
1602
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1603
1604
1605
            }

        } /* namespace Download */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1606
    }     /* namespace ParamOutputImpl */
fbe3c2bb   Benjamin Renard   First commit
1607
} /* namespace AMDA */