Blame view

src/Info/ParamTable.cc 33.8 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
/**
 * ParamTable.cc
 *
 *  Created on: 10 oct. 2014
 *  Author: AKKA
 */
#include "ParamTable.hh"

#include "Parameter.hh"
f2db3c16   Benjamin Renard   Support variable ...
10
#include "ParamData.hh"
3fe8b83d   Benjamin Renard   Get parameter inf...
11
12
#include "ParamInfo.hh"
#include "ParamMgr.hh"
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
13
#include "Process.hh"
91edc9c0   Benjamin Renard   Add process to tr...
14
#include "ServicesServer.hh"
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
15
#include <algorithm>
91edc9c0   Benjamin Renard   Add process to tr...
16
#include <boost/throw_exception.hpp>
fbe3c2bb   Benjamin Renard   First commit
17
18
19
20

using namespace log4cxx;

namespace AMDA {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
21
22
    namespace Info {

0051287c   Hacene SI HADJ MOHAND   starting us
23
#define PUSHINFO(infoMap, key, value) if(!value.empty())infoMap.push_back(std::pair<std::string,std::string>(key,value))
fbe3c2bb   Benjamin Renard   First commit
24

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
25
        LoggerPtr ParamTable::_logger(Logger::getLogger("AMDA-Kernel.ParamTable"));
fbe3c2bb   Benjamin Renard   First commit
26

91edc9c0   Benjamin Renard   Add process to tr...
27
        ParamTable::ParamTable(const char *paramId, int dim) : _paramId(paramId), _dim(dim),
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
28
29
        _tableName(""), _tableUnits(""), _variable("false") {
        }
fbe3c2bb   Benjamin Renard   First commit
30

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
31
32
        ParamTable::~ParamTable() {
        }
fbe3c2bb   Benjamin Renard   First commit
33

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
34
35
36
        std::string ParamTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return "";
        }
3fe8b83d   Benjamin Renard   Get parameter inf...
37

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
38
39
40
41
42
43
        /*
         * @brief Get param id
         */
        std::string ParamTable::getParamId(void) {
            return _paramId;
        }
7f7e3b39   Benjamin Renard   Fix a bug with st...
44

91edc9c0   Benjamin Renard   Add process to tr...
45
46
47
48
        int ParamTable::getDim(void) {
            return _dim;
        }

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
49
50
51
52
53
54
        /*
         * @brief Set name of the table
         */
        void ParamTable::setName(std::string name) {
            _tableName = name;
        }
fbe3c2bb   Benjamin Renard   First commit
55

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
56
57
58
59
60
61
62
63
64
65
66
67
68
        /*
         * @brief Get name of the table
         */
        std::string ParamTable::getName(ParameterManager* parameterManager) {
            if (_tableName.empty() && _variable) {
                std::string paramKeyForInfo = getTableParamKeyForInfo(parameterManager);
                if (!paramKeyForInfo.empty()) {
                    std::string tableParam = getTableParamByKey(parameterManager, paramKeyForInfo);
                    AMDA::Info::ParamInfoSPtr paramTableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParam);
                    if (paramTableInfo != nullptr)
                        return paramTableInfo->getName();
                }
            }
fbe3c2bb   Benjamin Renard   First commit
69

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
70
71
            return _tableName;
        }
fbe3c2bb   Benjamin Renard   First commit
72

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        /*
         * @brief Set units
         */
        void ParamTable::setUnits(std::string units) {
            _tableUnits = units;
        }

        /*
         * @brief Get units of the table
         */
        std::string ParamTable::getUnits(ParameterManager* parameterManager) {
            if (_tableName.empty() && _variable) {
                std::string paramKeyForInfo = getTableParamKeyForInfo(parameterManager);
                if (!paramKeyForInfo.empty()) {
                    std::string tableParam = getTableParamByKey(parameterManager, paramKeyForInfo);
                    AMDA::Info::ParamInfoSPtr paramTableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParam);
                    if (paramTableInfo != nullptr)
                        return paramTableInfo->getUnits();
0051287c   Hacene SI HADJ MOHAND   starting us
91
                }
0051287c   Hacene SI HADJ MOHAND   starting us
92
            }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

            return _tableUnits;
        }

        /*
         * @brief Set isVariable attribute
         */
        void ParamTable::setIsVariable(bool isVariable) {
            _variable = isVariable;
        }

        /*
         * @brief Get if it's a variable table
         */
        bool ParamTable::isVariable(ParameterManager* /*parameterManager*/) {
            return _variable;
        }
