ProcessTsyganenko96.cc 5.34 KB
/*
 * ProcessTsyganenko96.cc
 *
 *  Created on: Nov 05, 2017
 *      Author: benjamin
 */
#include <stdlib.h>
#include <string>

#include <boost/lexical_cast.hpp>

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

#include "Operation.hh"
#include "ParameterManager.hh"
#include "ProcessTsyganenko96.hh"
#include "ParamMgr.hh"
#include "ParameterCreatorFromExpression.hh"

using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
namespace Parameters {

  ProcessTsyganenko96::ProcessTsyganenko96(Parameter &parameter, bool inGSE) : SingleParamProcess_CRTP(parameter), _inGSE(inGSE) {
  }

  ProcessTsyganenko96::ProcessTsyganenko96(const ProcessTsyganenko96& pProcess, Parameter &parameter)
    : SingleParamProcess_CRTP(pProcess,parameter), _inGSE(pProcess._inGSE) {
  }

  ProcessTsyganenko96::~ProcessTsyganenko96() {
	if (_inputImfParam != nullptr) {
		_inputImfParam->closeConnection(this);
	}
	if (_inputPswParam != nullptr) {
		_inputPswParam->closeConnection(this);
	}
	if (_inputDstParam != nullptr) {
		_inputDstParam->closeConnection(this);
	}
  }

  void ProcessTsyganenko96::establishConnection() {
	if (_attributList.size() != 3) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTsyganenko96::parse require 3 attributes'")));
	}

	//Imf parameter
	_inputImfParam = _parameter.getParameterManager().getParameter(_attributList[0]);
	if (_inputImfParam == nullptr) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTsyganenko96::parse cannot retrieve imf param")));
	}
	_inputImfParam->openConnection(this);

	//Psw parameter
	_inputPswParam = _parameter.getParameterManager().getParameter(_attributList[1]);
	if (_inputPswParam == nullptr) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTsyganenko96::parse cannot retrieve psw param")));
	}
	_inputPswParam->openConnection(this);

	//Dst parameter
	_inputDstParam = _parameter.getParameterManager().getParameter(_attributList[2]);
	if (_inputDstParam == nullptr) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessTsyganenko96::parse cannot retrieve dst param")));
	}
	_inputDstParam->openConnection(this);

	SingleParamProcess::establishConnection();
  }

  TimeStamp  ProcessTsyganenko96::init() {
	TimeStamp time = _parameterInput->init( this, _timeIntervalList);

	_inputImfParam->init( this, _timeIntervalList);
	ParamData* lImfParamInput = _inputImfParam->getParamData(this).get();

	_inputPswParam->init( this, _timeIntervalList);
	ParamData* lPswParamInput = _inputPswParam->getParamData(this).get();

	_inputDstParam->init( this, _timeIntervalList);
	ParamData* lDstParamInput = _inputDstParam->getParamData(this).get();

	_paramInput = _parameterInput->getParamData(this).get();

	Tsyganenko96Creator lCreator(*this, *_paramInput, *lImfParamInput, *lPswParamInput, *lDstParamInput, _inGSE);
	_operation = lCreator.getOperation();	
	_paramData = ParamDataSPtr(_operation->getParamOutput());
	_paramData->setMinSampling(_paramInput->getMinSampling());
	return time;
}

unsigned int ProcessTsyganenko96::write() {
	getImfData();
	getPswData();
	getDstData();	
	return SingleParamProcess::write();
}

void ProcessTsyganenko96::getImfData() {
	try {
		ParamDataIndexInfo lParamDataIndexInfo;
		lParamDataIndexInfo = _inputImfParam->getAsync(this).get();
		while ((!lParamDataIndexInfo._noMoreTimeInt && !lParamDataIndexInfo._timeIntToProcessChanged) || (lParamDataIndexInfo._nbDataToProcess > 0)) {
			reinterpret_cast<Tsyganenko96::Tsyganenko96Base*>(_operation)->pushImfData(lParamDataIndexInfo);
			if (lParamDataIndexInfo._timeIntToProcessChanged || lParamDataIndexInfo._noMoreTimeInt)
				break;
			lParamDataIndexInfo = _inputImfParam->getAsync(this).get();
		}
	}catch (...) {
		throw;
	}
}

void ProcessTsyganenko96::getPswData() {
	try {
		ParamDataIndexInfo lParamDataIndexInfo;
		lParamDataIndexInfo = _inputPswParam->getAsync(this).get();
		while ((!lParamDataIndexInfo._noMoreTimeInt && !lParamDataIndexInfo._timeIntToProcessChanged) || (lParamDataIndexInfo._nbDataToProcess > 0)) {
			reinterpret_cast<Tsyganenko96::Tsyganenko96Base*>(_operation)->pushPswData(lParamDataIndexInfo);
			if (lParamDataIndexInfo._timeIntToProcessChanged || lParamDataIndexInfo._noMoreTimeInt)
				break;
			lParamDataIndexInfo = _inputPswParam->getAsync(this).get();
		}
	}catch (...) {
		throw;
	}
		
}

void ProcessTsyganenko96::getDstData() {
	try {
		ParamDataIndexInfo lParamDataIndexInfo;
		lParamDataIndexInfo = _inputDstParam->getAsync(this).get();
		while ((!lParamDataIndexInfo._noMoreTimeInt && !lParamDataIndexInfo._timeIntToProcessChanged) || (lParamDataIndexInfo._nbDataToProcess > 0)) {
			reinterpret_cast<Tsyganenko96::Tsyganenko96Base*>(_operation)->pushDstData(lParamDataIndexInfo);
			if (lParamDataIndexInfo._timeIntToProcessChanged || lParamDataIndexInfo._noMoreTimeInt)
				break;
			lParamDataIndexInfo = _inputDstParam->getAsync(this).get();
		}
	}catch (...) {
		throw;
	}
}

ProcessTsyganenko96GSM::ProcessTsyganenko96GSM(Parameter &parameter) : ProcessTsyganenko96(parameter,false) {
}

ProcessTsyganenko96GSE::ProcessTsyganenko96GSE(Parameter &parameter) : ProcessTsyganenko96(parameter,true) {
}

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