Blame view

src/Info/ParamTable.cc 15.9 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"
fbe3c2bb   Benjamin Renard   First commit
13
14
15
16
17
18
19
20
21

using namespace log4cxx;

namespace AMDA {
namespace Info {

LoggerPtr ParamTable::_logger(Logger::getLogger("AMDA-Kernel.ParamTable"));

ParamTable::ParamTable(const char *paramId) : _paramId(paramId),
f2db3c16   Benjamin Renard   Support variable ...
22
		_tableName(""), _tableUnits(""), _variable("false")
fbe3c2bb   Benjamin Renard   First commit
23
24
25
26
27
28
29
{
}

ParamTable::~ParamTable()
{
}

e7ea756d   Benjamin Renard   Implements tables...
30
std::string ParamTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
3fe8b83d   Benjamin Renard   Get parameter inf...
31
32
33
	return "";
}

fbe3c2bb   Benjamin Renard   First commit
34
/*
7f7e3b39   Benjamin Renard   Fix a bug with st...
35
36
37
38
39
40
41
42
 * @brief Get param id
 */
std::string ParamTable::getParamId(void)
{
	return _paramId;
}

/*
fbe3c2bb   Benjamin Renard   First commit
43
44
45
46
47
48
49
50
51
52
 * @brief Set name of the table
 */
void ParamTable::setName(std::string name)
{
	_tableName = name;
}

/*
 * @brief Get name of the table
 */
e7ea756d   Benjamin Renard   Implements tables...
53
std::string ParamTable::getName(ParameterManager* parameterManager)
fbe3c2bb   Benjamin Renard   First commit
54
{
3fe8b83d   Benjamin Renard   Get parameter inf...
55
	if (_tableName.empty() && _variable) {
e7ea756d   Benjamin Renard   Implements tables...
56
		std::string paramKeyForInfo = getTableParamKeyForInfo(parameterManager);
3fe8b83d   Benjamin Renard   Get parameter inf...
57
		if (!paramKeyForInfo.empty()) {
e7ea756d   Benjamin Renard   Implements tables...
58
			std::string tableParam = getTableParamByKey(parameterManager, paramKeyForInfo);
3fe8b83d   Benjamin Renard   Get parameter inf...
59
60
61
62
63
64
			AMDA::Info::ParamInfoSPtr paramTableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParam);
			if (paramTableInfo != nullptr)
				return paramTableInfo->getName();
		}
	}

fbe3c2bb   Benjamin Renard   First commit
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	return _tableName;
}

/*
 * @brief Set units
 */
void ParamTable::setUnits(std::string units)
{
	_tableUnits = units;
}

/*
 * @brief Get units of the table
 */
e7ea756d   Benjamin Renard   Implements tables...
79
std::string ParamTable::getUnits(ParameterManager* parameterManager)
fbe3c2bb   Benjamin Renard   First commit
80
{
3fe8b83d   Benjamin Renard   Get parameter inf...
81
	if (_tableName.empty() && _variable) {
e7ea756d   Benjamin Renard   Implements tables...
82
		std::string paramKeyForInfo = getTableParamKeyForInfo(parameterManager);
3fe8b83d   Benjamin Renard   Get parameter inf...
83
		if (!paramKeyForInfo.empty()) {
e7ea756d   Benjamin Renard   Implements tables...
84
			std::string tableParam = getTableParamByKey(parameterManager, paramKeyForInfo);
3fe8b83d   Benjamin Renard   Get parameter inf...
85
86
87
88
89
90
			AMDA::Info::ParamInfoSPtr paramTableInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(tableParam);
			if (paramTableInfo != nullptr)
				return paramTableInfo->getUnits();
		}
	}

fbe3c2bb   Benjamin Renard   First commit
91
92
93
	return _tableUnits;
}

f2db3c16   Benjamin Renard   Support variable ...
94
95
96
97
/*
 * @brief Set isVariable attribute
 */
void ParamTable::setIsVariable(bool isVariable)
fbe3c2bb   Benjamin Renard   First commit
98
{
f2db3c16   Benjamin Renard   Support variable ...
99
	_variable = isVariable;
fbe3c2bb   Benjamin Renard   First commit
100
101
102
}

/*
f2db3c16   Benjamin Renard   Support variable ...
103
 * @brief Get if it's a variable table
fbe3c2bb   Benjamin Renard   First commit
104
 */