236cd24c   Hacene SI HADJ MOHAND   working in full v...
110
111
112
113
114
115
116
117
118
119
120
        
           /*
         * @brief Set isVariable attribute
         */
        void ParamTable::setIsFullVariable(bool isFullVariable) {
            _fullVariable = isFullVariable;
        }

        /*
         * @brief Get if it's a variable table
         */
a5ce87d1   Benjamin Renard   Cleanup to remove...
121
        bool ParamTable::isFullVariable(ParameterManager* /*parameterManager*/) {
93bba7b7   Hacene SI HADJ MOHAND   ok for varable wi...
122
            return _fullVariable;
79366e37   Hacene SI HADJ MOHAND   trying to add ful...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
        }
        
        void ParamTable::addRelatedParams(ParameterManager *parameterManager, std::string paramId, std::list<std::string>relatedParams){
             AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramId);
             if(paramInfo == NULL)
                 return;
              const std::vector<std::string>& paramLinkedParams = paramInfo->getLinkedParamList();
              if(paramLinkedParams.empty())
                  return;
              for (auto pId : paramLinkedParams){
                  relatedParams.push_back(pId);
                  addRelatedParams(parameterManager, paramId, relatedParams);
              }
              return;
236cd24c   Hacene SI HADJ MOHAND   working in full v...
137
        }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

        void ParamTable::addTableParam(std::string key, std::string name) {
            _tableParams[key] = name;
        }

        std::string ParamTable::getTableParamByKey(ParameterManager* /*parameterManager*/, std::string key) {
            return _tableParams[key];
        }

        std::map<std::string, std::string>& ParamTable::getTableParams(ParameterManager* /*parameterManager*/) {
            return _tableParams;
        }

        std::vector<double> ParamTable::getConstantTableParamValuesByKey(ParameterManager *parameterManager, std::string key) {
            std::vector<double> paramValues;
            ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
            if (tmpParam == nullptr)
                return paramValues;
            AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
            if (_tableParams.find(key) == _tableParams.end())
                return paramValues;
            std::string tableParamName = _tableParams[key];
            if (lInfoList.find(tableParamName) == lInfoList.end())
                return paramValues;
            paramValues = *lInfoList[tableParamName].get();
            return paramValues;
        }

        std::vector<double> ParamTable::getVariableTableParamValuesByKey(ParameterManager* /*parameterManager*/, std::map<std::string, std::vector<double>>*paramsTableData, std::string key) {
            std::vector<double> paramValues;
            if (paramsTableData == NULL)
                return paramValues;
            if (paramsTableData->find(key) == paramsTableData->end())
                return paramValues;
            return (*paramsTableData)[key];
        }

        std::vector<double> ParamTable::getTableParamValuesByKey(ParameterManager *parameterManager, std::map<std::string, std::vector<double>>*paramsTableData, std::string key) {
            if (_variable)
                return getVariableTableParamValuesByKey(parameterManager, paramsTableData, key);
            else
                return getConstantTableParamValuesByKey(parameterManager, key);
        }

        void ParamTable::addTableInfo(ParameterManager *parameterManager, int dim, std::vector<std::pair<std::string, std::string>>&infoMap) {
            std::stringstream tableDim;
            tableDim << dim;

            std::stringstream infoKey;
0051287c   Hacene SI HADJ MOHAND   starting us
187
            infoKey.str("");
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
188
189
            infoKey << PARAMETER_TABLE << "[" << tableDim.str() << "]";
            PUSHINFO(infoMap, infoKey.str(), this->getName(parameterManager));
0051287c   Hacene SI HADJ MOHAND   starting us
190
191

            infoKey.str("");
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
192
            infoKey << PARAMETER_TABLE_UNITS << "[" << tableDim.str() << "]";
c7f96386   Hacene SI HADJ MOHAND   6036
193
194
195
196
197
            if (this->getUnits(parameterManager) ==""){
                                            PUSHINFO(infoMap, infoKey.str(), std::string(UNSPECIFIED_UNIT));
            }else{
                                             PUSHINFO(infoMap, infoKey.str(), this->getUnits(parameterManager));
                     }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
198
199
200
201
202
203
            if (this->isVariable(parameterManager)) {
                this->addVariableTableInfo(parameterManager, dim, infoMap);
            } else {
                //build min and max values list
                std::stringstream tableMinValues;
                std::stringstream tableMaxValues;
f3cd5351   Hacene SI HADJ MOHAND   us ok
204
205
                int size_ = this->getSize(parameterManager);
                for (int i = 0; i< size_; ++i) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
                    if (i > 0) {
                        tableMinValues << ",";
                        tableMaxValues << ",";
                    }
                    AMDA::Info::t_TableBound bound = this->getBound(parameterManager, i);
                    tableMinValues << bound.min;
                    tableMaxValues << bound.max;
                }
                infoKey.str("");
                infoKey << PARAMETER_TABLE_MINVAL << "[" << tableDim.str() << "]";
                PUSHINFO(infoMap, infoKey.str(), tableMinValues.str());

                infoKey.str("");
                infoKey << PARAMETER_TABLE_MAXVAL << "[" << tableDim.str() << "]";
                PUSHINFO(infoMap, infoKey.str(), tableMaxValues.str());
            }
        }

