Blame view

src/ExternLib/sum_into_table_indexes/SumIntoTableIndexes.hh 6.38 KB
09ec73e7   Benjamin Renard   Add process sum_i...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * 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<typename DataType>
class SumIntoTableIndexes1D : public Operation {

public:
	/**
	 * @brief Constructor.
	 * @details Create the ParamData type of the input ParamData.
	 */
	SumIntoTableIndexes1D(Process& pProcess, ParamDataSpec<std::vector<DataType> >& paramInput, int minIndex, int maxIndex)
	: Operation(pProcess),
	  _paramInput(paramInput),
	  _paramOutput(new ParamDataSpec<DataType>()), _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<DataType> inputElt = _paramInput.get(_index);

		  DataType output = 0;

		  for (int i = _minIndex; i <= _maxIndex; ++i) {
a4698d47   Benjamin Renard   Fix StatisticProc...
57
			  if ((i >= (int)inputElt.size()) || isNAN(inputElt[i]))
09ec73e7   Benjamin Renard   Add process sum_i...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
				  continue;
			  output += inputElt[i];
		  }

		  _paramOutput->pushTime(crtTime);
		  _paramOutput->getDataList().push_back(output);
	  }
  }

private:
	/**<
	 * @brief It is the channel of data derived
	 */
  ParamDataSpec<std::vector<DataType> > &_paramInput;

	/**<
	 * @brief It is the channel of the data derived
	 */
  ParamDataSpec<DataType> *_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<typename DataType>
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<Tab2DData<DataType> >& paramInput, int minIndex, int maxIndex, int tableRelatedDim)
	: Operation(pProcess),
	  _paramInput(paramInput),
	  _paramOutput(new ParamDataSpec<std::vector<DataType>>()),
	  _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<DataType> inputElt = _paramInput.get(_index);

			std::vector<DataType> 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<Tab2DData<DataType> > &_paramInput;

	ParamDataSpec<std::vector<DataType>> *_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<typename DataType>
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<Tab2DData<DataType> >& paramInput, int minIndex1, int maxIndex1, int table1RelatedDim, int minIndex2, int maxIndex2)
	: Operation(pProcess),
	  _paramInput(paramInput),
	  _paramOutput(new ParamDataSpec<DataType>()),
	  _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<DataType> 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<Tab2DData<DataType> > &_paramInput;

	ParamDataSpec<DataType> *_paramOutput;

	int _table1RelatedDim;

	int _minIndex1;

	int _maxIndex1;

	int _minIndex2;

	int _maxIndex2;
};


} /* namespace SumIntoTableIndexes */
} /* namespace Parameters */
} /* namespace AMDA */
#endif /* SUMINTOTABLEINDEXES_HH_ */