e7ea756d   Benjamin Renard   Implements tables...
105
bool ParamTable::isVariable(ParameterManager* /*parameterManager*/)
fbe3c2bb   Benjamin Renard   First commit
106
{
f2db3c16   Benjamin Renard   Support variable ...
107
108
109
110
111
112
113
114
	return _variable;
}

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

e7ea756d   Benjamin Renard   Implements tables...
115
std::string ParamTable::getTableParamByKey(ParameterManager* /*parameterManager*/, std::string key)
f2db3c16   Benjamin Renard   Support variable ...
116
117
118
119
{
	return _tableParams[key];
}

e7ea756d   Benjamin Renard   Implements tables...
120
std::map<std::string, std::string>& ParamTable::getTableParams(ParameterManager* /*parameterManager*/)
f2db3c16   Benjamin Renard   Support variable ...
121
122
123
124
125
126
127
{
	return _tableParams;
}

std::vector<double> ParamTable::getConstantTableParamValuesByKey(ParameterManager *parameterManager, std::string key)
{
	std::vector<double> paramValues;
fbe3c2bb   Benjamin Renard   First commit
128
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
f2db3c16   Benjamin Renard   Support variable ...
129
130
	if (tmpParam == nullptr)
		return paramValues;
fbe3c2bb   Benjamin Renard   First commit
131
	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
f2db3c16   Benjamin Renard   Support variable ...
132
133
134
135
136
137
138
139
140
	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;
}

e7ea756d   Benjamin Renard   Implements tables...
141
std::vector<double> ParamTable::getVariableTableParamValuesByKey(ParameterManager* /*parameterManager*/, std::map<std::string, std::vector<double>>* paramsTableData, std::string key)
f2db3c16   Benjamin Renard   Support variable ...
142
143
144
145
146
147
148
149
150
151
152
153
{
	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)
e7ea756d   Benjamin Renard   Implements tables...
154
		return getVariableTableParamValuesByKey(parameterManager, paramsTableData, key);
f2db3c16   Benjamin Renard   Support variable ...
155
156
157
158
159
160
161
162
163
	else
		return getConstantTableParamValuesByKey(parameterManager, key);
}

std::string ParamBoundsTable::_boundsParamKey = "TABLEPARAM_BOUNDS";

ParamBoundsTable::ParamBoundsTable(const char *paramId) :
		ParamTable(paramId)
{
fbe3c2bb   Benjamin Renard   First commit
164
165
}

e7ea756d   Benjamin Renard   Implements tables...
166
std::string ParamBoundsTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
3fe8b83d   Benjamin Renard   Get parameter inf...
167
168
169
	return ParamBoundsTable::_boundsParamKey;
}

fbe3c2bb   Benjamin Renard   First commit
170
/*
f2db3c16   Benjamin Renard   Support variable ...
171
 * @brief Get size of the table
fbe3c2bb   Benjamin Renard   First commit
172
 */
f2db3c16   Benjamin Renard   Support variable ...
173
int ParamBoundsTable::getSize(ParameterManager *parameterManager)
fbe3c2bb   Benjamin Renard   First commit
174
{
f2db3c16   Benjamin Renard   Support variable ...
175
176
177
178
179
180
181
182
183
184
	if (!_variable)
	{
		std::vector<double> boundsValues = getConstantTableParamValuesByKey(parameterManager, ParamBoundsTable::_boundsParamKey);
		return boundsValues.size() - 1;
	}
	else
	{
		return 0;
	}
}
fbe3c2bb   Benjamin Renard   First commit
185

f2db3c16   Benjamin Renard   Support variable ...
186
187
188
189
190
/*
 * @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)
{
fbe3c2bb   Benjamin Renard   First commit
191
192
	t_TableBound bound;
	bound.index = index;
fbe3c2bb   Benjamin Renard   First commit
193

f2db3c16   Benjamin Renard   Support variable ...
194
195
	std::vector<double> boundsValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamBoundsTable::_boundsParamKey);

a9510a8c   Benjamin Renard   Fix sum in range ...
196
	if (boundsValues.empty() || (index >= boundsValues.size() - 1))
fbe3c2bb   Benjamin Renard   First commit
197
198
199
200
201
202
	{
		LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}
f2db3c16   Benjamin Renard   Support variable ...
203
204
	bound.min = std::min(boundsValues[index], boundsValues[index+1]);
	bound.max = std::max(boundsValues[index], boundsValues[index+1]);
fbe3c2bb   Benjamin Renard   First commit
205
206
207
208

	return bound;
}

f2db3c16   Benjamin Renard   Support variable ...
209
210
211
212
std::string ParamCenterTable::_centersParamKey = "TABLEPARAM_CENTERS";

ParamCenterTable::ParamCenterTable(const char *paramId, double size) :
		ParamTable(paramId), _size(size)
fbe3c2bb   Benjamin Renard   First commit
213
214
215
{
}

e7ea756d   Benjamin Renard   Implements tables...
216
std::string ParamCenterTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
3fe8b83d   Benjamin Renard   Get parameter inf...
217
218
219
	return ParamCenterTable::_centersParamKey;
}

fbe3c2bb   Benjamin Renard   First commit
220
221
222
223
224
/*
 * @brief Get size of the table
 */
