ParamTable.cc 5.34 KB
/**
 * ParamTable.cc
 *
 *  Created on: 10 oct. 2014
 *  Author: AKKA
 */
#include "ParamTable.hh"

#include "Parameter.hh"

using namespace log4cxx;

namespace AMDA {
namespace Info {

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

ParamTable::ParamTable(const char *paramId) : _paramId(paramId),
		_tableName(""), _tableUnits("")
{
}

ParamTable::~ParamTable()
{
}

/*
 * @brief Set name of the table
 */
void ParamTable::setName(std::string name)
{
	_tableName = name;
}

/*
 * @brief Get name of the table
 */
std::string ParamTable::getName(void)
{
	return _tableName;
}

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

/*
 * @brief Get units of the table
 */
std::string ParamTable::getUnits(void)
{
	return _tableUnits;
}

ParamBoundsTable::ParamBoundsTable(const char *paramId, const char *boundsName) :
		ParamTable(paramId), _boundsName(boundsName)
{
}

/*
 * @brief Get size of the table
 */
int ParamBoundsTable::getSize(ParameterManager *parameterManager)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_boundsName];
	return pTableInfo->size() - 1;
}

/*
 * @brief Get a bounds for a specified index
 */
t_TableBound ParamBoundsTable::getBound(ParameterManager *parameterManager, unsigned int index)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);

	t_TableBound bound;
	bound.index = index;

	if (tmpParam == nullptr)
	{
		LOG4CXX_ERROR(_logger, "Associated parameter not reachable!");
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

	//get table info from parameter info list

	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_boundsName];

	if (index >= pTableInfo->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((*pTableInfo)[index], (*pTableInfo)[index+1]);
	bound.max = std::max((*pTableInfo)[index], (*pTableInfo)[index+1]);

	return bound;
}

ParamCenterTable::ParamCenterTable(const char *paramId, const char *centerName, double size) :
		ParamTable(paramId), _centerName(centerName), _size(size)
{
}

/*
 * @brief Get size of the table
 */
int ParamCenterTable::getSize(ParameterManager *parameterManager)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_centerName];
	return pTableInfo->size();
}

/*
 * @brief Get a bound for a specified index
 */
t_TableBound ParamCenterTable::getBound(ParameterManager *parameterManager, unsigned int index)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);

	t_TableBound bound;
	bound.index = index;

	if (tmpParam == nullptr)
	{
		LOG4CXX_ERROR(_logger, "Associated parameter not reachable!");
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

	//get table info from parameter info list

	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableInfo = lInfoList[_centerName];

	if (index >= pTableInfo->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 = (*pTableInfo)[index] - _size/2.;
	bound.max = (*pTableInfo)[index] + _size/2.;;

	return bound;
}

ParamMinMaxTable::ParamMinMaxTable(const char *paramId, const char *minName, const char *maxName) :
										ParamTable(paramId), _minName(minName), _maxName(maxName)
{
}

/*
 * @brief Get size of the table
 */
int ParamMinMaxTable::getSize(ParameterManager *parameterManager)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);
	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableMinInfo = lInfoList[_minName];
	return pTableMinInfo->size();
}

/*
 * @brief Get bound for a specified index
 */
t_TableBound ParamMinMaxTable::getBound(ParameterManager *parameterManager, unsigned int index)
{
	ParameterSPtr tmpParam = parameterManager->getParameter(_paramId);

	t_TableBound bound;
	bound.index = index;

	if (tmpParam == nullptr)
	{
		LOG4CXX_ERROR(_logger, "Associated parameter not reachable!");
		bound.min = index;
		bound.max = index+1;
		return bound;
	}

	//get table info from parameter info list

	AMDA::Parameters::Parameter::InfoList lInfoList = tmpParam->getInfoList();
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableMinInfo = lInfoList[_minName];
	AMDA::Parameters::Parameter::InfoValuesSPtr pTableMaxInfo = lInfoList[_maxName];

	if ((index >= pTableMinInfo->size()) || (index >= pTableMaxInfo->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((*pTableMinInfo)[index], (*pTableMaxInfo)[index]);
	bound.max = std::max((*pTableMinInfo)[index], (*pTableMaxInfo)[index]);

	return bound;
}

} /* namespace Info */
} /* namespace AMDA */