7abf24a0   Hacene SI HADJ MOHAND   correcting bug
224
        void ParamTable::addSemiVariableTableInfo(ParameterManager* parameterManager, int dim, std::string paramId, std::string tabKey, std::vector<std::pair<std::string, std::string>>&infoMap) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
225
226
            AMDA::Parameters::ParameterSPtr pParam = parameterManager->getParameter(paramId);
            Process* lProcess = dynamic_cast<Process*> (pParam->getDataWriterTemplate().get());
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
227
            if (lProcess != NULL) {
f3cd5351   Hacene SI HADJ MOHAND   us ok
228
                AMDA::Parameters::SemiVariableTable semiVariableTable = lProcess ->getSemiVariableTable();
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
229
230
231
                std::list<std::string>::iterator it;
                it = std::find(_printedTables.begin(), _printedTables.end(), paramId);
                if (!semiVariableTable.tabHeader.empty() && it == _printedTables.end()) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
232
233
234
235
236
237
238
239
                    std::stringstream head;
                    head.str("");
                    head << "mode" << " ";
                    for (auto h : semiVariableTable.tabHeader) {
                        head << h << " ";
                    }
                    PUSHINFO(infoMap, "", head.str());
                    // recuperer les centres 
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
240
                    bool variableSizes = false;
a5ce87d1   Benjamin Renard   Cleanup to remove...
241
                    //unsigned int nModes = semiVariableTable.tabValues.size();
93bba7b7   Hacene SI HADJ MOHAND   ok for varable wi...
242
243
                    unsigned int index =0;
                    unsigned nValues = 0;
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
244
                    for (auto tabValues : semiVariableTable.tabValues) {
93bba7b7   Hacene SI HADJ MOHAND   ok for varable wi...
245
246
                        if (index == 0)
                             nValues = tabValues.second.size();
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
247
248
                        if (tabValues.second.size() != nValues)
                            variableSizes = true;
51483991   Hacene SI HADJ MOHAND   correcting mex_ls
249
                        ++index;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
250
                    }
c0955cd4   Hacene SI HADJ MOHAND   ok for juno jedi
251
                    if (variableSizes || !semiVariableTable.calculateBounds) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
252
                        std::ostringstream values;
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
253
                        for (auto tabValues : semiVariableTable.tabValues) {
236cd24c   Hacene SI HADJ MOHAND   working in full v...
254
                            values << tabValues.first << " ";
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
255
256
257
258
259
260
261
                            for (unsigned int i = 0; i < nValues; i++) {
                                if (i < tabValues.second.size()) {
                                    values << std::to_string(tabValues.second[i]) << " ";
                                } else {
                                    values << "NAN ";
                                }
                            }
236cd24c   Hacene SI HADJ MOHAND   working in full v...
262
263
                            PUSHINFO(infoMap, "", values.str());
                            values.str("");
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
264
265
266
267
268
                        }
                    } else {
                        std::vector<double> energyVec;
                        std::map<std::string, std::vector<double>> paramsTableData;
                        std::map<int, std::vector<double>> semiVariableTableData;
2929f621   Hacene SI HADJ MOHAND   min max coorectio...
269
270
271
272
273
                        int nMode=0;
                        for (auto tabValues : semiVariableTable.tabValues) {
                        paramsTableData[tabKey] = tabValues.second;
                        for (unsigned int j = 0; j < nValues; ++j) {
                                t_TableBound bound = getBound(parameterManager, j , &paramsTableData);
51483991   Hacene SI HADJ MOHAND   correcting mex_ls
274
                                if(bound.min != j/2 && bound.max !=j/2+1){
2929f621   Hacene SI HADJ MOHAND   min max coorectio...
275
276
                                semiVariableTableData[nMode].push_back(bound.min);
                                semiVariableTableData[nMode + 1].push_back(bound.max);
51483991   Hacene SI HADJ MOHAND   correcting mex_ls
277
                                }
2929f621   Hacene SI HADJ MOHAND   min max coorectio...
278
279
280
                            
                        }
                        nMode +=2;
d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
                        }
                        int l = 0;
                        int k = 0;
                        for (auto v : semiVariableTableData) {
                            std::ostringstream values;
                            std::string born;
                            (l % 2 == 0) ? born = " Min " : born = " Max ";
                            values << std::to_string(k) << born;
                            // Convert all doubles to string ","
                            std::copy(v.second.begin(), v.second.end(),
                                    std::ostream_iterator<double>(values, " "));
                            PUSHINFO(infoMap, "", values.str());
                            values.str("");
                            if (l % 2 != 0)
                                k++;
                            l++;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
297

d7d55a02   Hacene SI HADJ MOHAND   ok for getClbInfo...
298
                        }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
299
300
301
                    }
                    _printedTables.push_back(paramId);
                }