int ParamCenterTable::getSize(ParameterManager *parameterManager)
{
f2db3c16   Benjamin Renard   Support variable ...
225
226
227
228
229
230
231
232
233
	if (!_variable)
	{
		std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterTable::_centersParamKey);
		return centersValues.size();
	}
	else
	{
		return 0;
	}
fbe3c2bb   Benjamin Renard   First commit
234
235
236
237
238
}

/*
 * @brief Get a bound for a specified index
 */
f2db3c16   Benjamin Renard   Support variable ...
239
t_TableBound ParamCenterTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData)
fbe3c2bb   Benjamin Renard   First commit
240
{
fbe3c2bb   Benjamin Renard   First commit
241
242
243
	t_TableBound bound;
	bound.index = index;

f2db3c16   Benjamin Renard   Support variable ...
244
	std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterTable::_centersParamKey);
fbe3c2bb   Benjamin Renard   First commit
245

f2db3c16   Benjamin Renard   Support variable ...
246
	if (index >= centersValues.size())
fbe3c2bb   Benjamin Renard   First commit
247
248
249
250
251
252
253
	{
		LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
254
255
256
257
258
259
260
261
262
263
	if (!std::isnan(centersValues[index]))
	{
		bound.min = centersValues[index] - _size/2.;
		bound.max = centersValues[index] + _size/2.;
	}
	else
	{
		bound.min = NAN;
		bound.max = NAN;
	}
fbe3c2bb   Benjamin Renard   First commit
264
265
266
267

	return bound;
}

f2db3c16   Benjamin Renard   Support variable ...
268
269
270
271
272
std::string ParamCenterWidthTable::_centersParamKey = "TABLEPARAM_CENTERS";
std::string ParamCenterWidthTable::_widthsParamKey = "TABLEPARAM_WIDTHS";

ParamCenterWidthTable::ParamCenterWidthTable(const char *paramId) :
		ParamTable(paramId)
f5c53312   Benjamin Renard   Get calib info in...
273
274
275
{
}

e7ea756d   Benjamin Renard   Implements tables...
276
std::string ParamCenterWidthTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
3fe8b83d   Benjamin Renard   Get parameter inf...
277
278
279
	return ParamCenterWidthTable::_centersParamKey;
}

f5c53312   Benjamin Renard   Get calib info in...
280
281
282
283
284
/*
 * @brief Get size of the table
 */
int ParamCenterWidthTable::getSize(ParameterManager *parameterManager)
{
f2db3c16   Benjamin Renard   Support variable ...
285
286
287
288
289
290
291
292
293
	if (!_variable)
	{
		std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterWidthTable::_centersParamKey);
		return centersValues.size();
	}
	else
	{
		return 0;
	}
f5c53312   Benjamin Renard   Get calib info in...
294
295
296
297
298
}

/*
 * @brief Get a bound for a specified index
 */
f2db3c16   Benjamin Renard   Support variable ...
299
t_TableBound ParamCenterWidthTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData)
f5c53312   Benjamin Renard   Get calib info in...
300
{
f5c53312   Benjamin Renard   Get calib info in...
301
302
303
	t_TableBound bound;
	bound.index = index;

f2db3c16   Benjamin Renard   Support variable ...
304
	std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterWidthTable::_centersParamKey);
5442b756   Benjamin Renard   Fix a bug in Para...
305
	std::vector<double> widthsValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterWidthTable::_widthsParamKey);
f5c53312   Benjamin Renard   Get calib info in...
306

f2db3c16   Benjamin Renard   Support variable ...
307
	if ((index >= centersValues.size()) || (index >= widthsValues.size()))
f5c53312   Benjamin Renard   Get calib info in...
308
309
310
311
312
313
314
	{
		LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
315
316
317
318
319
320
321
322
323
324
	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;
	}
f5c53312   Benjamin Renard   Get calib info in...
325
326
327
328

	return bound;
}

