Blame view

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

#include "DownloadOutput.hh"
#include "FileWriterASCIITabular.hh"
#include "FileWriterASCIIJson.hh"
#include "FileWriterASCIIVOTable.hh"
#include "FileWriterCDF.hh"
9e1bbe22   Benjamin Renard   Skeleton to imple...
13
#include "FileWriterCDFISTP.hh"
fbe3c2bb   Benjamin Renard   First commit
14
#include "Helper.hh"
3e19e9d5   Hacene SI HADJ MOHAND   completly vriable...
15
#include "Process.hh"
fbe3c2bb   Benjamin Renard   First commit
16
17
18
#include "Properties.hh"
#include "TimeUtil.hh"
#include "AMDA-Kernel_Config.hh"
5a7c3896   Hacene SI HADJ MOHAND   adding tableParam...
19
#include "Parameter.hh"
79366e37   Hacene SI HADJ MOHAND   trying to add ful...
20
#include <algorithm>
fbe3c2bb   Benjamin Renard   First commit
21
22
23
24
25
26
27
28
29
#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...
30
31
using namespace std::chrono;

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

        /**
         * @brief Implement ParamOutput to download parameters data in files.
         */
1a6e8df3   Erdogan Furkan   7875 - time inter...
40
41
42
43
44
45
46
47
48
49
50
        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
51
            }
fbe3c2bb   Benjamin Renard   First commit
52

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

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

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

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

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
86
87
                    try
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
88
89
90
91
92
                        _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...
93
94
95
96
97
98
99
100
101
102
                        // 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))
                                    {
5291eadc   Erdogan Furkan   For now - Ca avance
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
                                        AMDA::Parameters::ParameterSPtr tableParam = table.second->createRelatedParameter(&_parameterManager);

                                        if ((_downloadProperties.getTimeResolution() > 0) && (_downloadProperties.getOutputStructure() != ONE_FILE_PER_PARAMETER_PER_INTERVAL))
                                        {
                                            // Use resampled table param
                                            tableParam = _parameterManager.getSampledParameter(
                                                tableParam->getId(),
                                                "classic",
                                                _downloadProperties.getTimeResolution(),
                                                tableParam->getGapThreshold(), true);
                                        }
                                        
                                        tableParam->openConnection(this);
                                        ParamProperties *tableParamProperties = new ParamProperties();
                                        tableParamProperties->setOriginalId(tableParam->getId());
                                        tableParamProperties->setOutputId(tableParam->getId());
                                        _downloadProperties.addTableParamProperties(tableParamProperties);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
120
121
                                    }
                                }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
122
                            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
123
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
124
125
126
                    }
                    catch (...)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
127
                        LOG4CXX_ERROR(_logger, "DownloadOutput::establishConnection - It's impossible to open connection for " << paramProperties->getOutputId());
256d4fda   Furkan   The end is close
128
129
130
                        std::string filePrefix;
                        std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                        if (_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
131
                            _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
132
133
134
                        throw;
                    }
                }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
