/* * SumIntoTableIndexes.hh * * Created on: Mar 26, 2019 * Author: AKKA IS */ #ifndef SUMINTOTABLEINDEXES_HH_ #define SUMINTOTABLEINDEXES_HH_ #include "Parameter.hh" #include "ParamData.hh" #include "DataTypeMath.hh" #include "Operation.hh" namespace AMDA { namespace Parameters { namespace SumIntoTableIndexes { /** * @class SumIntoTableIndexes1D * @brief It is responsible to compute the sum of 1D parameter data into a table of indexes. * @details This class implement the interface Operation. */ template class SumIntoTableIndexes1D : public Operation { public: /** * @brief Constructor. * @details Create the ParamData type of the input ParamData. */ SumIntoTableIndexes1D(Process& pProcess, ParamDataSpec >& paramInput, int minIndex, int maxIndex) : Operation(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataSpec()), _minIndex(minIndex), _maxIndex(maxIndex) { _paramDataOutput=_paramOutput; } virtual ~SumIntoTableIndexes1D() { } /** * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo) */ void write(ParamDataIndexInfo &pParamDataIndexInfo) { for (unsigned int _index = pParamDataIndexInfo._startIndex ; _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; ++_index) { double crtTime = _paramInput.getTime(_index); std::vector inputElt = _paramInput.get(_index); DataType output = 0; for (int i = _minIndex; i <= _maxIndex; ++i) { if ((i >= inputElt.size()) || isNAN(inputElt[i])) continue; output += inputElt[i]; } _paramOutput->pushTime(crtTime); _paramOutput->getDataList().push_back(output); } } private: /**< * @brief It is the channel of data derived */ ParamDataSpec > &_paramInput; /**< * @brief It is the channel of the data derived */ ParamDataSpec *_paramOutput; int _minIndex; int _maxIndex; }; /** * @class SumIntoTableIndexes2DOneRange * @brief It is responsible to compute the sum of 2D parameter data into one table indexes. * @details This class implement the interface Operation. */ template class SumIntoTableIndexes2DOneRange : public Operation { public: /** * @brief Constructor. * @details Create the ParamData type of the input ParamData when only one range is defined for one dimension (the output data is a vector). */ SumIntoTableIndexes2DOneRange(Process& pProcess, ParamDataSpec >& paramInput, int minIndex, int maxIndex, int tableRelatedDim) : Operation(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataSpec>()), _tableRelatedDim(tableRelatedDim), _minIndex(minIndex), _maxIndex(maxIndex) { _paramDataOutput = _paramOutput; } virtual ~SumIntoTableIndexes2DOneRange() { } /** * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo) */ void write(ParamDataIndexInfo &pParamDataIndexInfo) { for (unsigned int _index = pParamDataIndexInfo._startIndex ; _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; ++_index) { double crtTime = _paramInput.getTime(_index); Tab2DData inputElt = _paramInput.get(_index); std::vector outputElt; if (_tableRelatedDim == 0) { outputElt.resize(inputElt.getDim2Size(), 0); for (int i = _minIndex; i <= _maxIndex; ++i) { for (int j = 0; j < inputElt.getDim2Size(); ++j) { if (isNAN(inputElt[i][j])) continue; outputElt[j] += inputElt[i][j]; } } } else { outputElt.resize(inputElt.getDim1Size(), 0); for (int j = _minIndex; j <= _maxIndex; ++j) { for (int i = 0; i < inputElt.getDim1Size(); ++i) { if (isNAN(inputElt[i][j])) continue; outputElt[i] += inputElt[i][j]; } } } _paramOutput->pushTime(crtTime); _paramOutput->getDataList().push_back(outputElt); } } private: /**< * @brief It is the channel of data derived */ ParamDataSpec > &_paramInput; ParamDataSpec> *_paramOutput; int _tableRelatedDim; int _minIndex; int _maxIndex; }; /** * @class SumIntoIndexesTable2DTwoRanges * @brief It is responsible to compute the sum of 2D parameter data into two tables ranges of indexes. * @details This class implement the interface Operation. */ template class SumIntoTableIndexes2DTwoRanges : public Operation { public: /** * @brief Constructor. * @details Create the ParamData type of the input ParamData when a range is defined for each dimensions (the output data is a scalar). */ SumIntoTableIndexes2DTwoRanges(Process& pProcess, ParamDataSpec >& paramInput, int minIndex1, int maxIndex1, int table1RelatedDim, int minIndex2, int maxIndex2) : Operation(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataSpec()), _table1RelatedDim(table1RelatedDim), _minIndex1(minIndex1), _maxIndex1(maxIndex1), _minIndex2(minIndex2), _maxIndex2(maxIndex2) { _paramDataOutput = _paramOutput; } virtual ~SumIntoTableIndexes2DTwoRanges() { } /** * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo) */ void write(ParamDataIndexInfo &pParamDataIndexInfo) { for (unsigned int _index = pParamDataIndexInfo._startIndex ; _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; ++_index) { double crtTime = _paramInput.getTime(_index); Tab2DData inputElt = _paramInput.get(_index); DataType outputElt = 0; for (int i = _minIndex1; i <= _maxIndex1; ++i) { for (int j = _minIndex2; j <= _maxIndex2; ++j) { if (_table1RelatedDim == 0) { if (isNAN(inputElt[i][j])) continue; outputElt += inputElt[i][j]; } else { if (isNAN(inputElt[j][i])) continue; outputElt += inputElt[j][i]; } } } _paramOutput->pushTime(crtTime); _paramOutput->getDataList().push_back(outputElt); } } private: /**< * @brief It is the channel of data derived */ ParamDataSpec > &_paramInput; ParamDataSpec *_paramOutput; int _table1RelatedDim; int _minIndex1; int _maxIndex1; int _minIndex2; int _maxIndex2; }; } /* namespace SumIntoTableIndexes */ } /* namespace Parameters */ } /* namespace AMDA */ #endif /* SUMINTOTABLEINDEXES_HH_ */