Blame view

src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh 8.56 KB
f9eb7c3a   Erdogan Furkan   For now
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
/*
 * Pusher.hh
 *
 *  Created on: Jan 30, 2019
 *      Author: AKKA
 */

#ifndef PUSHER_H_
#define PUSHER_H_

#include <vector>
#include "ParamData.hh"


#include "SpeasyProxyParamData.hh"

namespace AMDA {
namespace SpeasyProxyInterface {

// int getNbDataByPacket(ConstantParamType paramType, int dim1, int dim2);

/**
 * @class PusherBase
 * @details This class is the operation responsible to transform raw data from local file into a ParamData
 * of the corresponding type ( scalar or vector of short or int or float or double or ... type).
 */
struct PusherBase {
public:
	/*
	 * @brief Constructor
	 */
3e723802   Benjamin Renard   Improve SpeasyPro...
32
33
34
35
	PusherBase (int dim1, int dim2, SpeasyProxyContainerType container, 
                SpeasyProxyParamType type) : 
                    _paramData(NULL), _dim1(dim1), _dim2(dim2), 
                    _fillValue(NAN), _container(container), _type(type)
f9eb7c3a   Erdogan Furkan   For now
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	{
	}

	/*
	 * @brief Destructor
	 */
	virtual ~PusherBase()
	{
	}

	/*
	 * @brief Get the ParamData
	 */
	AMDA::Parameters::ParamData* getParamData(void)
	{
		return _paramData;
	}

3e723802   Benjamin Renard   Improve SpeasyPro...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    SpeasyProxyContainerType getContainer(void)
    {
        return _container;
    }

    int getDim1() {
        return _dim1;
    }

    int getDim2() {
        return _dim2;
    }

    SpeasyProxyParamType getType() {
        return _type;
    }

a0567216   Benjamin Renard   Fix some bugs
71
72
73
74
    void setFillValue(double fillValue) {
        _fillValue = fillValue;
    }

f9eb7c3a   Erdogan Furkan   For now
75
76
77
	/*
	 * @brief Virtual method to put a packet in the ParamData
	 */
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
78
	virtual int put(SpeasyProxyParamDataPacket* packet) = 0;
f9eb7c3a   Erdogan Furkan   For now
79

a0567216   Benjamin Renard   Fix some bugs
80
81
82
83
84
    /*
	 * @brief Virtual method to put a NAN in the ParamData
	 */
    virtual void putNaN() = 0;

f9eb7c3a   Erdogan Furkan   For now
85
86
87
88
89
90
91
protected:
	/*
	 * @brief Pointer to the paramData
	 */
	AMDA::Parameters::ParamData* _paramData;

	/*
f9eb7c3a   Erdogan Furkan   For now
92
93
94
95
96
97
98
99
100
101
102
103
104
	 * @brief For Vector and Tab2D dimension
	 */
	int _dim1;

	/*
	 * @brief For Tab2D dimension
	 */
	int _dim2;

	/*
	 * @brief Nb data returned by one packet
	 */
	// int _nbDataByPacket;
a0567216   Benjamin Renard   Fix some bugs
105
106
107
108
109

    /*
	 * @brief Fill value
	 */
    double _fillValue;
3e723802   Benjamin Renard   Improve SpeasyPro...
110
111
112
113

    SpeasyProxyContainerType _container;

    SpeasyProxyParamType _type;
f9eb7c3a   Erdogan Furkan   For now
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
};


template <SpeasyProxyParamType type>
struct MapType { typedef void Type; };

template <> struct MapType<SpeasyProxyParamType::TYPE_SHORT>  { typedef short Type; };
template <> struct MapType<SpeasyProxyParamType::TYPE_INT>  { typedef int Type; };
template <> struct MapType<SpeasyProxyParamType::TYPE_FLOAT>  { typedef float Type; };
template <> struct MapType<SpeasyProxyParamType::TYPE_DOUBLE> { typedef double Type; };


template<SpeasyProxyParamType type, SpeasyProxyContainerType container = CONTAINER_VECTOR>
class Pusher;

/**
 * @brief Pusher implementation for the Tab2D.
 */
template<SpeasyProxyParamType type>
class Pusher<type,CONTAINER_MATRIX> : public PusherBase
{
public:
	/*
	 * @brief Define some usefull types
	 */
	typedef typename MapType<type>::Type BaseElemenType;
	typedef AMDA::Parameters::Tab2DData<BaseElemenType> ElemenType;
	typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;