236cd24c   Hacene SI HADJ MOHAND   working in full v...
302

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
303
304
305
306
307
            }
            AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(paramId);
            const std::vector<std::string>& paramLinkedParams = paramInfo->getLinkedParamList();
            for (auto pId : paramLinkedParams)
                addSemiVariableTableInfo(parameterManager, dim, pId, tabKey, infoMap);
7abf24a0   Hacene SI HADJ MOHAND   correcting bug
308
            return;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
309
310
311
312
313
314
315
        }

        void ParamTable::addVariableTableInfo(ParameterManager * parameterManager, int dim, std::vector<std::pair<std::string, std::string>>&tableInfo) {
            std::map<std::string, std::string>& tableParams = this->getTableParams(parameterManager);
            if (!tableParams.empty()) {
                std::stringstream infoKey;
                int i = 0;
236cd24c   Hacene SI HADJ MOHAND   working in full v...
316
                for (auto tableParam : tableParams) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
317
                    infoKey.str("");
236cd24c   Hacene SI HADJ MOHAND   working in full v...
318
319
320
                    infoKey << VARIABLE_PARAMETER_TABLE << tableParam.first << "[" << i << "]";
                    PUSHINFO(tableInfo, infoKey.str(), tableParam.second);
                    AMDA::Parameters::ParameterSPtr variableTableParam = parameterManager->getParameter(tableParam.second);
a3eb6f22   Hacene SI HADJ MOHAND   clen up
321
                    addSemiVariableTableInfo(parameterManager, dim, tableParam.second, tableParam.first, tableInfo);
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
322
323
324
325
326
                    i++;
                }
            }
        }