f2db3c16   Benjamin Renard   Support variable ...
329
330
331
332
std::string ParamCenterAutoTable::_centersParamKey = "TABLEPARAM_CENTERS";

ParamCenterAutoTable::ParamCenterAutoTable(const char *paramId, bool log) :
		ParamTable(paramId), _log(log)
65c661e8   Benjamin Renard   Table definition ...
333
334
335
{
}

e7ea756d   Benjamin Renard   Implements tables...
336
std::string ParamCenterAutoTable::getTableParamKeyForInfo(ParameterManager* /*parameterManager*/) {
3fe8b83d   Benjamin Renard   Get parameter inf...
337
338
339
	return ParamCenterAutoTable::_centersParamKey;
}

65c661e8   Benjamin Renard   Table definition ...
340
341
342
343
344
/*
 * @brief Get size of the table
 */
int ParamCenterAutoTable::getSize(ParameterManager *parameterManager)
{
f2db3c16   Benjamin Renard   Support variable ...
345
346
347
348
349
350
351
352
353
	if (!_variable)
	{
		std::vector<double> centersValues = getConstantTableParamValuesByKey(parameterManager, ParamCenterAutoTable::_centersParamKey);
		return centersValues.size();
	}
	else
	{
		return 0;
	}
65c661e8   Benjamin Renard   Table definition ...
354
355
356
357
358
}

/*
 * @brief Get a bound for a specified index
 */
f2db3c16   Benjamin Renard   Support variable ...
359
t_TableBound ParamCenterAutoTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData)
65c661e8   Benjamin Renard   Table definition ...
360
{
65c661e8   Benjamin Renard   Table definition ...
361
362
363
	t_TableBound bound;
	bound.index = index;

f2db3c16   Benjamin Renard   Support variable ...
364
	std::vector<double> centersValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamCenterAutoTable::_centersParamKey);
65c661e8   Benjamin Renard   Table definition ...
365

f2db3c16   Benjamin Renard   Support variable ...
366
	if (index >= centersValues.size())