135
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
136

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
137
138
139
            /**
             * @overload ParamOutput::init()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
140
141
            void DownloadOutput::init()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
142
143
                LOG4CXX_DEBUG(_logger, "DownloadOutput::init");

1a6e8df3   Erdogan Furkan   7875 - time inter...
144
145
146
147
148
149
                // 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
150
151
                        AMDA::Parameters::ParameterSPtr param = _parameterManager.getParameter(paramProperties->getOriginalId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
152
153
154
                        // 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
155

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
159
                        // push process to the map
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
160
161
162
                        _tooSmallIntervalProcessMap[paramProperties->getOriginalId()].reset(process);
                    }
                }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
163

1a6e8df3   Erdogan Furkan   7875 - time inter...
164
                // init all needed parameters
5291eadc   Erdogan Furkan   For now - Ca avance
165
                for (auto paramProperties : _downloadProperties.getAllParamPropertiesList())
1a6e8df3   Erdogan Furkan   7875 - time inter...
166
167
168
169
                {
                    try
                    {
                        // init parameter
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
170
171
172
                        LOG4CXX_DEBUG(gLogger, "DownloadOutput::init - " << paramProperties->getOutputId());
                        _parameterManager.getParameter(paramProperties->getOutputId())->init(this, _timeIntervalList);

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
173
                        AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramProperties->getOriginalId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
174
175
                        // adding tableParams
                        std::map<int, boost::shared_ptr<AMDA::Info::ParamTable>> tables = paramInfo->getTables();
1453b252   Erdogan Furkan   Some minor modifi...
176

1a6e8df3   Erdogan Furkan   7875 - time inter...
177
178
                        if (!tables.empty())
                        {
aa269fc9   Hacene SI HADJ MOHAND   ok for constant t...
179
                            _tableParamsList.push_back(paramProperties->getOriginalId());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
180
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
181
182
183
                    }
                    catch (...)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
184

1a6e8df3   Erdogan Furkan   7875 - time inter...
185
                        LOG4CXX_ERROR(_logger, "DownloadOutput::init : Error to init parameter " << paramProperties->getOutputId());
256d4fda   Furkan   The end is close
186
187
188
                        std::string filePrefix;
                        std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                        if (_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
189
                            _fileWriter->writeError("Init Error.\nIt's impossible to initialize parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
190
191
192
                        throw;
                    }
                }
1a6e8df3   Erdogan Furkan   7875 - time inter...
193
194
195
196
197
                // init processes for too small intervals
                if (isNeedToGenerateTooSmallIntervalFile())
                {
                    for (auto process : _tooSmallIntervalProcessMap)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
198
199
200
201
202
203
204
205
                        process.second->init(_timeIntervalListTooSmall);
                    }
                }
            }

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
210
211
                if (_fileWriter == NULL)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
212
213
214
215
                    LOG4CXX_ERROR(_logger, "DownloadOutput::apply : No file writer defined");
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
216
                // Working flags
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
217
                bool separateInfoFile = _fileWriter->isInfoInSeparateFile(
1a6e8df3   Erdogan Furkan   7875 - time inter...
218
219
220
                    _downloadProperties.getSeparateInfoFile(),
                    _timeIntervalList->size() == 1,
                    _downloadProperties.getOutputStructure());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
221

1a6e8df3   Erdogan Furkan   7875 - time inter...
222
223
                try
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
224
                    bool isFirstInterval = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
225
226
227
                    // Intervals loop
                    while (_currentTimeInterval != _timeIntervalList->end())
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
228
229
                        _currentParamId = "";
                        _currentIntervalIndex = _currentTimeInterval->_index;
1a6e8df3   Erdogan Furkan   7875 - time inter...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
                        // 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
244
245
246
247
                        }

                        isFirstInterval = false;
                        ++_currentTimeInterval;
1a6e8df3   Erdogan Furkan   7875 - time inter...
248
                        // 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
249
                        if ((_currentTimeInterval == _timeIntervalList->end()) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
250
251
                            ((_downloadProperties.getOutputStructure() == ONE_FILE) ||
                             (_downloadProperties.getOutputStructure() == ONE_FILE_REFPARAM)))
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
252
253
254
255
                            _fileWriter->finalize();
                    }
                    _fileWriter->closeFile();

1a6e8df3   Erdogan Furkan   7875 - time inter...
256
                    // build too small interval file if needed
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
257
258
                    if (isNeedToGenerateTooSmallIntervalFile())
                        buildTooSmallIntervalCatalog();
1453b252   Erdogan Furkan   Some minor modifi...
259
                    if (!_tableParamsList.empty() && _fileWriter->getExtension() != "cdf")
1a6e8df3   Erdogan Furkan   7875 - time inter...
260
                    {
65414a1c   Hacene SI HADJ MOHAND   working for mav
261
                        std::string filePath = getTableInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
262
263
                        if (!_fileWriter->createNewFile(filePath))
                        {
65414a1c   Hacene SI HADJ MOHAND   working for mav
264
265
266
267
                            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...
268
                        // write info
65414a1c   Hacene SI HADJ MOHAND   working for mav
269
                        writeAMDAInfo();
a3eb6f22   Hacene SI HADJ MOHAND   clen up
270
271
                        _fileWriter->writeTableParamsInfo(_tableParamsList, 0);
                        _fileWriter->finalize(true);
65414a1c   Hacene SI HADJ MOHAND   working for mav
272
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
273
274
275
                }
                catch (...)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
276
277
278
279
                    _fileWriter->closeFile();
                    LOG4CXX_ERROR(_logger, "DownloadOutput::apply : Error to apply output");
                    throw;
                }
b17b9ebc   Benjamin Renard   Another fix for #...
280
            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
281
282
283
284

            /*
             * @brief Apply structure for "one-file"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
285
286
            void DownloadOutput::applyOneFileStructure(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
287
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFileStructure");
1a6e8df3   Erdogan Furkan   7875 - time inter...
288
289
290
291
292
293
                // create a data file
                if (isFirstInterval)
                {
                    if (separateInfoFile)
                    {
                        // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
294
                        std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
295
296
                        if (!_fileWriter->createNewFile(filePath))
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
297
298
299
300
                            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...
301
                        // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
302
303
304
305
306
                        writeInfo(false, false, true);
                    }

                    createNewDataFile();
                }
1a6e8df3   Erdogan Furkan   7875 - time inter...
307
                // write data for each parameters
5291eadc   Erdogan Furkan   For now - Ca avance
308
                for (auto paramProperties : _downloadProperties.getAllParamPropertiesList())
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
309
                    getParameterDataFromServer(paramProperties->getOutputId());
26dc55e4   Erdogan Furkan   For now
310

1a6e8df3   Erdogan Furkan   7875 - time inter...
311
312
313
314
315
316
317
                // write info
                if (isFirstInterval)
                {
                    if (!separateInfoFile)
                    {
                        // write all info
                        writeInfo(true, false, false);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
318
319
                    }
                }
b17b9ebc   Benjamin Renard   Another fix for #...
320
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
321

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
322
323
324
            /*
             * @brief Apply structure for "one-file-per-interval"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
325
326
            void DownloadOutput::applyOneFilePerInterval(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
327
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFilePerInterval");
1a6e8df3   Erdogan Furkan   7875 - time inter...
328
                // create new output file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
329
                createNewDataFile();
5291eadc   Erdogan Furkan   For now - Ca avance
330
                for (auto paramProperties : _downloadProperties.getAllParamPropertiesList())
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
331
332
333
                    getParameterDataFromServer(paramProperties->getOutputId());

                _currentParamId = "";
1a6e8df3   Erdogan Furkan   7875 - time inter...
334
335
336
                if (separateInfoFile)
                {
                    // write only interval info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
337
                    writeInfo(true, true, false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
338
339
340
341
                }
                else
                {
                    // write all info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
342
343
344
                    writeInfo(true, false, false);
                }

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
348
349
350
                if (separateInfoFile && isFirstInterval)
                {
                    // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
351
                    std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
352
353
                    if (!_fileWriter->createNewFile(filePath))
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
354
355
356
357
358
                        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...
359
                    // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
360
361
362
                    writeInfo(false, false, true);
                }
            }
16bdce87   Benjamin Renard   correction All in...
363

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
364
365
366
            /*
             * @brief Apply structure for "one-file-per-parameter-per-interval"
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
367
368
            void DownloadOutput::applyOneFilePerParameterPerInterval(bool separateInfoFile, bool isFirstInterval)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
369
                LOG4CXX_DEBUG(_logger, "DownloadOutput::applyOneFilePerParameterPerInterval");
26dc55e4   Erdogan Furkan   For now
370
                for (auto paramProperties : _downloadProperties.getAllParamPropertiesList())
1a6e8df3   Erdogan Furkan   7875 - time inter...
371
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
372
                    _currentParamId = paramProperties->getOutputId();
1a6e8df3   Erdogan Furkan   7875 - time inter...
373
                    // create output file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
374
                    createNewDataFile();
1a6e8df3   Erdogan Furkan   7875 - time inter...
375
                    // force first parameter id
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
376
377
                    _firstParamId = paramProperties->getOutputId();

1a6e8df3   Erdogan Furkan   7875 - time inter...
378
                    // write data
5291eadc   Erdogan Furkan   For now - Ca avance
379
                    getParameterDataFromServer(paramProperties->getOutputId()); // A revoir
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
380

1a6e8df3   Erdogan Furkan   7875 - time inter...
381
382
383
                    if (separateInfoFile)
                    {
                        // write only interval info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
384
                        writeInfo(true, true, false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
385
386
387
388
                    }
                    else
                    {
                        // write all info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
389
390
391
                        writeInfo(true, false, false);
                    }

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
395
396
397
                    if (separateInfoFile && isFirstInterval)
                    {
                        // create info file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
398
                        std::string filePath = getInfoFilePath(_fileWriter->getExtension());
1a6e8df3   Erdogan Furkan   7875 - time inter...
399
400
                        if (!_fileWriter->createNewFile(filePath))
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
401
402
403
404
405
                            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...
406
                        // write info
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
407
408
409
410
                        writeInfo(false, false, true);
                    }
                }
            }
fbe3c2bb   Benjamin Renard   First commit
411

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
412
            void DownloadOutput::writeInfo(bool isWriteIntervalInfo,
1a6e8df3   Erdogan Furkan   7875 - time inter...
413
414
415
                                           bool isWriteOnlyIntervalInfo,
                                           bool isFinalizeInfoFile)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
416
417
418
                char *hideHeader;
                if ((hideHeader = getenv("HIDE_HEADER_FILE")) != NULL)
                    if (strcmp(hideHeader, "true") == 0)
1a6e8df3   Erdogan Furkan   7875 - time inter...
419
                        return; // hide header for validation tests
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
420

1a6e8df3   Erdogan Furkan   7875 - time inter...
421
422
                if (!isWriteOnlyIntervalInfo)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
423
424
425
426
427
428
429
430
431
432
                    writeAMDAInfo();
                    writeRequestInfo();
                    writeParamInfo();
                }
                if (isWriteIntervalInfo)
                    writeIntervalInfo();

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
434
435
            void DownloadOutput::writeTableInfo()
            {
fbe3c2bb   Benjamin Renard   First commit
436

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

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

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

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

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

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
457
458
            void DownloadOutput::writeRequestInfo(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
459
460
461
462
463
                std::string structure = ouputStructureToStr[_downloadProperties.getOutputStructure()];
                std::string timeFormat = ouputFormatTimeToStr[_downloadProperties.getTimeFormat()];

                std::stringstream outputParams;
                bool firstParam = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
464
465
                for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
466
467
468
469
470
471
472
                    if (!firstParam)
                        outputParams << ",";
                    firstParam = false;
                    outputParams << paramProperties->getOriginalId();
                }

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
476
477
            void DownloadOutput::writeIntervalInfo(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
478
479
                std::stringstream startTime, stopTime;
                TimeUtil::formatTimeDateInIso(_currentTimeInterval->_startTime, startTime);
a6431512   Erdogan Furkan   Correction et ada...
480
                if (_timeIntervalList->size() > 1 && (_downloadProperties.getOutputStructure()== ONE_FILE || _downloadProperties.getOutputStructure()== ONE_FILE_REFPARAM ))
1a6e8df3   Erdogan Furkan   7875 - time inter...
481
482
483
484
485
486
                {
                    DownloadOutput::isSeveralIntervals = true;
                    _parseTimeInterval = _timeIntervalList->end();
                    _parseTimeInterval--;
                    TimeUtil::formatTimeDateInIso(_parseTimeInterval->_stopTime, stopTime);
                }
a6431512   Erdogan Furkan   Correction et ada...
487
                else
1a6e8df3   Erdogan Furkan   7875 - time inter...
488
489
490
491
492
                {
                    DownloadOutput::isSeveralIntervals = false;
                    TimeUtil::formatTimeDateInIso(_currentTimeInterval->_stopTime, stopTime);
                }
                _fileWriter->writeIntervalInfo(startTime.str(), stopTime.str(), isSeveralIntervals);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
493
            }
fbe3c2bb   Benjamin Renard   First commit
494

1a6e8df3   Erdogan Furkan   7875 - time inter...
495
496
            void DownloadOutput::writeParamInfo()
            {
5291eadc   Erdogan Furkan   For now - Ca avance
497
498
                ParamPropertiesList allParamPropertiesList = _downloadProperties.getAllParamPropertiesList();
                _fileWriter->writeParamsInfo(allParamPropertiesList,
1a6e8df3   Erdogan Furkan   7875 - time inter...
499
                                             _downloadProperties.getOutputStructure(), _currentParamId);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
500
            }
fbe3c2bb   Benjamin Renard   First commit
501

1a6e8df3   Erdogan Furkan   7875 - time inter...
502
503
            bool DownloadOutput::isNeedToGenerateTooSmallIntervalFile()
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
504
505
                return (_timeIntervalListTooSmall->empty() == false);
            }
fbe3c2bb   Benjamin Renard   First commit
506

1a6e8df3   Erdogan Furkan   7875 - time inter...
507
508
            void DownloadOutput::buildTooSmallIntervalCatalog(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
509
510
511
512
513
                if (!isNeedToGenerateTooSmallIntervalFile())
                    return;

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

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
518
                // create small intervals catalog file
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
519
520
521
522
523
524
525
526
527
528
529
530

                _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...
531
                // add interval index description
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
532
                TimeTableCatalog::ParameterDescription indexDesc(
1a6e8df3   Erdogan Furkan   7875 - time inter...
533
534
535
536
537
538
                    "index",
                    "Interval index",
                    "1",
                    TimeTableCatalog::ParameterDescription::ParameterType::Integer,
                    "",
                    "Interval index in input TimeTable",
0b2d2cab   Erdogan Furkan   Kernel part for c...
539
                    "",
1a6e8df3   Erdogan Furkan   7875 - time inter...
540
541
                    "meta.number",
                    "");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
542
543
                _smallIntervalsCatalog.addParameterDescription(indexDesc);

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
550
                    // push index for this time interval
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
551
552
553
554
                    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...
555
556
                    for (auto process : _tooSmallIntervalProcessMap)
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
557
558
                        std::vector<std::string> crtResult;
                        std::vector<std::string> crtCoverage;
1a6e8df3   Erdogan Furkan   7875 - time inter...
559
                        // compute the mean
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
560
561
                        process.second->compute(crtResult, crtCoverage);

1a6e8df3   Erdogan Furkan   7875 - time inter...
562
563
564
                        if (currentTooSmallTimeInterval == _timeIntervalListTooSmall->begin())
                        {
                            // add mean processes description to the catalog
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
565
566
567
568
569
                            std::string name = "mean(";
                            name += process.first;
                            name += ")";

                            TimeTableCatalog::ParameterDescription desc(
1a6e8df3   Erdogan Furkan   7875 - time inter...
570
571
572
573
574
575
                                process.first,
                                name,
                                process.second->getResultDimDefinition(),
                                TimeTableCatalog::ParameterDescription::ParameterType::Double,
                                "",
                                "Mean of the parameter in the interval",
0b2d2cab   Erdogan Furkan   Kernel part for c...
576
                                "",
1a6e8df3   Erdogan Furkan   7875 - time inter...
577
578
                                process.second->getUCD(),
                                "");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
579
580
581
                            _smallIntervalsCatalog.addParameterDescription(desc);
                        }

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

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

1a6e8df3   Erdogan Furkan   7875 - time inter...
589
                    // go to the next too small interval
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
590
591
592
                    ++currentTooSmallTimeInterval;
                }
            }
fbe3c2bb   Benjamin Renard   First commit
593

1a6e8df3   Erdogan Furkan   7875 - time inter...
594
595
596
            void DownloadOutput::terminate(void)
            {
                // write the catalog file
fbe3c2bb   Benjamin Renard   First commit
597

1a6e8df3   Erdogan Furkan   7875 - time inter...
598
599
                if (isNeedToGenerateTooSmallIntervalFile())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
600
601
                    std::string ttPath = _timeIntervalList->begin()->_ttPath;
                    _smallIntervalsCatalog.write(_workPath,
1a6e8df3   Erdogan Furkan   7875 - time inter...
602
603
                                                 TimeTableCatalog::TimeTableCatalogFactory::getInstance().getReaderType(ttPath));
                    // add the catalog file to the output files list
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
604
605
606
                    boost::filesystem::path ttp(ttPath);
                    _files.push_back(_smallIntervalsCatalog._name + ttp.extension().string());
                }
fbe3c2bb   Benjamin Renard   First commit
607

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
608
609
                ParamOutput::terminate();
            }
fbe3c2bb   Benjamin Renard   First commit
610

1a6e8df3   Erdogan Furkan   7875 - time inter...
611
612
            void DownloadOutput::createNewDataFile(void)
            {
256d4fda   Furkan   The end is close
613
614
615
                std::string filePrefix;
                std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                if (!_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
616
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
617
618
619
620
621
622
                    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
623

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
624
625
626
            /*
             * @brief Create parameters in relation with the download properties
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
627
628
            void DownloadOutput::createParameters(void)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
629
630
                LOG4CXX_DEBUG(_logger, "DownloadOutput::createParameters");

1a6e8df3   Erdogan Furkan   7875 - time inter...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
                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
652
                            }
1a6e8df3   Erdogan Furkan   7875 - time inter...
653
654
655
656
657
658
659
660
661
662
663
664
                            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
665
                            }
1a6e8df3   Erdogan Furkan   7875 - time inter...
666
667
668
                        }
                        catch (...)
                        {
256d4fda   Furkan   The end is close
669
670
671
                            std::string filePrefix;
                            std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                            if (_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
                                _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
689
                                    AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(paramProperties->getOriginalId());
1a6e8df3   Erdogan Furkan   7875 - time inter...
690
691
692
693
                                    samplingTime = std::max(samplingTime, getSamplingInTreeParameter(originalParam));
                                }
                                catch (...)
                                {
256d4fda   Furkan   The end is close
694
695
696
                                    std::string filePrefix;
                                    std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                                    if (_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
697
                                        _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
698
699
700
701
                                    throw;
                                }
                            }
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
702
703
704
705

                        _samplingValue = samplingTime;

                        // create resampled parameters for all parameters defined in the request
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
706
                        bool isFirstParam = true;
1a6e8df3   Erdogan Furkan   7875 - time inter...
707
708
709
710
711
712
                        AMDA::Parameters::ParameterSPtr firstParam;
                        for (auto paramProperties : _downloadProperties.getParamPropertiesList())
                        {
                            try
                            {
                                // get original parameter
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
713
714
                                AMDA::Parameters::ParameterSPtr originalParam = _parameterManager.getParameter(paramProperties->getOriginalId());

1a6e8df3   Erdogan Furkan   7875 - time inter...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
                                // 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
755
                                isFirstParam = false;
1a6e8df3   Erdogan Furkan   7875 - time inter...
756
757
758
                            }
                            catch (...)
                            {
256d4fda   Furkan   The end is close
759
760
761
                                std::string filePrefix;
                                std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                                if (_fileWriter->createNewFile(filePath,filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
762
                                    _fileWriter->writeError("EstablishConnection Error.\nIt's impossible to create  the parameter: \"" + paramProperties->getOriginalId() + "\".");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
763
764
765
766
                                throw;
                            }
                        }
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
                    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 (...)
                        {
256d4fda   Furkan   The end is close
785
786
787
                            std::string filePrefix;
                            std::string filePath = getFilePath(_fileWriter->getExtension(), false, filePrefix);
                            if (_fileWriter->createNewFile(filePath, filePrefix))
1a6e8df3   Erdogan Furkan   7875 - time inter...
788
789
790
791
792
793
794
795
796
                                _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
797
798
799
800
801
802
                }
            }

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

1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
808
809
810
                switch (_downloadProperties.getFileFormat()) {
                    case ASCII_FILE_FORMAT:
                        _fileWriter = new FileWriter::FileWriterASCIITabular(_parameterManager);
59034873   Hacene SI HADJ MOHAND   8675 ok
811
                        _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
812
813
814
                        break;
                    case JSON_FILE_FORMAT:
                        _fileWriter = new FileWriter::FileWriterASCIIJson(_parameterManager);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
815
                        _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
816
817
818
                        break;
                    case VOT_FILE_FORMAT:
                        _fileWriter = new FileWriter::FileWriterASCIIVOTable(_parameterManager);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
819
                        _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
820
821
822
                        break;
                    case CDF_FILE_FORMAT:
                        _fileWriter = new FileWriter::FileWriterCDF(_parameterManager);
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
823
                        _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
824
                        break;
9e1bbe22   Benjamin Renard   Skeleton to imple...
825
                    case CDF_ISTP_FILE_FORMAT:
993426a6   Erdogan Furkan   TIME2000 included
826
827
			            _fileWriter = new FileWriter::FileWriterCDFISTP(_parameterManager);
                        _fileWriter->setTimeFormat(_downloadProperties.getTimeFormat());
9e1bbe22   Benjamin Renard   Skeleton to imple...
828
			break;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
829
830
831
                    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
832
833
834
835
836
837
                }
            }

            /*
             * @brief Get file path in relation with the sequence step
             */