91edc9c0   Benjamin Renard   Add process to tr...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
        ParameterSPtr ParamTable::createRelatedParameter(ParameterManager *parameterManager) {
            ParameterSPtr lParameter;

            //Compute a ResmapledParameter name
            std::stringstream lIdent;
            lIdent << _paramId << "_" << _tableName;
            LOG4CXX_DEBUG(_logger, "Create Parameter from ParamTable: " << lIdent.str());
            // Search if already exist
            lParameter = parameterManager->findParamInParameterList(lIdent.str());
            if (lParameter != nullptr) {
                LOG4CXX_DEBUG(_logger, "Table Parameter: " << lIdent.str() << " founded");
                lParameter = parameterManager->checkIfIsANeededParameter(lParameter);
            } else {
                // create Parameter from ParamTable
                LOG4CXX_DEBUG(_logger, "ParamTable::createRelatedParameter: " << lIdent.str() << " creation");
                lParameter = ParameterSPtr(new Parameter(*parameterManager, lIdent.str()));
                Process* lProcess = NULL;
                lProcess = ServicesServer::getInstance()->getProcess("tableparamtoparameter", *lParameter.get());
                if (lProcess) {
                    std::stringstream expression;
                    expression << _paramId << "|" << _dim;
                    lProcess->setExpression(expression.str());
                    lProcess->setIsUserProcess(false);
                    DataWriterSPtr lDataWriter(lProcess);
                    lParameter->setDataWriter(lDataWriter);
                } else {
                    BOOST_THROW_EXCEPTION(ParameterManager_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("Cannot found tableparamtoparameter process")));
                }
                parameterManager->addParamInParameterList(lParameter);
            }
            return lParameter;
        }

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
360
361
        std::string ParamBoundsTable::_boundsParamKey = "TABLEPARAM_BOUNDS";

91edc9c0   Benjamin Renard   Add process to tr...
362
363
        ParamBoundsTable::ParamBoundsTable(const char *paramId, int dim) :
        ParamTable(paramId, dim) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
        }

        std::string ParamBoundsTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return ParamBoundsTable::_boundsParamKey;
        }

        /*
         * @brief Get size of the table
         */
        int ParamBoundsTable::getSize(ParameterManager *parameterManager) {
            if (!_variable) {
                std::vector<double> boundsValues = getConstantTableParamValuesByKey(parameterManager, ParamBoundsTable::_boundsParamKey);
                return boundsValues.size() - 1;
            } else {
                return 0;
            }
        }

        /*
         * @brief Get a bounds for a specified index
         */
        t_TableBound ParamBoundsTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound bound;
            bound.index = index;

            std::vector<double> boundsValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamBoundsTable::_boundsParamKey);

            if (boundsValues.empty() || (index >= boundsValues.size() - 1)) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }
            bound.min = std::min(boundsValues[index], boundsValues[index + 1]);
            bound.max = std::max(boundsValues[index], boundsValues[index + 1]);
c2e1eb0f   Erdogan Furkan   More compliant now
399
            bound.center = (bound.min + bound.max) /2.;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
400
401
402
403
404
405

            return bound;
        }

        std::string ParamCenterTable::_centersParamKey = "TABLEPARAM_CENTERS";

91edc9c0   Benjamin Renard   Add process to tr...
406
407
        ParamCenterTable::ParamCenterTable(const char *paramId, int dim, double size) :
        ParamTable(paramId, dim), _size(size) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
        }

        std::string ParamCenterTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return ParamCenterTable::_centersParamKey;
        }

        /*
         * @brief Get size of the table
         */
        int ParamCenterTable::getSize(ParameterManager *parameterManager) {
            if (!_variable) {
                std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterTable::_centersParamKey);
                return centersValues.size();
            } else {
                return 0;
            }
        }

        /*
         * @brief Get a bound for a specified index
         */
        t_TableBound ParamCenterTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound bound;
            bound.index = index;

            std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterTable::_centersParamKey);

            if (index >= centersValues.size()) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

            if (!std::isnan(centersValues[index])) {
                bound.min = centersValues[index] - _size / 2.;
                bound.max = centersValues[index] + _size / 2.;
            } else {
                bound.min = NAN;
                bound.max = NAN;
            }
c2e1eb0f   Erdogan Furkan   More compliant now
449
            bound.center = centersValues[index];
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
450
451
452
453
454
455
            return bound;
        }

        std::string ParamCenterWidthTable::_centersParamKey = "TABLEPARAM_CENTERS";
        std::string ParamCenterWidthTable::_widthsParamKey = "TABLEPARAM_WIDTHS";

