ParamInfo.cc 5.13 KB
/*
 * ParamInfo.cc
 *
 *  Created on: Oct 8, 2014
 *      Author: m.mazel
 */

#include "ParamInfo.hh"

namespace AMDA {
namespace Info {

std::ostream& operator<<(std::ostream& out, const ParamInfo& pi){

	out << "[ParamInfo]" << std::endl;
	out << "{"<<std::endl;
	out << "  _id                 = " << pi._id << std::endl;
	out << "  _name               = " << pi._name << std::endl;
	out << "  _short_name         = " << pi._short_name << std::endl;
	out << "  _components         = " << pi._components << std::endl;
	out << "  _units              = " << pi._units << std::endl;
	out << "  _coordinates_system = " << pi._coordinates_system << std::endl;
	out << "  _tensor_order       = " << pi._tensor_order << std::endl;
	out << "  _si_conversion      = " << pi._si_conversion << std::endl;
	out << "  _fill_value         = " << pi._fill_value << std::endl;
	out << "  _ucd                = " << pi._ucd << std::endl;
	out << "  _statusDef          = ";
	for (auto status : pi._statusDef)
		out  << "[" << status.getMinValue() <<
		", " << status.getMaxValue() <<
		", " << status.getName() << "]," << std::endl;
	out << "  _processInfo        = " << pi._processInfo << std::endl;
	out << "  _processDesc        = " << pi._processDesc << std::endl;
	out << "  _linkedParamList    = ";
	for (auto linkedParam : pi._linkedParamList)
		out << linkedParam << ", ";
	out << std::endl;
	out << "  _dataset_id         = " << pi._dataset_id << std::endl;
	out << "  _instrument_id         = " << pi._dataset_id << std::endl;
	out << "}" << std::endl;
	return out;
}

#define PUSHINFO(infoMap, key, value) if(!value.empty())infoMap.push_back(std::pair<std::string,std::string>(key,value))

std::vector<std::pair<std::string,std::string>> ParamInfo::getInfoMap(ParameterManager *parameterManager)
{
	std::vector<std::pair<std::string,std::string>> infoMap;

	PUSHINFO(infoMap, PARAMETER_ID, getId());
	PUSHINFO(infoMap, PARAMETER_NAME,getName());
	PUSHINFO(infoMap, PARAMETER_SHORT_NAME,getShortName());

	if (getProcessInfo().empty())
	{
		//not a processed param
		PUSHINFO(infoMap, PARAMETER_COMPONENTS, getComponents());
		PUSHINFO(infoMap, PARAMETER_UNITS, getUnits());
		PUSHINFO(infoMap, PARAMETER_COORDSYS, getCoordinatesSystem());
		std::stringstream tensorOrder;
		tensorOrder << getTensorOrder();
		PUSHINFO(infoMap, PARAMETER_TENSOR, tensorOrder.str());
		PUSHINFO(infoMap, PARAMETER_SICONV, getSiConversion());

		if (_tables.empty())
		{
			//no table defined
			PUSHINFO(infoMap, PARAMETER_TABLE, std::string("None"));
		}
		else
		{
			//push tables definition
			for (auto table : _tables)
			{
				std::stringstream tableDim;
				tableDim << table.first;

				std::stringstream infoKey;
				infoKey.str("");
				infoKey << PARAMETER_TABLE << "[" << tableDim.str() << "]";
				PUSHINFO(infoMap, infoKey.str(),table.second->getName(parameterManager));

				infoKey.str("");
				infoKey << PARAMETER_TABLE_UNITS << "[" << tableDim.str() << "]";
				PUSHINFO(infoMap, infoKey.str(), table.second->getUnits(parameterManager));

				//build min and max values list
				std::stringstream tableMinValues;
				std::stringstream tableMaxValues;
				for (int i = 0; i< table.second->getSize(parameterManager); ++i)
				{
					if (i > 0)
					{
						tableMinValues << ",";
						tableMaxValues << ",";
					}
					AMDA::Info::t_TableBound bound = table.second->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());
			}
		}
		std::stringstream fillVal;
		fillVal << getFillValue();
		PUSHINFO(infoMap, PARAMETER_FILLVALUE, fillVal.str());
		PUSHINFO(infoMap, PARAMETER_UCD, getUcd());

		//push status if defined
		if (!_statusDef.empty())
		{
			for (int i = 0; i < (int)_statusDef.size(); ++i)
			{
				std::stringstream statusIndex;
				statusIndex << i;

				std::stringstream crtVal;

				std::stringstream infoKey;
				infoKey.str("");
				infoKey << PARAMETER_STATUS_NAME << "[" << statusIndex.str() << "]";
				PUSHINFO(infoMap, infoKey.str(),_statusDef[i].getName());
				infoKey.str("");
				infoKey << PARAMETER_STATUS_MIN << "[" << statusIndex.str() << "]";
				crtVal.str("");
				crtVal << _statusDef[i].getMinValue();
				PUSHINFO(infoMap, infoKey.str(),crtVal.str());
				infoKey.str("");
				infoKey << PARAMETER_STATUS_MAX << "[" << statusIndex.str() << "]";
				crtVal.str("");
				crtVal << _statusDef[i].getMaxValue();
				PUSHINFO(infoMap, infoKey.str(),crtVal.str());
			}
		}
	}
	else
	{
		//processed parameter
		PUSHINFO(infoMap, PARAMETER_PROCESS_INFO, getProcessInfo());
		PUSHINFO(infoMap, PARAMETER_PROCESS_DESC, getProcessDescription());

		std::stringstream linkedParam;
		bool isFirst = true;
		for (auto param : _linkedParamList)
		{
			if (!isFirst)
				linkedParam << ",";
			isFirst = false;
			linkedParam << param;
		}
		PUSHINFO(infoMap, PARAMETER_LINKED_PARAM, linkedParam.str());
	}

	return infoMap;
}

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