65c661e8   Benjamin Renard   Table definition ...
367
368
369
370
371
372
373
374
375
	{
		LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

	//Compute bounds

f2db3c16   Benjamin Renard   Support variable ...
376
	if (centersValues.size() <= 1)
65c661e8   Benjamin Renard   Table definition ...
377
378
379
380
381
382
383
384
385
386
387
388
	{
		LOG4CXX_ERROR(_logger, "Table dimension too small to compute bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

	double minus = 0.;
	double plus  = 0.;

	if (index == 0)
	{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
389
390
391
392
393
394
395
		if (!std::isnan(centersValues[1]) && !std::isnan(centersValues[0]))
		{
			if (_log)
				plus  = (log10(centersValues[1]) - log10(centersValues[0]))/2.;
			else
				plus  = (centersValues[1] - centersValues[0])/2.;
		}
65c661e8   Benjamin Renard   Table definition ...
396
		else
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
397
			plus = NAN;
65c661e8   Benjamin Renard   Table definition ...
398
399
		minus = plus;
	}
f2db3c16   Benjamin Renard   Support variable ...
400
	else if (index == centersValues.size() - 1)
65c661e8   Benjamin Renard   Table definition ...
401
	{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
402
403
404
405
406
407
408
		if (!std::isnan(centersValues[centersValues.size() - 1]) && !std::isnan(centersValues[centersValues.size() - 2]))
		{
			if (_log)
				minus = (log10(centersValues[centersValues.size() - 1]) - log10(centersValues[centersValues.size() - 2]))/2.;
			else
				minus = (centersValues[centersValues.size() - 1] - centersValues[centersValues.size() - 2])/2.;
		}
65c661e8   Benjamin Renard   Table definition ...
409
		else
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
410
			minus = NAN;
65c661e8   Benjamin Renard   Table definition ...
411
412
413
414
415
416
417
		plus  = minus;

	}
	else
	{
		if (_log)
		{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
418
419
420
421
422
423
424
425
			if (!std::isnan(centersValues[index]) && !std::isnan(centersValues[index-1]) && (centersValues[index] > 0) && (centersValues[index-1] > 0))
				minus = (log10(centersValues[index]) - log10(centersValues[index-1]))/2.;
			else
				minus = NAN;
			if (!std::isnan(centersValues[index+1]) && !std::isnan(centersValues[index]) && (centersValues[index+1] > 0) && (centersValues[index] > 0))
				plus  = (log10(centersValues[index+1]) - log10(centersValues[index]))/2.;
			else
				plus = NAN;
65c661e8   Benjamin Renard   Table definition ...
426
427
428
		}
		else
		{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
429
430
431
432
433
434
435
436
			if (!std::isnan(centersValues[index]) && !std::isnan(centersValues[index-1]))
				minus = (centersValues[index] - centersValues[index-1])/2.;
			else
				minus = NAN;
			if (!std::isnan(centersValues[index+1]) && !std::isnan(centersValues[index]))
				plus  = (centersValues[index+1] - centersValues[index])/2.;
			else
				plus = NAN;
65c661e8   Benjamin Renard   Table definition ...
437
438
439
		}
	}

f2db3c16   Benjamin Renard   Support variable ...
440
441
	if (_log)
	{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
442
443
444
445
446
447
448
449
		if (!std::isnan(minus))
			bound.min = exp(log10(centersValues[index]) - minus);
		else
			bound.min = NAN;
		if (!std::isnan(plus))
			bound.max = exp(log10(centersValues[index]) + plus);
		else
			bound.max = NAN;
f2db3c16   Benjamin Renard   Support variable ...
450
451
452
	}
	else
	{
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
453
454
455
456
457
458
459
460
		if (!std::isnan(minus))
			bound.min = centersValues[index] - minus;
		else
			bound.min = NAN;
		if (!std::isnan(plus))
			bound.max = centersValues[index] + plus;
		else
			bound.max = NAN;
f2db3c16   Benjamin Renard   Support variable ...
461
	}
65c661e8   Benjamin Renard   Table definition ...
462
463
464
465
466
467
468
469
470
471
472

	if (bound.min > bound.max)
	{
		double temp = bound.max;
		bound.max = bound.min;
		bound.min = temp;
	}

	return bound;
}

f2db3c16   Benjamin Renard   Support variable ...
473
474
475
476
std::string ParamMinMaxTable::_minParamKey = "TABLEPARAM_MIN";
std::string ParamMinMaxTable::_maxParamKey = "TABLEPARAM_MAX";

ParamMinMaxTable::ParamMinMaxTable(const char *paramId) : ParamTable(paramId)
fbe3c2bb   Benjamin Renard   First commit
477
478
479
480
481
482
483
484
{
}

/*
 * @brief Get size of the table
 */
int ParamMinMaxTable::getSize(ParameterManager *parameterManager)
{
f2db3c16   Benjamin Renard   Support variable ...
485
486
487
488
489
490
491
492
493
	if (!_variable)
	{
		std::vector<double> minValues = getConstantTableParamValuesByKey(parameterManager, ParamMinMaxTable::_minParamKey);
		return minValues.size();
	}
	else
	{
		return 0;
	}
fbe3c2bb   Benjamin Renard   First commit
494
495
496
497
498
}

/*
 * @brief Get bound for a specified index
 */
f2db3c16   Benjamin Renard   Support variable ...
499
t_TableBound ParamMinMaxTable::getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData)
fbe3c2bb   Benjamin Renard   First commit
500
{
fbe3c2bb   Benjamin Renard   First commit
501
502
503
	t_TableBound bound;
	bound.index = index;

f2db3c16   Benjamin Renard   Support variable ...
504
505
	std::vector<double> minValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamMinMaxTable::_minParamKey);
	std::vector<double> maxValues = getTableParamValuesByKey(parameterManager, paramsTableData, ParamMinMaxTable::_maxParamKey);
fbe3c2bb   Benjamin Renard   First commit
506

f2db3c16   Benjamin Renard   Support variable ...
507
	if ((index >= minValues.size()) || (index >= maxValues.size()))
fbe3c2bb   Benjamin Renard   First commit
508
509
510
511
512
513
514
	{
		LOG4CXX_ERROR(_logger, "Index " << index << " outside of table definition => Cannot get real bound" );
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

f2db3c16   Benjamin Renard   Support variable ...
515
516
	bound.min = std::min(minValues[index], maxValues[index]);
	bound.max = std::max(minValues[index], maxValues[index]);
fbe3c2bb   Benjamin Renard   First commit
517
518
519
520

	return bound;
}

e7ea756d   Benjamin Renard   Implements tables...
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
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
605
606
607
608
609
610
611
612
613

LinkTable::LinkTable(const char *paramId, const char* originParamId) : ParamTable(paramId), _originParamId(originParamId), _originTableDim(0)
{
}

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

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

fbe3c2bb   Benjamin Renard   First commit
614
615
} /* namespace Info */
} /* namespace AMDA */