91edc9c0   Benjamin Renard   Add process to tr...
456
457
        ParamCenterWidthTable::ParamCenterWidthTable(const char *paramId, int dim) :
        ParamTable(paramId, dim) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
        }

        std::string ParamCenterWidthTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return ParamCenterWidthTable::_centersParamKey;
        }

        /*
         * @brief Get size of the table
         */
        int ParamCenterWidthTable::getSize(ParameterManager *parameterManager) {
            if (!_variable) {
                std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterWidthTable::_centersParamKey);
                return centersValues.size();
            } else {
                return 0;
            }
        }

        /*
         * @brief Get a bound for a specified index
         */
        t_TableBound ParamCenterWidthTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound bound;
            bound.index = index;

            std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterWidthTable::_centersParamKey);
            std::vector<double> widthsValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterWidthTable::_widthsParamKey);

            if ((index >= centersValues.size()) || (index >= widthsValues.size())) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

            if (!std::isnan(centersValues[index]) && !std::isnan(widthsValues[index])) {
                bound.min = centersValues[index] - widthsValues[index] / 2.;
                bound.max = centersValues[index] + widthsValues[index] / 2.;
            } else {
                bound.min = NAN;
                bound.max = NAN;
            }
c2e1eb0f   Erdogan Furkan   More compliant now
500
            bound.center = centersValues[index];
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
501
502
            return bound;
        }
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
503
504
505
        
        std::string EmbeddedCenterTable::_paramKey = "TABLEPARAM_CENTERS";
        
91edc9c0   Benjamin Renard   Add process to tr...
506
507
        EmbeddedCenterTable::EmbeddedCenterTable(const char *paramId, int dim,  std::vector<double> & centersValue, bool logMode):
                          ParamTable(paramId, dim),  _centersValues(centersValue), _log(logMode){
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
508
509
510
511
512
513
        }
        
          std::string EmbeddedCenterTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return EmbeddedCenterTable::_paramKey; 
        }
          
f3cd5351   Hacene SI HADJ MOHAND   us ok
514
      int EmbeddedCenterTable::getSize(ParameterManager*  /*parameterManager*/) {
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
515
516
517
518
                 return _centersValues.size();
        }
             
             
