ParamTable.hh 7.04 KB
/**
 * ParamTable.hh
 *
 *  Created on: 10 oct. 2014
 *  Author: AKKA
 */

#ifndef PARAMTABLE_HH_
#define PARAMTABLE_HH_

#include "ParameterManager.hh"

#include "log4cxx/logger.h"

#define PARAMETER_TABLE        "PARAMETER_TABLE_"
#define PARAMETER_TABLE_UNITS  "PARAMETER_TABLE_UNITS"
#define PARAMETER_TABLE_MINVAL "PARAMETER_TABLE_MIN_VALUES"
#define PARAMETER_TABLE_MAXVAL "PARAMETER_TABLE_MAX_VALUES"
#define  VARIABLE_PARAMETER_TABLE  "PARAMETER_TABLE_"

namespace AMDA {
namespace Info {

	using namespace AMDA::Parameters;

	/**
	 * @brief Structure that's define a table bound
	 */
	typedef struct {
		int index;
		double min;
		double max;
	} t_TableBound;

	/**
	 * @class ParamTable
	 * @brief Abstract class used to define a Parameter table .
	 * @details
	 */
	class ParamTable
	{
	public:
		ParamTable(const char *paramId);

		virtual ~ParamTable();

		virtual int getSize(ParameterManager *parameterManager) = 0;

		virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

		virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL) = 0;

		void setParameterLink(ParameterSPtr parameter);

		std::string getParamId(void);

		void setName(std::string name);

		virtual std::string getName(ParameterManager *parameterManager);

		void setUnits(std::string name);

		virtual std::string getUnits(ParameterManager *parameterManager);

		void setIsVariable(bool isVariable);

		virtual bool isVariable(ParameterManager *parameterManager);

		void addTableParam(std::string key, std::string name);

		virtual std::string getTableParamByKey(ParameterManager *parameterManager, std::string key);

		virtual std::map<std::string, std::string>& getTableParams(ParameterManager *parameterManager);
                
                                        void addTableInfo(ParameterManager *parameterManager, int dim, std::vector<std::pair<std::string,std::string>>& infoMap);

	protected:
		/** logger of paramTable */
		static log4cxx::LoggerPtr _logger;

		std::string _paramId;

		std::string _tableName;

		std::string _tableUnits;

		bool _variable;

		std::map<std::string, std::string> _tableParams;

		std::vector<double> getTableParamValuesByKey(ParameterManager *parameterManager, std::map<std::string, std::vector<double>>* paramsTableData, std::string key);

		std::vector<double> getConstantTableParamValuesByKey(ParameterManager *parameterManager, std::string key);

		std::vector<double> getVariableTableParamValuesByKey(ParameterManager *parameterManager, std::map<std::string, std::vector<double>>* paramsTableData, std::string key);

                                        virtual void addVariableTableInfo(ParameterManager *parameterManager, int dim, std::vector<std::pair<std::string,std::string>>& infoMap);
	};

	/**
	 * @class ParamBoundsTable
	 * @brief Implementation of a ParamTable for a table defined by a list
	 * @details
	 */
	class ParamBoundsTable : public ParamTable {
	public:
		ParamBoundsTable(const char *paramId);

		virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

		virtual int getSize(ParameterManager *parameterManager);

		virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);

		static std::string _boundsParamKey;
	};

	/**
	 * @class ParamCenterTable
	 * @brief Implementation of a ParamTable for a table defined by a list of center value and a size
	 * @details
	 */
	class ParamCenterTable : public ParamTable {
	public:
		ParamCenterTable(const char *paramId, double size);

		virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

		virtual int getSize(ParameterManager *parameterManager);

		virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);

		static std::string _centersParamKey;

	private:
		double _size;
	};

	/**
	 * @class ParamCenterWidthTable
	 * @brief Implementation of a ParamTable for a table defined by a list of center value and a list of band width
	 * @details
	 */
	class ParamCenterWidthTable : public ParamTable {
	public:
		ParamCenterWidthTable(const char *paramId);

		virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

		virtual int getSize(ParameterManager *parameterManager);

		virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);

		static std::string _centersParamKey;
		static std::string _widthsParamKey;
	};

	/**
	 * @class ParamCenterAutoTable
	 * @brief Implementation of a ParamTable for a table defined by a list of center value. Bounds automatically computed to be at the center of two consecutive channels
	 * @details
	 */
	class ParamCenterAutoTable : public ParamTable {
	public:
		ParamCenterAutoTable(const char *paramId, bool log);

		virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

		virtual int getSize(ParameterManager *parameterManager);

		virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);
             
		static std::string _centersParamKey;

	private:
		bool _log;
	};

	/**
	 * @class ParamMinMaxTable
	 * @brief Implementation of a ParamTable for a table defined by two list: one for min and one for max
	 * @details
	 */
	class ParamMinMaxTable : public ParamTable {
		public:
			ParamMinMaxTable(const char *paramId);

			virtual int getSize(ParameterManager *parameterManager);

			virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);

			static std::string _minParamKey;
			static std::string _maxParamKey;
	};


	/*
         * @class LinkTable
	 * @brief Implementation of a ParamTable that is a link to an existing ParamTable
	 * @details
	 */
	class LinkTable : public ParamTable {
		public:
			LinkTable(const char *paramId, const char* originParamId);

			virtual int getSize(ParameterManager *parameterManager);

			virtual t_TableBound getBound(ParameterManager *parameterManager, unsigned int index, std::map<std::string, std::vector<double>>* paramsTableData = NULL);

			void setOriginTableDim(int originTableDim) {
				_originTableDim = originTableDim;
			}

			virtual std::string getTableParamKeyForInfo(ParameterManager *parameterManager);

			virtual std::string getName(ParameterManager *parameterManager);

			virtual std::string getUnits(ParameterManager *parameterManager);

			virtual bool isVariable(ParameterManager *parameterManager);

			virtual std::map<std::string, std::string>& getTableParams(ParameterManager *parameterManager);

		private:
			std::string _originParamId;
			int _originTableDim;
			std::map<std::string, std::string> _emptyTableParam;

			ParamTable* getOriginParamTable(ParameterManager *parameterManager);
	};

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

#endif /* PARAMTABLE_HH_ */