256d4fda   Furkan   The end is close
838
            std::string DownloadOutput::getFilePath(std::string extension, bool infoFile, std::string &filePrefix)
1a6e8df3   Erdogan Furkan   7875 - time inter...
839
840
            {
                // create workspace dir if needed
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
841
                int ret = AMDA::Helpers::Helper::mkdir(_workPath.c_str());
1a6e8df3   Erdogan Furkan   7875 - time inter...
842
843
                if (ret)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
844
845
846
                    const size_t buflen = 250;
                    char buf[250];
                    LOG4CXX_ERROR(_logger,
1a6e8df3   Erdogan Furkan   7875 - time inter...
847
                                  "Create working directory \"" << _workPath << "\"error : " << strerror_r(ret, buf, buflen));
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
848
849
850
                    BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
851
                // create full file path
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
852
853
854
855
856
857
                std::stringstream filePath;
                filePath << _workPath;

                filePath << "/";

                std::stringstream fileName;
1a6e8df3   Erdogan Furkan   7875 - time inter...
858
859
                if (_downloadProperties.getFileName().empty())
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
860
                    fileName << "output-";
256d4fda   Furkan   The end is close
861
                    filePrefix = "output-";
1a6e8df3   Erdogan Furkan   7875 - time inter...
862
                    // add parameters ids
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
863
                    bool firstParam = true;
23cd82f6   Erdogan Furkan   Almost done
864
                    for (auto paramProperties : _downloadProperties.getAllParamPropertiesList())
1a6e8df3   Erdogan Furkan   7875 - time inter...
865
866
867
868
                    {
                        if (!_currentParamId.empty())
                        {
                            // add only current parameter id
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
869
870
871
                            if (_currentParamId != paramProperties->getOutputId())
                                continue;
                        }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
872

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
873
                        if (!firstParam)
256d4fda   Furkan   The end is close
874
                        {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
875
                            fileName << "_";
256d4fda   Furkan   The end is close
876
877
                            filePrefix += "_";
                        }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
878
                        firstParam = false;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
879

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
880
                        fileName << paramProperties->getOriginalId();
256d4fda   Furkan   The end is close
881
                        filePrefix += paramProperties->getOriginalId();
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
882

1a6e8df3   Erdogan Furkan   7875 - time inter...
883
884
885
                        // add indexes
                        for (auto index : paramProperties->getIndexDefList())
                        {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
886
887
888
889
                            boost::replace_all(index, "[", "");
                            boost::replace_all(index, "]", "");
                            boost::replace_all(index, "*", "x");
                            fileName << "_" << index;
256d4fda   Furkan   The end is close
890
891
                            filePrefix += "_";
                            filePrefix += index;
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
892
                        }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
893
                    }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
894

355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
895
                    std::stringstream fileNameSuffix;
1a6e8df3   Erdogan Furkan   7875 - time inter...
896
897
                    if (!infoFile)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
898
                        if ((_downloadProperties.getOutputStructure() != ONE_FILE) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
899
900
901
902
                            (_downloadProperties.getOutputStructure() != ONE_FILE_REFPARAM) &&
                            (_parameterManager.getInputIntervals()->size() != 1))
                        {
                            // add interval index
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
903
                            fileNameSuffix << "_" << _currentTimeInterval->_ttName;
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
904
                            fileNameSuffix << "_" << _currentIntervalIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
905
906
907
908
909
910
                        }
                        else
                        {
                            if (_currentTimeInterval->_ttName.empty())
                            {
                                // add start time
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
911
912
913
914
                                double lStartTime = _currentTimeInterval->_startTime;
                                char buffer[TIMELENGTH];
                                Double2DD_Time(buffer, lStartTime);
                                fileNameSuffix << "_" << buffer;
1a6e8df3   Erdogan Furkan   7875 - time inter...
915
916
917
918
                            }
                            else
                            {
                                // add TT name
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
919
920
                                fileNameSuffix << "_" << _currentTimeInterval->_ttName;
                            }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
921
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
922
923
                    }
                    else
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
924
                        fileNameSuffix << "_info";
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
925

1a6e8df3   Erdogan Furkan   7875 - time inter...
926
927
928
                    // check fileName size
                    if (fileName.str().size() + extension.size() + 1 + fileNameSuffix.str().size() > 100)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
929
                        filePath << fileName.str().substr(0, 100 - extension.size() - 1 - fileNameSuffix.str().size()) << fileNameSuffix.str();
1a6e8df3   Erdogan Furkan   7875 - time inter...
930
931
932
                    }
                    else
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
933
934
                        filePath << fileName.str() << fileNameSuffix.str();
                    }