	SpecParamData* _specParamData;

	/*
	 * @brief Constructor
	 */
3e723802   Benjamin Renard   Improve SpeasyPro...
148
	Pusher(int dim1, int dim2) : PusherBase( dim1, dim2, CONTAINER_MATRIX, type)
f9eb7c3a   Erdogan Furkan   For now
149
150
151
152
153
154
155
156
	{
		_paramData = _specParamData = createParamData();
		// _nbDataByPacket = getNbDataByPacket(type, dim1, dim2);
	}

	/*
	 * @brief Put packet in a "vector" ParamData
	 */
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
157
	virtual int put(SpeasyProxyParamDataPacket* packet)
f9eb7c3a   Erdogan Furkan   For now
158
	{
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
159
160
161
162
		//ParamData is created, add data

		_specParamData->getDataList().resize(packet->getNbData());

a0567216   Benjamin Renard   Fix some bugs
163
		BaseElemenType fillEl = _fillValue;
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

		for (int index = 0; index < packet->getNbData(); ++index)
		{
			//get time
			double time = packet->getTime(index);
			//this element will be deleted by the Container designed by "_specParamData->getDataList()"
			ElemenType elem = ElemenType(packet->getDim1Size(),packet->getDim2Size());
			for (int dim1Index = 0;  dim1Index < packet->getDim1Size(); ++dim1Index)
			{
				for (int dim2Index = 0;  dim2Index < packet->getDim2Size(); ++dim2Index)
				{
					BaseElemenType baseElem;
					//get data element
					if (packet->getDataValue(&baseElem,index,dim1Index,dim2Index))
					{
a0567216   Benjamin Renard   Fix some bugs
179
180
181
						if (!isnan(_fillValue))
						    if (baseElem == fillEl)
					        	baseElem << NotANumber();
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
					}
					else
						baseElem << NotANumber();
					elem[dim1Index][dim2Index] = baseElem;
				}
			}

			//push time and element in the ParamData
			_specParamData->getDataList().push_back(elem);
			_specParamData->getTimeList().push_back(time);
		}

		//return nb of processed records
		return packet->getNbData();
f9eb7c3a   Erdogan Furkan   For now
196
197
198
199

		return 0;
	}

a0567216   Benjamin Renard   Fix some bugs
200
201
202
203
204
205
206
207
208
209
210
    virtual void putNaN() {
		_specParamData->getDataList().resize(1);
		ElemenType nanElem = ElemenType(_dim1,_dim2);
		for(int i = 0; i < _dim1; ++i) {
			for(int j = 0; j < _dim2; ++j) {
				nanElem[i][j] << NotANumber();
			}
		}
		_specParamData->getDataList().push_back(nanElem);
	}

f9eb7c3a   Erdogan Furkan   For now
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
	/*
	 * @brief ParamData creation
	 */
	SpecParamData* createParamData()
	{
		return new AMDA::Parameters::ParamDataSpec<AMDA::Parameters::Tab2DData<typename MapType<type>::Type> >(_dim1,_dim2);
	}
};

/**
 * @brief Pusher implementation for the vector.
 */
template<SpeasyProxyParamType type>
class Pusher<type,CONTAINER_VECTOR> : public PusherBase
{
public:
	/*
	 * @brief Define some usefull types
	 */
	typedef typename MapType<type>::Type BaseElemenType;
	typedef std::vector<BaseElemenType> ElemenType;
	typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;

	SpecParamData* _specParamData;

	/*
	 * @brief Constructor
	 */
3e723802   Benjamin Renard   Improve SpeasyPro...
239
	Pusher(int dim) : PusherBase(dim, 1, CONTAINER_VECTOR, type)
f9eb7c3a   Erdogan Furkan   For now
240
241
242
243
244
245
246
247
	{
		_paramData = _specParamData = createParamData();
		// _nbDataByPacket = getNbDataByPacket(type, dim, 1);
	}

