MexVexElsDecode.hh 3.37 KB
/*
 * MexVexElsDecode.hh
 *
 *  Created on: Oct 13, 2016
 *      Author: elena / benjamin
 */

#ifndef MEXVEXELSDECODE_HH_
#define MEXVEXELSDECODE_HH_

#include "Parameter.hh"
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "Operation.hh"

namespace AMDA {
namespace Parameters {
namespace MexVexElsDecode {

/**
 * @class MexVexElsDecode
 * @brief 
 * @details This class implement the interface Operation.
 */

template <typename TParamData> 
class MexVexElsDecode : public Operation {
	
typedef typename TParamData::ElementType ElemType;

public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
	MexVexElsDecode(Process& pProcess, TParamData& paramInput, std::string energyTable)
	: Operation(pProcess),
	  _paramInput(paramInput),
	  _paramOutput(new TParamData()),
	  _energyTable(energyTable){
	  _paramDataOutput=_paramOutput;
	}

	virtual ~MexVexElsDecode() {
		
	}

	/**
	 * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo)
	 */
  
	void write(ParamDataIndexInfo &pParamDataIndexInfo) {
	  
		ParameterSPtr crtParam = _process.getParameterManager().getParameter(_energyTable);
		ParamData* lModeParamInput = crtParam->getParamData(&_process).get();
		for (unsigned int _index = pParamDataIndexInfo._startIndex ;
			_index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess;
			++_index)
		{
			double crtTime = _paramInput.getTime(_index);
			ElemType inputElt = _paramInput.get(_index);
		
			int mode = (dynamic_cast<ParamDataScalaireShort*>(lModeParamInput))->get(_index);
	     
			if (mode == 1) {
				for (int i = 0; i < 4; ++i){			       
					_paramOutput->pushTime(crtTime+i);
					pushDataForMode1 (inputElt, i);				 
				}
			}
			else if (mode == 0 || mode == 2)			
			{
				_paramOutput->pushTime(crtTime);
				_paramOutput->getDataList().push_back(inputElt);
			}
		}		
	}

	template<typename Type>
	void pushDataForMode1(Type& elt, int index) {
		_paramOutput->getDataList().push_back(elt);
	}

	template<typename Type>
	void pushDataForMode1(std::vector<Type>& elt, int index) {
		typename std::vector<Type>::const_iterator first = elt.begin() + 32 * index;
		typename std::vector<Type>::const_iterator last = elt.begin() + 32 * (index + 1) - 1;
		std::vector<Type> splitVec;
		splitVec.resize(128, std::nan(""));

		int i = 0;
		for (typename std::vector<Type>::const_iterator it = first; it != last; ++it) {
			splitVec[i] = (*it);
			++i;
		}

		_paramOutput->getDataList().push_back(splitVec);
	}		
	
	template<typename Type>  
	void pushDataForMode1(Tab2DData<Type>& elt, int index) {
		Tab2DData<Type> newElt(elt.getDim1Size(),31); 
		for(int i = 0; i < elt.getDim1Size(); ++i) {                        			
			std::vector<Type> eltVector = elt[i].toVector();
			typename std::vector<Type>::const_iterator first = eltVector.begin() + 32 * index;
			typename std::vector<Type>::const_iterator last =  eltVector.begin() + 32 * (index + 1) - 1;
			std::vector<Type> splitVec(first, last);
			newElt[i] = splitVec;
		}                
		_paramOutput->getDataList().push_back(newElt);
	}
  
private:
	/**<
	 * @brief It is the channel of data derived
	 */
	TParamData &_paramInput;

	/**<
	 * @brief It is the channel of the data derived
	 */
	TParamData *_paramOutput;
	
	std::string _energyTable; 
};  

} /* namespace MexVexElsDecode */
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* MEXVEXELSDECODE_HH_ */