1a6e8df3   Erdogan Furkan   7875 - time inter...
935
936
937
938
939
                }
                else
                {
                    if (!infoFile)
                    {
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
940
                        if ((_downloadProperties.getOutputStructure() != ONE_FILE) &&
1a6e8df3   Erdogan Furkan   7875 - time inter...
941
942
943
944
945
946
947
948
949
950
951
952
953
                            (_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
954
955
                        filePath << _downloadProperties.getFileName() << "_info";
                    }
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
956
957
                }

1a6e8df3   Erdogan Furkan   7875 - time inter...
958
                // add extension
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
959
960
961
962
963
964
965
966
967
                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...
968
969
            std::string DownloadOutput::getInfoFilePath(std::string extension)
            {
256d4fda   Furkan   The end is close
970
971
                std::string filePrefix;
                return getFilePath(extension, true,filePrefix);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
972
            }
a3eb6f22   Hacene SI HADJ MOHAND   clen up
973
974

            /*
65414a1c   Hacene SI HADJ MOHAND   working for mav
975
             * @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
976
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
977
978
            std::string DownloadOutput::getTableInfoFilePath(std::string extension)
            {
a3eb6f22   Hacene SI HADJ MOHAND   clen up
979
                std::string suffix = "_table";
65414a1c   Hacene SI HADJ MOHAND   working for mav
980
                std::string path = getInfoFilePath(extension);
a3eb6f22   Hacene SI HADJ MOHAND   clen up
981
982
983
                int pos = path.size() - extension.size() - 1;
                pos = std::max(pos, 0);
                path.insert(pos, suffix);
65414a1c   Hacene SI HADJ MOHAND   working for mav
984
                return path;
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
985
986
            }

1a6e8df3   Erdogan Furkan   7875 - time inter...
987
988
989
990
            void DownloadOutput::getParameterDataFromServer(std::string paramId)
            {
                try
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
991
                    _currentParamId = paramId;
1a6e8df3   Erdogan Furkan   7875 - time inter...
992
993
994
995
                    do
                    {
                        try
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
996
                            _paramDataIndexInfo = _parameterManager.getParameter(paramId)->getAsync(this).get();
1a6e8df3   Erdogan Furkan   7875 - time inter...
997
998
999
                        }
                        catch (...)
                        {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1000
1001
1002
                            BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                            throw;
                        }
1a6e8df3   Erdogan Furkan   7875 - time inter...
1003
1004
1005
1006
                        if (_paramDataIndexInfo._nbDataToProcess > 0)
                        {
                            try
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1007
                                _parameterManager.getParameter(paramId)->getParamData(this)->accept(*this);
1a6e8df3   Erdogan Furkan   7875 - time inter...
1008
1009
1010
                            }
                            catch (AMDA::AMDA_exception &e)
                            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1011
1012
1013
1014
1015
                                e << AMDA::errno_code(AMDA_PARAM_OUTPUT_ERR);
                                throw;
                            }
                        }
                    } while (!_paramDataIndexInfo._noMoreTimeInt && !_paramDataIndexInfo._timeIntToProcessChanged);
1a6e8df3   Erdogan Furkan   7875 - time inter...
1016
1017
1018
1019
                }
                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
1020
1021
1022
1023
1024
                    throw;
                }
            }

            void DownloadOutput::addParameterInFile(std::string paramId,
1a6e8df3   Erdogan Furkan   7875 - time inter...
1025
1026
1027
1028
                                                    FileWriter::FileDataType type, bool isFirstParam, int dim1Size, int dim2Size)
            {
                if (!_paramDefinedInFile[paramId])
                {
5291eadc   Erdogan Furkan   For now - Ca avance
1029
                    bool isTableParam =false;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1030
                    ParamProperties *prop = _downloadProperties.getParamPropertiesFromOutputId(paramId);
5291eadc   Erdogan Furkan   For now - Ca avance
1031
1032
1033
1034
1035
1036
1037
                    if(prop == nullptr){
                        prop = _downloadProperties.getTableParamPropertiesFromOutputId(paramId);
                        if(prop == nullptr)
                             BOOST_THROW_EXCEPTION(AMDA::Parameters::ParamOutput_exception());
                        isTableParam=true;
                    }
                    _fileWriter->addParameter(prop, _paramsIndexList[paramId], type, isFirstParam, dim1Size, dim2Size, isTableParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1038
1039
1040
1041
                }
                _paramDefinedInFile[paramId] = true;
            }

1a6e8df3   Erdogan Furkan   7875 - time inter...
1042
1043
            void DownloadOutput::buildParamIndexes(std::string paramId, int dim1Size, int dim2Size)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1044
                _paramsIndexList[paramId].clear();
5291eadc   Erdogan Furkan   For now - Ca avance
1045
                for (auto paramProp : _downloadProperties.getAllParamPropertiesList())
1a6e8df3   Erdogan Furkan   7875 - time inter...
1046
1047
1048
1049
1050
1051
1052
                {
                    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
1053
                                ERROR_EXCEPTION(
1a6e8df3   Erdogan Furkan   7875 - time inter...
1054
                                    "DownloadOutput of: '" << paramId << "' index: " << indexDef << " out of range");
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
                            }
                        }
                        break;
                    }
                }

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

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

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1070
1071
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1072
1073
1074
1075
1076
                bool isFirstParam = (_currentParamId == _firstParamId);

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1077
1078
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1079
1080
1081
1082
                    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...
1083
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1084
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1085
1086
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1087
1088
1089
1090
1091
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1092
1093
            void DownloadOutput::visit(AMDA::Parameters::ParamDataScalaireFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1094
1095
1096
1097
1098
                bool isFirstParam = (_currentParamId == _firstParamId);

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1099
1100
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1101
1102
1103
1104
                    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...
1105
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1106
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1107
1108
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1109
1110
1111
1112
1113
            }

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

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1121
1122
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1123
1124
1125
1126
                    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...
1127
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1128
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1129
1130
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1131
1132
1133
1134
1135
            }

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

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1143
1144
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1145
1146
1147
1148
                    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...
1149
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1150
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1151
1152
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1153
1154
1155
1156
1157
            }

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

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1165
1166
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1167
1168
1169
1170
                    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...
1171
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1172
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1173
1174
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1175
1176
1177
1178
1179
            }

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

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

                for (unsigned int index = _paramDataIndexInfo._startIndex;
1a6e8df3   Erdogan Furkan   7875 - time inter...
1187
1188
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1189
1190
1191
1192
                    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...
1193
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1194
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1195
1196
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1197
1198
1199
1200
1201
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1202
1203
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1204
1205
1206
1207
1208
1209
1210
1211
                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...
1212
1213
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1214
1215
1216
1217
                    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...
1218
1219
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1220
1221
1222
                        _fileWriter->writeShortData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1223
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1224
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1225
1226
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1227
1228
1229
1230
1231
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1232
1233
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1234
1235
1236
1237
1238
1239
1240
1241
                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...
1242
1243
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1244
1245
1246
1247
                    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...
1248
1249
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1250
1251
1252
                        _fileWriter->writeFloatData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1253
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1254
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1255
1256
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1257
1258
1259
1260
1261
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1262
1263
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1264
1265
1266
1267
1268
1269
1270
1271
                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...
1272
1273
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1274
1275
1276
1277
                    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...
1278
1279
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1280
1281
1282
                        _fileWriter->writeDoubleData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1283
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1284
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1285
1286
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1287
1288
1289
1290
1291
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1292
1293
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DLongDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1294
1295
1296
1297
1298
1299
1300
1301
                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...
1302
1303
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1304
1305
1306
1307
                    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...
1308
1309
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1310
1311
1312
                        _fileWriter->writeLongDoubleData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1313
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1314
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1315
1316
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1317
1318
1319
1320
1321
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1322
1323
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DInt *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1324
1325
1326
1327
1328
1329
1330
1331
                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...
1332
1333
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1334
1335
1336
1337
                    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...
1338
1339
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1340
1341
1342
                        _fileWriter->writeIntData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1343
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1344
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1345
1346
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1347
1348
1349
1350
1351
            }

            /**
             * @overload VisitorOfParamData::visit()
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1352
1353
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab1DLogicalData *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1354
1355
1356
1357
1358
1359
1360
1361
                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...
1362
1363
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1364
1365
1366
1367
                    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...
1368
1369
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1370
1371
1372
                        _fileWriter->writeLogicalData(_currentParamId, varIndex, pParamData->get(index)[component.getDim1Index()], _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1373
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1374
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1375
1376
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1377
1378
1379
1380
1381
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1382
1383
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DShort *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1384
1385
1386
1387
1388
1389
1390
1391
                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...
1392
1393
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1394
1395
1396
1397
                    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...
1398
1399
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1400
1401
1402
1403
                        short val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeShortData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1404
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1405
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1406
1407
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1408
1409
1410
1411
1412
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1413
1414
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DFloat *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1415
1416
1417
1418
1419
1420
1421
1422
                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...
1423
1424
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1425
1426
1427
1428
                    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...
1429
1430
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1431
1432
1433
1434
                        float val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeFloatData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1435
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1436
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1437
1438
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1439
1440
1441
1442
1443
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1444
1445
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1446
1447
1448
1449
1450
1451
1452
1453
                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...
1454
1455
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1456
1457
1458
1459
                    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...
1460
1461
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1462
1463
1464
1465
                        double val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeDoubleData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1466
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1467
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1468
1469
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1470
1471
1472
1473
1474
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1475
1476
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DLongDouble *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1477
1478
1479
1480
1481
1482
1483
1484
                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...
1485
1486
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1487
1488
1489
1490
                    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...
1491
1492
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1493
1494
1495
1496
                        long double val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeLongDoubleData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1497
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1498
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1499
1500
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1501
1502
1503
1504
1505
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1506
1507
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DInt *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1508
1509
1510
1511
1512
1513
1514
1515
                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...
1516
1517
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1518
1519
1520
1521
                    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...
1522
1523
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1524
1525
1526
1527
                        int val = (pParamData->get(index))[component.getDim1Index()][component.getDim2Index()];
                        _fileWriter->writeIntData(_currentParamId, varIndex, val, _downloadProperties.getPrecision());
                        ++varIndex;
                    }
7929a8a9   Benjamin Renard   CDF writer optimi...
1528
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1529
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1530
1531
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1532
1533
1534
1535
1536
            }

            /**
             * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
             */
1a6e8df3   Erdogan Furkan   7875 - time inter...
1537
1538
            void DownloadOutput::visit(AMDA::Parameters::ParamDataTab2DLogicalData *pParamData)
            {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1539
1540
1541
1542
1543
1544
1545
1546
                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...
1547
1548
                     index < _paramDataIndexInfo._nbDataToProcess + _paramDataIndexInfo._startIndex; ++index)
                {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1549
1550
1551
1552
                    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...
1553
1554
                    for (auto component : _paramsIndexList[_currentParamId])
                    {
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1555
1556
1557
1558
                        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...
1559
                    _fileWriter->goToNextRecord(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1560
                }
355b96ac   Hacene SI HADJ MOHAND   ticket 9399 ok
1561
1562
                if (_paramDataIndexInfo._nbDataToProcess > 0)
                    _fileWriter->flushData(_currentParamId, isFirstParam);
1f8dfaf6   Hacene SI HADJ MOHAND   bug at init param
1563
1564
1565
            }

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