	/*
	 * @brief Put packet in a "vector" ParamData
	 */
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
248
	virtual int put(SpeasyProxyParamDataPacket* packet)
f9eb7c3a   Erdogan Furkan   For now
249
	{
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
250
251
252
		//ParamData is created, add data
		_specParamData->getDataList().resize(packet->getNbData());

a0567216   Benjamin Renard   Fix some bugs
253
		BaseElemenType fillEl = _fillValue;
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
254
255
256
257
258
259
260
261
262
263
264
265
266

		for (int index = 0; index < packet->getNbData(); ++index)
		{
			//get time
			double time = packet->getTime(index);

			ElemenType elem;
			for (int dimIndex = 0;  dimIndex < packet->getDim1Size(); ++dimIndex)
			{
				BaseElemenType baseElem;
				//get data element
				if (packet->getDataValue(&baseElem,index,dimIndex))
				{
a0567216   Benjamin Renard   Fix some bugs
267
268
269
				    if (!isnan(_fillValue))
					    if (baseElem == fillEl)
				        	baseElem << NotANumber();
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
				}
				else
					baseElem << NotANumber();
				//push data base element
				elem.push_back(baseElem);
			}

			//push time and element in the ParamData
			_specParamData->getDataList().push_back(elem);
			_specParamData->getTimeList().push_back(time);
		}

		//return nb of processed records
		return packet->getNbData();
f9eb7c3a   Erdogan Furkan   For now
284
285
	}

a0567216   Benjamin Renard   Fix some bugs
286
287
288
289
290
291
292
293
    virtual void putNaN() {
		_specParamData->getDataList().resize(1);
		ElemenType nanElem = ElemenType();
		nanElem.resize(_dim1);
		nanElem << NotANumber();
		_specParamData->getDataList().push_back(nanElem);
	}

f9eb7c3a   Erdogan Furkan   For now
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
	/*
	 * @brief ParamData creation
	 */
	SpecParamData* createParamData()
	{
		return new AMDA::Parameters::ParamDataSpec< std::vector<typename MapType<type>::Type> >(_dim1);
	}
};

/**
 * @brief Pusher implementation for the scalar.
 */
template<SpeasyProxyParamType type>
class Pusher<type,CONTAINER_SCALAR> : public PusherBase {
public:
	/*
	 * @brief Define some usefull types
	 */
	typedef typename MapType<type>::Type BaseElemenType;
	typedef BaseElemenType ElemenType;
	typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;

	SpecParamData* _specParamData;

	/*
	 * @brief Constructor
	 */
3e723802   Benjamin Renard   Improve SpeasyPro...
321
	Pusher() : PusherBase(1, 1, CONTAINER_SCALAR, type)
f9eb7c3a   Erdogan Furkan   For now
322
323
324
325
326
327
328
329
	{
		_paramData = _specParamData = createParamData();
		// _nbDataByPacket = getNbDataByPacket(type, 1, 1);
	}

	/*
	 * @brief Put packet in a "scalar" ParamData
	 */
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
330
	virtual int put(SpeasyProxyParamDataPacket* packet)
f9eb7c3a   Erdogan Furkan   For now
331
	{
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
332
333
334
		//ParamData is created, add data
		_specParamData->getDataList().resize(packet->getNbData());

a0567216   Benjamin Renard   Fix some bugs
335
		BaseElemenType fillEl = _fillValue;
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
336
337
338
339
340
341
342
343
344
345

		for (int index = 0; index < packet->getNbData(); ++index)
		{
			//get time
			double time = packet->getTime(index);

			BaseElemenType baseElem;
			//get element
			if (packet->getDataValue(&baseElem,index))
			{
a0567216   Benjamin Renard   Fix some bugs
346
347
348
349
350
				if (!isnan(_fillValue))
				{
				    if (baseElem == fillEl)
			        	baseElem << NotANumber();
				}
ae3e8cdf   Erdogan Furkan   ParamGet of Speas...
351
352
353
354
355
356
357
358
359
360
			}
			else
				baseElem << NotANumber();

			//push time and element in the ParamData
			_specParamData->getDataList().push_back(baseElem);
			_specParamData->getTimeList().push_back(time);
		}

		return packet->getNbData();
f9eb7c3a   Erdogan Furkan   For now
361
362
	}

a0567216   Benjamin Renard   Fix some bugs
363
364
365
366
367
368
369
    virtual void putNaN() {
                BaseElemenType valNaN;
                valNaN << NotANumber();
		_specParamData->getDataList().resize(1);
		_specParamData->getDataList().push_back(valNaN);
	}

f9eb7c3a   Erdogan Furkan   For now
370
371
372
373
374
375
376
377
	SpecParamData* createParamData() {
		return new SpecParamData();
	}
};

} /* namespace SpeasyProxyInterface */
} /* namespace AMDA */
#endif /* PUSHER_H_ */