ProcessGtlLEPBCalculate.cc 3.93 KB
/*
 * ProcessGtlLEPBCalculate.cc
 *
 *  Created on: Oct 14, 2016
 *      Author: elena
 */
#include <stdlib.h>
#include <string>

#include <boost/lexical_cast.hpp>

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

#include "Operation.hh"
#include "ParameterManager.hh"
#include "ProcessGtlLEPBCalculate.hh"
#include "GtlLEPBCalculateCreator.hh"
#include "ParamMgr.hh"
#include "ParameterCreatorFromExpression.hh"

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

namespace AMDA {
namespace Parameters {

double LEPB_DIR[4][2] = {
	{135.00, 225.00},// tailward
	{225.00, 315}, // dawnward
	{-45.00, 45.00}, // sunward
	{45.00, 135.00} // duskward
};


  ProcessGtlLEPBCalculate::ProcessGtlLEPBCalculate(Parameter &parameter) : MultiParamProcess_CRTP(parameter),
  				_isAnisotropy(false), _valueMin(0.), _valueMax(0.) {
  }

  ProcessGtlLEPBCalculate::ProcessGtlLEPBCalculate(const ProcessGtlLEPBCalculate& pProcess, Parameter &parameter)
    : MultiParamProcess_CRTP(pProcess,parameter), _isAnisotropy(pProcess._isAnisotropy), _inputParamName(pProcess._inputParamName),
		_azimuthParamName(pProcess._azimuthParamName), _valueMin(pProcess._valueMin), _valueMax(pProcess._valueMax)  {
  }

  ProcessGtlLEPBCalculate::~ProcessGtlLEPBCalculate() {
  }

  void ProcessGtlLEPBCalculate::parse() {
  	ParameterCreatorFromExpression creator(_parameter.getParameterManager());
  	ParameterSPtr lParameter = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
  	_paramNameList[lParameter->getId()].first = lParameter;
	_inputParamName = lParameter->getId();
  	
	if (_attributList.size() < 3) {
  		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessGtlLEPBCalculate::parse require at least 3 attributes'")));
  	}

	if (_attributList[0] != _expression) {
		lParameter = creator.getOneParameterFromExpression(_parameter,_attributList[0], isUserProcess());
		_paramNameList[lParameter->getId()].first = lParameter;
		_azimuthParamName = lParameter->getId();
	}
	else {
		_azimuthParamName = lParameter->getId();
	}

	if (_attributList[1] != _expression) {
		lParameter = creator.getOneParameterFromExpression(_parameter,_attributList[1], isUserProcess());
		_paramNameList[lParameter->getId()].first = lParameter;
		_energyParamName = lParameter->getId();
	}
	else {
		_energyParamName = lParameter->getId();
	}

	if (!_isAnisotropy && (_attributList.size() == 3)) {
		int dirIndex = atoi(_attributList[2].c_str());
		if (dirIndex < 0 || dirIndex > 3) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessGtlLEPBCalculate::parse outside available sectors'")));
		}
		_valueMin = LEPB_DIR[dirIndex][0];
		_valueMax = LEPB_DIR[dirIndex][1];
	}
	else {
		_valueMin = atof(_attributList[2].c_str());
		_valueMax = atof(_attributList[3].c_str());
	}
  }

  void ProcessGtlLEPBCalculate::establishConnection() {
  	parse();
  	MultiParamProcess::establishConnection();
  }

  TimeStamp  ProcessGtlLEPBCalculate::init() {
	TimeStamp timeStamp = MultiParamProcess::init();

	ParamData* lmainParamInput = _paramNameList[_inputParamName].first->getParamData(this).get();

	ParamData* lazimuthParamInput = _paramNameList[_azimuthParamName].first->getParamData(this).get();

	ParamData* lenergyParamInput = _paramNameList[_energyParamName].first->getParamData(this).get();

	GtlLEPBCalculateCreator lGtlLEPBCalculateCreator(*this, *lmainParamInput, *lazimuthParamInput, *lenergyParamInput, 
													_valueMin, _valueMax, _isAnisotropy);

	_operation = lGtlLEPBCalculateCreator.getOperation();	
	_paramData = ParamDataSPtr(_operation->getParamOutput());
	_paramData->setMinSampling(lmainParamInput->getMinSampling());

	return timeStamp;
}

ProcessGtlLEPBAnisotropyCalculate::ProcessGtlLEPBAnisotropyCalculate(Parameter &parameter) : ProcessGtlLEPBCalculate(parameter) {
	_isAnisotropy = true;
}




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