ParamTableProcess.cc 3.26 KB
/*
 * ParamTableProcess.cc
 *
 *  Created on: Nov 23, 2022
 *      Author: AKKA
 */

#include "ParamTableProcess.hh"

#include <stdlib.h>
#include <string>

#include "AMDA_exception.hh"
#include "DicError.hh"

#include "ParameterManager.hh"
#include "ParamMgr.hh"
#include "ParamTableOperation.hh"


namespace AMDA {
	namespace Parameters {

		ParamTableProcess::ParamTableProcess(Parameter &parameter)
		  : MultiParamProcess_CRTP(parameter), _dim(0) {
		}

		ParamTableProcess::ParamTableProcess(const ParamTableProcess& pProcess, Parameter &parameter)
		: MultiParamProcess_CRTP(pProcess,parameter), _dim(pProcess._dim) {
		  //Establish Connection Without Parse
		  MultiParamProcess::establishConnection();
		}

		ParamTableProcess::~ParamTableProcess() {
		}

		void ParamTableProcess::establishConnection() {
			std::vector<std::string> strs;
			boost::split(strs, _expression, boost::is_any_of("|"));
			if (strs.size() != 2) {
				BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ParamTableProcess::establishConnection cannot retrieve paramId or dim")));
			}
			std::string paramId = strs[0];
			_dim = std::stoi(strs[1].c_str());
			_paramSPtr = _parameter.getParameterManager().getParameter(paramId);
			_paramNameList[_paramSPtr->getId()].first = _paramSPtr;
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(_paramSPtr->getInfoId());
			if (paramInfo == nullptr) {
				BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ParamTableProcess::establishConnection cannot retrieve param info")));
			}
			_paramTable = paramInfo->getTable(_dim);

			std::map<std::string, std::string> tableParams = _paramTable->getTableParams(&_parameter.getParameterManager());
			for (std::map<std::string, std::string>::iterator it = tableParams.begin(); it != tableParams.end(); ++it) {
				
				AMDA::Parameters::ParameterSPtr p = _parameter.getParameterManager().getParameter(it->second);
				_paramNameList[it->second].first = p;
			}
			
			
			MultiParamProcess::establishConnection();
		}

		TimeStamp ParamTableProcess::init() {
			TimeStamp timeStamp = MultiParamProcess::init();
			//_parameter.init(this, _timeIntervalList);
					
			this->setOperation((Operation*)(new AMDA::Parameters::ParamTable::ParamTableOperation(*this)));
			this->getParamData().reset( this->getOperation()->getParamOutput());
			return timeStamp;
		}

		boost::shared_ptr<AMDA::Info::ParamTable> ParamTableProcess::getParamTable() {
			return _paramTable;
		}

		void ParamTableProcess::updateInfo(Parameter & parameter)
		{
			MultiParamProcess::updateInfo(parameter);
			LOG4CXX_DEBUG(_logger, "ParamTableProcess::updateInfo - " << parameter.getId());

			//Param info
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true);

			if (paramInfo != nullptr)
			{
				paramInfo->resetLinkedParamList();
				std::string processDescription = "Table of ";
				processDescription += _paramSPtr->getInfoId();
				processDescription += " dimension ";
				processDescription += std::to_string(_dim);

				paramInfo->setProcessDescription(processDescription);
			}
		}

	} /* namespace Parameters */
} /* namespace AMDA */