f3cd5351   Hacene SI HADJ MOHAND   us ok
519
            t_TableBound EmbeddedCenterTable::getBound(ParameterManager* /*parameterManager*/, unsigned int index, std::map<std::string, std::vector<double>>* /*paramsTableData*/) {
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
            t_TableBound bound;
            bound.index = index;

            if (index >= _centersValues.size()) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

            //Compute bounds

            if (_centersValues.size() <= 1) {
                LOG4CXX_ERROR(_logger, "Table dimension too small to compute bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }
f3cd5351   Hacene SI HADJ MOHAND   us ok
538
539
540
541
542
543
544
545
546
            if(index == 0 ){
                bound.min = 1.0/((1.0/_centersValues[0]+ 1.0/_centersValues[1])/2);
                bound.max = 2.0*_centersValues[0];
            }else if(index ==_centersValues.size() -1){
                bound.max = 1.0/((1.0/_centersValues[index]+ 1.0/_centersValues[index-1])/2);
                bound.min = _centersValues[index]/2;
            }else{
                bound.min = 1.0/((1.0/_centersValues[index]+ 1.0/_centersValues[index+1])/2);
                bound.max = 1.0/((1.0/_centersValues[index]+ 1.0/_centersValues[index-1])/2);
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
547
            }
c2e1eb0f   Erdogan Furkan   More compliant now
548
            bound.center = _centersValues[index];
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
549
550
551
552
553
554
555
            return bound;
        }
             
        
        /**
         *  ParamCenterAutoTable
         */
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
556
557

        std::string ParamCenterAutoTable::_centersParamKey = "TABLEPARAM_CENTERS";
03aa741e   Hacene SI HADJ MOHAND   adding table but ...
558
        
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
559

91edc9c0   Benjamin Renard   Add process to tr...
560
561
        ParamCenterAutoTable::ParamCenterAutoTable(const char *paramId, int dim, bool log) :
        ParamTable(paramId, dim), _log(log) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
        }

        std::string ParamCenterAutoTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
            return ParamCenterAutoTable::_centersParamKey;
        }

        /*
         * @brief Get size of the table
         */
        int ParamCenterAutoTable::getSize(ParameterManager *parameterManager) {
            if (!_variable) {
                std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterAutoTable::_centersParamKey);
                return centersValues.size();
            } else {
                return 0;
            }
        }

        /*
         * @brief Get a bound for a specified index
         */
        t_TableBound ParamCenterAutoTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound bound;
            bound.index = index;

            std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterAutoTable::_centersParamKey);

            if (index >= centersValues.size()) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

            //Compute bounds

            if (centersValues.size() <= 1) {
                LOG4CXX_ERROR(_logger, "Table dimension too small to compute bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

8cba7bcf   Benjamin Renard   Fix centerAutoTab...
605
606
607
608
609
610
611
612
613
614
            std::vector<double> workingValues;
            for (std::vector<double>::iterator it = centersValues.begin(); it != centersValues.end(); ++it) {
                if (_log) {
                    workingValues.push_back(log10(*it));
                }
                else {
                    workingValues.push_back(*it);
                }
            }

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
615
616
617
618
            double minus = 0.;
            double plus = 0.;

            if (index == 0) {
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
619
620
                if (!std::isnan(workingValues[1]) && !std::isnan(workingValues[0])) {
                        plus = (workingValues[1] - workingValues[0]) / 2.;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
621
622
623
                } else
                    plus = NAN;
                minus = plus;
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
624
625
626
            } else if (index == workingValues.size() - 1) {
                if (!std::isnan(workingValues[workingValues.size() - 1]) && !std::isnan(workingValues[workingValues.size() - 2])) {
                        minus = (workingValues[workingValues.size() - 1] - workingValues[workingValues.size() - 2]) / 2.;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
627
628
629
                } else
                    minus = NAN;
                plus = minus;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
630
            } else {
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
631
632
                if (!std::isnan(workingValues[index]) && !std::isnan(workingValues[index - 1]))
                    minus = (workingValues[index] - workingValues[index - 1]) / 2.;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
633
                else
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
634
635
636
                    minus = NAN;
                if (!std::isnan(workingValues[index + 1]) && !std::isnan(workingValues[index]))
                    plus = (workingValues[index + 1] - workingValues[index]) / 2.;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
637
                else
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
638
                    plus = NAN;
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
639
640
            }

8cba7bcf   Benjamin Renard   Fix centerAutoTab...
641
642
643
644
645
646
647
648
649
            if (!std::isnan(minus))
                bound.min = workingValues[index] - minus;
            else
                bound.min = NAN;
            if (!std::isnan(plus))
                bound.max = workingValues[index] + plus;
            else
                bound.max = NAN;

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
650
651
652
653
654
655
            if (bound.min > bound.max) {
                double temp = bound.max;
                bound.max = bound.min;
                bound.min = temp;
            }

8cba7bcf   Benjamin Renard   Fix centerAutoTab...
656
657
658
659
            if (_log) {
                bound.min = pow(10,bound.min);
                bound.max = pow(10,bound.max);
            }
c2e1eb0f   Erdogan Furkan   More compliant now
660
            bound.center = centersValues[index];
8cba7bcf   Benjamin Renard   Fix centerAutoTab...
661

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
662
663
664
665
666
667
668
            return bound;
        }


        std::string ParamMinMaxTable::_minParamKey = "TABLEPARAM_MIN";
        std::string ParamMinMaxTable::_maxParamKey = "TABLEPARAM_MAX";

91edc9c0   Benjamin Renard   Add process to tr...
669
        ParamMinMaxTable::ParamMinMaxTable(const char *paramId, int dim) : ParamTable(paramId, dim) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
        }

        /*
         * @brief Get size of the table
         */
        int ParamMinMaxTable::getSize(ParameterManager *parameterManager) {
            if (!_variable) {
                std::vector<double> minValues = getConstantTableParamValuesByKey(parameterManager, ParamMinMaxTable::_minParamKey);
                return minValues.size();
            } else {
                return 0;
            }
        }

        /*
         * @brief Get bound for a specified index
         */
        t_TableBound ParamMinMaxTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound bound;
            bound.index = index;

            std::vector<double> minValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamMinMaxTable::_minParamKey);
            std::vector<double> maxValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamMinMaxTable::_maxParamKey);

            if ((index >= minValues.size()) || (index >= maxValues.size())) {
                LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound");
                bound.min = index;
                bound.max = index + 1;
                return bound;
            }

            bound.min = std::min(minValues[index], maxValues[index]);
            bound.max = std::max(minValues[index], maxValues[index]);

