ParamTableProcess.cc 2.58 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) {
		}

		ParamTableProcess::ParamTableProcess(const ParamTableProcess& pProcess, Parameter &parameter)
		: MultiParamProcess_CRTP(pProcess,parameter) {
		  //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];
			int 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;
		}

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