c2e1eb0f   Erdogan Furkan   More compliant now
704
705
            bound.center = (bound.min + bound.max)/2.;

b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
706
707
708
            return bound;
        }

91edc9c0   Benjamin Renard   Add process to tr...
709
        LinkTable::LinkTable(const char *paramId, int dim, const char* originParamId) : ParamTable(paramId, dim), _originParamId(originParamId), _originTableDim(0) {
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
710
711
712
713
714
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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
        }

        ParamTable* LinkTable::getOriginParamTable(ParameterManager* parameterManager) {
            if (parameterManager == NULL) {
                return NULL;
            }

            ParameterSPtr tmpParam = parameterManager->getParameter(_originParamId);
            if (tmpParam == nullptr) {
                return NULL;
            }

            ParamInfoSPtr paramInfo = ParamMgr::getInstance()->getParamInfoFromId(tmpParam->getInfoId());
            if (paramInfo == nullptr) {
                return NULL;
            }

            boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr = paramInfo->getTable(_originTableDim);
            if (tableSPtr == nullptr) {
                return NULL;
            }
            return tableSPtr.get();
        }

        std::string LinkTable::getTableParamKeyForInfo(ParameterManager* parameterManager) {
            std::string res = "";
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table != NULL) {
                res = table->getTableParamKeyForInfo(parameterManager);
            }
            return res;
        }

        std::string LinkTable::getName(ParameterManager* parameterManager) {
            std::string res = "";
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table != NULL) {
                res = table->getName(parameterManager);
            }
            return res;
        }

        std::string LinkTable::getUnits(ParameterManager* parameterManager) {
            std::string res = "";
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table != NULL) {
                res = table->getUnits(parameterManager);
            }
            return res;
        }

        bool LinkTable::isVariable(ParameterManager* parameterManager) {
            bool res = false;
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table != NULL) {
                res = table->isVariable(parameterManager);
            }
            return res;
        }
236cd24c   Hacene SI HADJ MOHAND   working in full v...
769
770
771
772
773
774
775
776
777
        
          bool LinkTable::isFullVariable(ParameterManager* parameterManager) {
            bool res = false;
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table != NULL) {
                res = table->isFullVariable(parameterManager);
            }
            return res;
        }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806

        std::map<std::string, std::string>& LinkTable::getTableParams(ParameterManager* parameterManager) {
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table == NULL) {
                return _emptyTableParam;
            }
            return table->getTableParams(parameterManager);
        }

        int LinkTable::getSize(ParameterManager *parameterManager) {
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table == NULL) {
                return 0;
            }
            return table->getSize(parameterManager);
        }

        t_TableBound LinkTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>*paramsTableData) {
            t_TableBound res;
            ParamTable* table = getOriginParamTable(parameterManager);
            if (table == NULL) {
                res.index = index;
                res.min = index;
                res.max = index + 1;
            } else {
                res = table->getBound(parameterManager, index, paramsTableData);
            }
            return res;
        }
d924031c   Hacene SI HADJ MOHAND   progress
807
808
809
810
811
812
813
814
815
        bool ParamTable::isInvertedOrder(ParameterManager *parameterManager){
                if(this->getSize(parameterManager) <2) 
                        return true;
                
                double fist_        = getBound(parameterManager, 0).min; 
                double second_ = getBound(parameterManager, 1).min; 
                
                 return (fist_ > second_);
        }
b31e7a52   Hacene SI HADJ MOHAND   working with mav_st
816
817

    } /* namespace Info */
fbe3c2bb   Benjamin Renard   First commit
818
} /* namespace AMDA */