Commit ae3e8cdf8a5becc9d044fec62cf95f557875cbdd
1 parent
f9eb7c3a
Exists in
SpeasyGet
ParamGet of SpeasyProxy working - TBC
Showing
8 changed files
with
2075 additions
and
114 deletions
Show diff stats
config/xsd/parameter/getspeasyproxy.xsd
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | <xs:attribute name="minSampling" type="xs:string" use="required" /> |
10 | 10 | <xs:attribute name="dim1" type="xs:integer" /> |
11 | 11 | <xs:attribute name="dim2" type="xs:integer" /> |
12 | + <xs:attribute name="type" type="xs:string" /> | |
12 | 13 | </xs:complexType> |
13 | 14 | |
14 | 15 | <xs:complexType name="speasy-proxy-type"> | ... | ... |
... | ... | @@ -0,0 +1,919 @@ |
1 | +/* | |
2 | + * FileReaderCDF.cc | |
3 | + * | |
4 | + * Created on: Nov 24, 2014 | |
5 | + * Author: AKKA | |
6 | + */ | |
7 | + | |
8 | +#include "FileReaderCDF.hh" | |
9 | + | |
10 | +#include "ParameterManager.hh" | |
11 | +#include "SpeasyProxyInterfaceConfig.hh" | |
12 | +#include "TimeUtil.hh" | |
13 | + | |
14 | +#include <boost/shared_ptr.hpp> | |
15 | + | |
16 | +namespace AMDA { | |
17 | +namespace SpeasyProxyInterface { | |
18 | + | |
19 | +FileReaderCDF::FileReaderCDF() : _cdfid(NULL), _workingBuffers(new CDFWorkingBuffers) | |
20 | +{ | |
21 | +} | |
22 | + | |
23 | +FileReaderCDF::~FileReaderCDF() | |
24 | +{ | |
25 | +} | |
26 | + | |
27 | +bool FileReaderCDF::open(std::string filePath) | |
28 | +{ | |
29 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
30 | + | |
31 | + if (isOpened()) | |
32 | + { | |
33 | + //LOG4CXX_ERROR(gLogger, "FileReaderCDF::open - A file is already opened"); | |
34 | + return true;//false; | |
35 | + } | |
36 | + | |
37 | + CDFstatus status = CDFopenCDF(filePath.c_str(), &_cdfid); | |
38 | + | |
39 | + return (status == CDF_OK); | |
40 | +} | |
41 | + | |
42 | +bool FileReaderCDF::close(void) | |
43 | +{ | |
44 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
45 | + | |
46 | + if (isOpened()) | |
47 | + { | |
48 | + CDFstatus status = CDFcloseCDF(_cdfid); | |
49 | + | |
50 | + if (status == CDF_OK) | |
51 | + _cdfid = NULL; | |
52 | + } | |
53 | + | |
54 | + return (_cdfid == NULL); | |
55 | +} | |
56 | + | |
57 | +bool FileReaderCDF::isOpened(void) | |
58 | +{ | |
59 | + return (_cdfid != NULL); | |
60 | +} | |
61 | + | |
62 | +std::string FileReaderCDF::getTimeParamId(void) | |
63 | +{ | |
64 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
65 | + | |
66 | + std::string result = ""; | |
67 | + | |
68 | + //search in rVariables | |
69 | + long numrVars; | |
70 | + CDFstatus status = CDFgetNumrVars (_cdfid, &numrVars); | |
71 | + | |
72 | + if (status == CDF_OK) | |
73 | + { | |
74 | + for (long i = 0; i < numrVars; ++i) | |
75 | + { | |
76 | + CDFVarInfo varInfo; | |
77 | + status = CDFvarInquire(_cdfid, i, varInfo._name, &varInfo._dataType, | |
78 | + &varInfo._numElts, &varInfo._recVary, varInfo._dimVarys); | |
79 | + if (status == CDF_OK) | |
80 | + { | |
81 | + if ((varInfo._dataType == CDF_EPOCH) || (varInfo._dataType == CDF_EPOCH16) || (varInfo._dataType == CDF_TIME_TT2000)) | |
82 | + { | |
83 | + result = varInfo._name; | |
84 | + return result; | |
85 | + } | |
86 | + } | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + //search in zVariables | |
91 | + long numzVars; | |
92 | + status = CDFgetNumzVars (_cdfid, &numzVars); | |
93 | + | |
94 | + if (status == CDF_OK) | |
95 | + { | |
96 | + for (long i = 0; i < numzVars; ++i) | |
97 | + { | |
98 | + CDFVarInfo varInfo; | |
99 | + status = CDFinquirezVar(_cdfid, i, varInfo._name, &varInfo._dataType, | |
100 | + &varInfo._numElts, &varInfo._numDims, varInfo._dimSizes, | |
101 | + &varInfo._recVary, varInfo._dimVarys); | |
102 | + if (status == CDF_OK) | |
103 | + { | |
104 | + if ((varInfo._dataType == CDF_EPOCH) || (varInfo._dataType == CDF_EPOCH16) || (varInfo._dataType == CDF_TIME_TT2000)) | |
105 | + { | |
106 | + result = varInfo._name; | |
107 | + return result; | |
108 | + } | |
109 | + } | |
110 | + } | |
111 | + } | |
112 | + | |
113 | + return result; | |
114 | +} | |
115 | + | |
116 | +bool FileReaderCDF::getParamInfo(std::string& paramId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size) | |
117 | +{ | |
118 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
119 | + | |
120 | + paramType = SpeasyProxyParamType::TYPE_UNKNOWN; | |
121 | + dim1Size = 0; | |
122 | + dim2Size = 0; | |
123 | + | |
124 | + //get CDF var info | |
125 | + CDFVarInfo varInfo; | |
126 | + if (!getCDFVarInfo(paramId, varInfo)) | |
127 | + return false; | |
128 | + | |
129 | + //get ParamType in relation to the CDF var type | |
130 | + switch (varInfo._dataType) | |
131 | + { | |
132 | + case CDF_REAL4 : | |
133 | + case CDF_FLOAT : | |
134 | + paramType = SpeasyProxyParamType::TYPE_FLOAT; | |
135 | + break; | |
136 | + case CDF_REAL8 : | |
137 | + case CDF_DOUBLE : | |
138 | + case CDF_EPOCH : | |
139 | + paramType = SpeasyProxyParamType::TYPE_DOUBLE; | |
140 | + break; | |
141 | + case CDF_EPOCH16 : | |
142 | + paramType = SpeasyProxyParamType::TYPE_EPOCH16; | |
143 | + break; | |
144 | + case CDF_BYTE : | |
145 | + case CDF_INT1 : | |
146 | + case CDF_UINT1 : | |
147 | + case CDF_INT2 : | |
148 | + case CDF_UINT2 : | |
149 | + paramType = SpeasyProxyParamType::TYPE_SHORT; | |
150 | + break; | |
151 | + case CDF_INT4 : | |
152 | + case CDF_UINT4 : | |
153 | + paramType = SpeasyProxyParamType::TYPE_INT; | |
154 | + break; | |
155 | + case CDF_TIME_TT2000 : | |
156 | + case CDF_INT8 : | |
157 | + paramType = SpeasyProxyParamType ::TYPE_TT2000; | |
158 | + break; | |
159 | + case CDF_CHAR : | |
160 | + case CDF_UCHAR : | |
161 | + default : | |
162 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamInfo - Unknown data type"); | |
163 | + return false; | |
164 | + } | |
165 | + | |
166 | + //set param size | |
167 | + if (varInfo._numDims > 2) | |
168 | + { | |
169 | + dim1Size = 0; | |
170 | + dim2Size = 0; | |
171 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamInfo - Unknown dimension"); | |
172 | + return false; | |
173 | + } | |
174 | + else if (varInfo._numDims == 2) | |
175 | + { | |
176 | + //Dimensions for a Tab2D | |
177 | + dim1Size = varInfo._dimSizes[0]; | |
178 | + dim2Size = varInfo._dimSizes[1]; | |
179 | + } | |
180 | + else if (varInfo._numDims == 1) | |
181 | + { | |
182 | + //Dimensions for a Vector | |
183 | + dim1Size = varInfo._dimSizes[0]; | |
184 | + dim2Size = 1; | |
185 | + } | |
186 | + else | |
187 | + { | |
188 | + //Dimensions for a Scalar | |
189 | + dim1Size = 1; | |
190 | + dim2Size = 1; | |
191 | + } | |
192 | + | |
193 | + return true; | |
194 | +} | |
195 | + | |
196 | +bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo) | |
197 | +{ | |
198 | + if (paramName.empty()) | |
199 | + { | |
200 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Empty param name"); | |
201 | + return false; | |
202 | + } | |
203 | + | |
204 | + if (paramName.size() >= CDF_VAR_NAME_LEN256) | |
205 | + { | |
206 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Param name too large"); | |
207 | + return false; | |
208 | + } | |
209 | + | |
210 | + //reset info structure | |
211 | + memset(&varInfo,0,sizeof(CDFVarInfo)); | |
212 | + | |
213 | + //confirm variable existence | |
214 | + memcpy(varInfo._name,paramName.c_str(),paramName.size()*sizeof(char)); | |
215 | + varInfo._name[paramName.size()] = '\0'; | |
216 | + | |
217 | + varInfo._num = CDFgetVarNum(_cdfid,varInfo._name); | |
218 | + | |
219 | + if (varInfo._num < 0) | |
220 | + { | |
221 | + LOG4CXX_INFO(gLogger, "FileReaderCDF::getCDFVarInfo - Cannot find variable"); | |
222 | + return false; | |
223 | + } | |
224 | + | |
225 | + //Is it a zVariable? | |
226 | + CDFstatus status = CDFconfirmzVarExistence(_cdfid,varInfo._name); | |
227 | + | |
228 | + bool isZVar = (status == CDF_OK); | |
229 | + | |
230 | + if (isZVar) | |
231 | + { | |
232 | + //get info about a zVariable | |
233 | + varInfo._type = CDFVT_Z; | |
234 | + | |
235 | + status = CDFinquirezVar(_cdfid, varInfo._num, varInfo._name, &varInfo._dataType, | |
236 | + &varInfo._numElts, &varInfo._numDims, varInfo._dimSizes, &varInfo._recVary, | |
237 | + varInfo._dimVarys); | |
238 | + | |
239 | + if (status != CDF_OK) | |
240 | + { | |
241 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFinquirezVar"); | |
242 | + return false; | |
243 | + } | |
244 | + | |
245 | + status = CDFgetzVarMaxWrittenRecNum(_cdfid, varInfo._num, &varInfo._maxRecNum); | |
246 | + | |
247 | + if (status != CDF_OK) | |
248 | + { | |
249 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetzVarMaxWrittenRecNum"); | |
250 | + return false; | |
251 | + } | |
252 | + | |
253 | + status = CDFgetDataTypeSize(varInfo._dataType,&varInfo._numBytes); | |
254 | + | |
255 | + if (status != CDF_OK) | |
256 | + { | |
257 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); | |
258 | + return false; | |
259 | + } | |
260 | + } | |
261 | + else | |
262 | + { | |
263 | + //get info about a rVariable | |
264 | + varInfo._type = CDFVT_R; | |
265 | + | |
266 | + status = CDFvarInquire(_cdfid, varInfo._num, varInfo._name, | |
267 | + &varInfo._dataType, &varInfo._numElts, &varInfo._recVary, varInfo._dimVarys); | |
268 | + | |
269 | + if (status != CDF_OK) | |
270 | + { | |
271 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFvarInquire"); | |
272 | + return false; | |
273 | + } | |
274 | + | |
275 | + long encoding; | |
276 | + long majority; | |
277 | + long numVars; | |
278 | + long numAttrs; | |
279 | + status = CDFinquire (_cdfid, &varInfo._numDims, varInfo._dimSizes, &encoding, &majority, | |
280 | + &varInfo._maxRecNum, &numVars, &numAttrs); | |
281 | + | |
282 | + if (status != CDF_OK) | |
283 | + { | |
284 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFinquire"); | |
285 | + return false; | |
286 | + } | |
287 | + | |
288 | + status = CDFgetDataTypeSize(varInfo._dataType,&varInfo._numBytes); | |
289 | + | |
290 | + if (status != CDF_OK) | |
291 | + { | |
292 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetDataTypeSize"); | |
293 | + return false; | |
294 | + } | |
295 | + } | |
296 | + | |
297 | + return true; | |
298 | +} | |
299 | + | |
300 | +int FileReaderCDF::getRecordIndex(std::string& timeId, double time) | |
301 | +{ | |
302 | + LOG4CXX_DEBUG(gLogger, "FileReaderCDF::getRecordIndex"); | |
303 | + | |
304 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
305 | + | |
306 | + //get corresponding epoch time | |
307 | + double timeEPOCH = timeStampToEPOCHTime(time); | |
308 | + | |
309 | + //get all time data | |
310 | + long nbRec; | |
311 | + long dimSize; | |
312 | + long dataType; | |
313 | + long numBytes; | |
314 | + | |
315 | + if (!getCDFData(timeId, 0, CDFWorkingBuffers::BufferType::BUFFER_TIME, | |
316 | + dataType, numBytes, nbRec, dimSize)) | |
317 | + { | |
318 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Cannot get time var data"); | |
319 | + return -1; | |
320 | + } | |
321 | + | |
322 | + if ((dataType != CDF_EPOCH) && (dataType != CDF_EPOCH16) && (dataType != CDF_TIME_TT2000)) | |
323 | + { | |
324 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Not a time var " << timeId); | |
325 | + return -1; | |
326 | + } | |
327 | + | |
328 | + //search nearest record | |
329 | + for (long i = 0; i < nbRec; ++i) | |
330 | + { | |
331 | + double crtTime; | |
332 | + switch (dataType) { | |
333 | + case CDF_EPOCH : | |
334 | + if (!extractDouble(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, dimSize,dataType,numBytes,crtTime)) | |
335 | + { | |
336 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Error to extract time data"); | |
337 | + return -1; | |
338 | + } | |
339 | + break; | |
340 | + case CDF_EPOCH16 : | |
341 | + double crtEpoch16Time[2]; | |
342 | + if (!extractEpoch16(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, dimSize,dataType,numBytes,crtEpoch16Time)) | |
343 | + { | |
344 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Error to extract time data"); | |
345 | + return -1; | |
346 | + } | |
347 | + crtTime = epoch16ToEpochTime(crtEpoch16Time); | |
348 | + break; | |
349 | + case CDF_TIME_TT2000 : | |
350 | + long long crtTT2000Time; | |
351 | + if (!extractTT2000(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, dimSize,dataType,numBytes,crtTT2000Time)) | |
352 | + { | |
353 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Error to extract time data"); | |
354 | + return -1; | |
355 | + } | |
356 | + crtTime = tt2000ToEpochTime(crtTT2000Time); | |
357 | + break; | |
358 | + default: | |
359 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getRecordIndex - Error to extract time data"); | |
360 | + return -1; | |
361 | + } | |
362 | + if (timeEPOCH <= crtTime) | |
363 | + return i; | |
364 | + } | |
365 | + | |
366 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Cannot get record index"); | |
367 | + return -1; | |
368 | +} | |
369 | + | |
370 | +FileReaderStatus FileReaderCDF::getParamPacketData(std::string& timeId, std::string& paramId, | |
371 | + SpeasyProxyParamDataPacket *packet) | |
372 | +{ | |
373 | + LOG4CXX_DEBUG(gLogger, "FileReaderCDF::getParamPacketData"); | |
374 | + | |
375 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
376 | + | |
377 | + | |
378 | + //get the size of one value of a data in the packet | |
379 | + int packetValueSize; | |
380 | + switch (packet->getType()) | |
381 | + { | |
382 | + case SpeasyProxyParamType::TYPE_FLOAT: | |
383 | + packetValueSize = sizeof(float); | |
384 | + break; | |
385 | + case SpeasyProxyParamType::TYPE_DOUBLE: | |
386 | + packetValueSize = sizeof(double); | |
387 | + break; | |
388 | + case SpeasyProxyParamType::TYPE_SHORT: | |
389 | + packetValueSize = sizeof(short); | |
390 | + break; | |
391 | + case SpeasyProxyParamType::TYPE_INT: | |
392 | + packetValueSize = sizeof(int); | |
393 | + break; | |
394 | + default: | |
395 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - ParamType not implemented for CDF format"); | |
396 | + return FRS_ERROR; | |
397 | + } | |
398 | + | |
399 | + //get time data | |
400 | + long nbTimeRec; | |
401 | + long dimTimeSize; | |
402 | + long dataTimeType; | |
403 | + long numTimeBytes; | |
404 | + if (!timeId.empty()) { | |
405 | + if (!getCDFData(timeId, 0, CDFWorkingBuffers::BufferType::BUFFER_TIME, dataTimeType, numTimeBytes, nbTimeRec, dimTimeSize)) | |
406 | + { | |
407 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Cannot get time var data for " << timeId); | |
408 | + return FRS_ERROR; | |
409 | + } | |
410 | + | |
411 | + if ((dataTimeType != CDF_EPOCH) && (dataTimeType != CDF_EPOCH16) && (dataTimeType != CDF_TIME_TT2000)) | |
412 | + { | |
413 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Bad time format " << timeId); | |
414 | + return FRS_ERROR; | |
415 | + } | |
416 | + } | |
417 | + else { | |
418 | + nbTimeRec = 1; | |
419 | + } | |
420 | + | |
421 | + //get data | |
422 | + long nbRec; | |
423 | + long dimSize; | |
424 | + long dataType; | |
425 | + long numBytes; | |
426 | + if (!getCDFData(paramId, 0, CDFWorkingBuffers::BufferType::BUFFER_DATA, dataType, numBytes, nbRec, dimSize)) | |
427 | + { | |
428 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Cannot get var data for " << paramId); | |
429 | + return FRS_ERROR; | |
430 | + } | |
431 | + | |
432 | + //check dimension integrity | |
433 | + if (dimSize != packet->getDimsSize()) | |
434 | + { | |
435 | + std::cout << dimSize << packet->getDimsSize() << std::endl; | |
436 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Incompatibility between dim size of the packet and the CDF var"); | |
437 | + return FRS_ERROR; | |
438 | + } | |
439 | + | |
440 | + //alloc buffer for one record of the packet | |
441 | + _workingBuffers->reallocBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC, | |
442 | + packetValueSize*packet->getDimsSize()); | |
443 | + | |
444 | + for (int i = 0; i < nbTimeRec; ++i) | |
445 | + { | |
446 | + double crtTime = 0; | |
447 | + if (!timeId.empty()) { | |
448 | + //time | |
449 | + double crtTimeEPOCH; | |
450 | + switch (dataTimeType) { | |
451 | + case CDF_EPOCH : | |
452 | + if (!extractDouble(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, | |
453 | + dimTimeSize,dataTimeType,numTimeBytes,crtTimeEPOCH)) | |
454 | + { | |
455 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract time data"); | |
456 | + return FRS_ERROR; | |
457 | + } | |
458 | + break; | |
459 | + case CDF_EPOCH16 : | |
460 | + double crtTimeEPOCH16[2]; | |
461 | + if (!extractEpoch16(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, | |
462 | + dimTimeSize,dataTimeType,numTimeBytes,crtTimeEPOCH16)) | |
463 | + { | |
464 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract time data"); | |
465 | + return FRS_ERROR; | |
466 | + } | |
467 | + crtTimeEPOCH = epoch16ToEpochTime(crtTimeEPOCH16); | |
468 | + break; | |
469 | + case CDF_TIME_TT2000 : | |
470 | + long long crtTimeTT2000; | |
471 | + if (!extractTT2000(CDFWorkingBuffers::BufferType::BUFFER_TIME, i, 0, | |
472 | + dimTimeSize,dataTimeType,numTimeBytes,crtTimeTT2000)) | |
473 | + { | |
474 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract time data"); | |
475 | + return FRS_ERROR; | |
476 | + } | |
477 | + crtTimeEPOCH = tt2000ToEpochTime(crtTimeTT2000); | |
478 | + break; | |
479 | + default: | |
480 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract time data"); | |
481 | + return FRS_ERROR; | |
482 | + } | |
483 | + | |
484 | + crtTime = epochTimeToTimeStamp(crtTimeEPOCH); | |
485 | + } | |
486 | + | |
487 | + bool packetFull; | |
488 | + | |
489 | + if (i >= nbRec) | |
490 | + { | |
491 | + //add record data | |
492 | + if (!packet->addData(crtTime, | |
493 | + _workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC), | |
494 | + packetFull)) | |
495 | + { | |
496 | + if (packetFull) | |
497 | + return FRS_MORE; | |
498 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to add data in packet"); | |
499 | + return FRS_ERROR; | |
500 | + } | |
501 | + continue; | |
502 | + } | |
503 | + | |
504 | + for (int j = 0; j < dimSize; ++j) | |
505 | + { | |
506 | + switch (packet->getType()) | |
507 | + { | |
508 | + case SpeasyProxyParamType::TYPE_FLOAT: | |
509 | + { | |
510 | + //extract and copy value in the buffer | |
511 | + float f; | |
512 | + if (!extractFloat(CDFWorkingBuffers::BufferType::BUFFER_DATA, i, j, | |
513 | + dimSize, dataType, numBytes, f)) | |
514 | + { | |
515 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract a data"); | |
516 | + return FRS_ERROR; | |
517 | + } | |
518 | + void* p = (void*)((intptr_t)_workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC) + j*packetValueSize); | |
519 | + memcpy(p,&f,sizeof(float)); | |
520 | + } | |
521 | + break; | |
522 | + case SpeasyProxyParamType::TYPE_DOUBLE: | |
523 | + { | |
524 | + //extract and copy value in the buffer | |
525 | + double d; | |
526 | + if (!extractDouble(CDFWorkingBuffers::BufferType::BUFFER_DATA, i, j, | |
527 | + dimSize, dataType, numBytes, d)) | |
528 | + { | |
529 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract a data"); | |
530 | + return FRS_ERROR; | |
531 | + } | |
532 | + void* p = (void*)((intptr_t)_workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC) + j*packetValueSize); | |
533 | + memcpy(p,&d,sizeof(double)); | |
534 | + } | |
535 | + break; | |
536 | + case SpeasyProxyParamType::TYPE_SHORT: | |
537 | + { | |
538 | + //extract and copy value in the buffer | |
539 | + short s; | |
540 | + if (!extractShort(CDFWorkingBuffers::BufferType::BUFFER_DATA, i, j, | |
541 | + dimSize, dataType, numBytes, s)) | |
542 | + { | |
543 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract a data"); | |
544 | + return FRS_ERROR; | |
545 | + } | |
546 | + void* p = (void*)((intptr_t)_workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC) + j*packetValueSize); | |
547 | + memcpy(p,&s,sizeof(short)); | |
548 | + } | |
549 | + break; | |
550 | + case SpeasyProxyParamType::TYPE_INT: | |
551 | + { | |
552 | + //extract and copy value in the buffer | |
553 | + int ii; | |
554 | + if (!extractInt(CDFWorkingBuffers::BufferType::BUFFER_DATA, i, j, | |
555 | + dimSize, dataType, numBytes, ii)) | |
556 | + { | |
557 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to extract a data"); | |
558 | + return FRS_ERROR; | |
559 | + } | |
560 | + void* p = (void*)((intptr_t)_workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC) + j*packetValueSize); | |
561 | + memcpy(p,&ii,sizeof(int)); | |
562 | + } | |
563 | + break; | |
564 | + default: | |
565 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - ParamType not implemented for CDF format"); | |
566 | + return FRS_ERROR; | |
567 | + } | |
568 | + } | |
569 | + | |
570 | + //add data record in the packet | |
571 | + if (!packet->addData(crtTime, | |
572 | + _workingBuffers->getBuffer(CDFWorkingBuffers::BufferType::BUFFER_PACKETREC), | |
573 | + packetFull)) | |
574 | + { | |
575 | + if (packetFull) | |
576 | + return FRS_MORE; | |
577 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Error to add data in packet"); | |
578 | + return FRS_ERROR; | |
579 | + } | |
580 | + } | |
581 | + | |
582 | + return FRS_EOF; | |
583 | +} | |
584 | + | |
585 | +double FileReaderCDF::timeStampToEPOCHTime(double timeStamp) | |
586 | +{ | |
587 | + std::stringstream isoTime; | |
588 | + TimeUtil::formatTimeDateInIso(timeStamp, isoTime); | |
589 | + | |
590 | + std::string timeString = isoTime.str(); | |
591 | + | |
592 | + char timeChar[EPOCH4_STRING_LEN+1]; | |
593 | + memset(timeChar,0,(EPOCH4_STRING_LEN+1)*sizeof(char)); | |
594 | + | |
595 | + if ((timeString.size() > 0) && (timeString.size() <= EPOCH4_STRING_LEN)) | |
596 | + memcpy(timeChar,timeString.c_str(),timeString.size()*sizeof(char)); | |
597 | + | |
598 | + return parseEPOCH4(timeChar); | |
599 | +} | |
600 | + | |
601 | +double FileReaderCDF::epochTimeToTimeStamp(double epochTime) | |
602 | +{ | |
603 | + char isoTime[EPOCH4_STRING_LEN+1]; | |
604 | + encodeEPOCH4(epochTime,isoTime); | |
605 | + return TimeUtil::readTimeInIso(isoTime); | |
606 | +} | |
607 | + | |
608 | +double FileReaderCDF::epoch16ToEpochTime(double epoch16Time[]) | |
609 | +{ | |
610 | + long year, month, day, hour, minute, second, msec, microsec, nanosec, picosec; | |
611 | + EPOCH16breakdown(epoch16Time, &year, &month, &day, &hour, &minute, &second, &msec, µsec, &nanosec, &picosec); | |
612 | + return computeEPOCH(year, month, day, hour, minute, second, msec); | |
613 | +} | |
614 | + | |
615 | +double FileReaderCDF::tt2000ToEpochTime(long long tt2000Time) | |
616 | +{ | |
617 | + return CDF_TT2000_to_UTC_EPOCH(tt2000Time); | |
618 | +} | |
619 | + | |
620 | +bool FileReaderCDF::getCDFData(std::string& varId, long startRec, | |
621 | + CDFWorkingBuffers::BufferType bufferType, | |
622 | + long& dataType, long& numBytes, long& nbRec, long& dimSize) | |
623 | +{ | |
624 | + nbRec = 0; | |
625 | + dimSize = 0; | |
626 | + CDFVarInfo varInfo; | |
627 | + if (!getCDFVarInfo(varId, varInfo)) | |
628 | + { | |
629 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFData - Cannot get param info " << varId); | |
630 | + return false; | |
631 | + } | |
632 | + | |
633 | + dataType = varInfo._dataType; | |
634 | + numBytes = varInfo._numBytes; | |
635 | + | |
636 | + if (varInfo._numElts > 1) | |
637 | + { | |
638 | + //only possible if CDF_CHAR | |
639 | + //not implemented (CDF_CHAR variable is not a valid variable for the ParamGet) | |
640 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFData - _numElts >= 1! " << varId); | |
641 | + return false; | |
642 | + } | |
643 | + | |
644 | + if ((varInfo._maxRecNum <= 0) && (varInfo._recVary != 0)) | |
645 | + //no record in file | |
646 | + return true; | |
647 | + | |
648 | + nbRec = varInfo._maxRecNum - startRec + 1; | |
649 | + | |
650 | + dimSize = 1; | |
651 | + if (varInfo._numDims > 0) | |
652 | + for (int i = 0; i < varInfo._numDims; ++i) | |
653 | + dimSize *= varInfo._dimSizes[i]; | |
654 | + | |
655 | + _workingBuffers->reallocBuffer(bufferType, nbRec*varInfo._numBytes*dimSize); | |
656 | + | |
657 | + CDFstatus status = CDFgetVarRangeRecordsByVarName(_cdfid, varInfo._name, startRec, | |
658 | + varInfo._maxRecNum, _workingBuffers->getBuffer(bufferType)); | |
659 | + | |
660 | + if (status != CDF_OK) | |
661 | + { | |
662 | + LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFData - Error to get data for " << varId); | |
663 | + return false; | |
664 | + } | |
665 | + | |
666 | + return true; | |
667 | +} | |
668 | + | |
669 | +bool FileReaderCDF::extractShort(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
670 | + long dataType, long numBytes, short& value) | |
671 | +{ | |
672 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
673 | + | |
674 | + switch(dataType) | |
675 | + { | |
676 | + case CDF_BYTE : | |
677 | + case CDF_INT1 : | |
678 | + { | |
679 | + char* c = (char*)p; | |
680 | + value = (short)(*c); | |
681 | + break; | |
682 | + } | |
683 | + case CDF_UINT1 : | |
684 | + { | |
685 | + unsigned char* uc = (unsigned char*)p; | |
686 | + value = (short)(*uc); | |
687 | + break; | |
688 | + } | |
689 | + case CDF_INT2 : | |
690 | + { | |
691 | + short* s = (short *)p; | |
692 | + value = (short)(*s); | |
693 | + break; | |
694 | + } | |
695 | + case CDF_UINT2 : | |
696 | + { | |
697 | + unsigned short* us = (unsigned short*)p; | |
698 | + value = (short)(*us); | |
699 | + break; | |
700 | + } | |
701 | + default: | |
702 | + return false; | |
703 | + } | |
704 | + return true; | |
705 | +} | |
706 | + | |
707 | +bool FileReaderCDF::extractInt(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
708 | + long dataType, long numBytes, int& value) | |
709 | +{ | |
710 | + //try to extract a short | |
711 | + short s; | |
712 | + if (extractShort(bufferType, recIndex, dimIndex, dimSize, | |
713 | + dataType, numBytes, s)) | |
714 | + { | |
715 | + //cast short to int | |
716 | + value = (int)s; | |
717 | + return true; | |
718 | + } | |
719 | + | |
720 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
721 | + switch (dataType) | |
722 | + { | |
723 | + case CDF_INT4 : | |
724 | + { | |
725 | + int* i = (int*)p; | |
726 | + value = (int)(*i); | |
727 | + break; | |
728 | + } | |
729 | + case CDF_UINT4 : | |
730 | + { | |
731 | + unsigned int* ui = (unsigned int*)(p); | |
732 | + value = (int)(*ui); | |
733 | + break; | |
734 | + } | |
735 | + default: | |
736 | + return false; | |
737 | + } | |
738 | + | |
739 | + return true; | |
740 | +} | |
741 | + | |
742 | +bool FileReaderCDF::extractFloat(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
743 | + long dataType, long numBytes, float& value) | |
744 | +{ | |
745 | + //try to extract an int | |
746 | + int i; | |
747 | + if (extractInt(bufferType, recIndex, dimIndex, dimSize, | |
748 | + dataType, numBytes, i)) | |
749 | + { | |
750 | + //cast int to float | |
751 | + value = (float)i; | |
752 | + return true; | |
753 | + } | |
754 | + | |
755 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
756 | + switch (dataType) | |
757 | + { | |
758 | + case CDF_REAL4 : | |
759 | + case CDF_FLOAT : | |
760 | + { | |
761 | + float* f = (float*)p; | |
762 | + value = (float)(*f); | |
763 | + break; | |
764 | + } | |
765 | + default : | |
766 | + return false; | |
767 | + } | |
768 | + | |
769 | + return true; | |
770 | +} | |
771 | + | |
772 | +bool FileReaderCDF::extractDouble(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
773 | + long dataType, long numBytes, double& value) | |
774 | +{ | |
775 | + //try to extract an float | |
776 | + float f; | |
777 | + if (extractFloat(bufferType, recIndex, dimIndex, dimSize, | |
778 | + dataType, numBytes, f)) | |
779 | + { | |
780 | + //cast float to double | |
781 | + value = (double)f; | |
782 | + return true; | |
783 | + } | |
784 | + | |
785 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
786 | + | |
787 | + switch(dataType) | |
788 | + { | |
789 | + case CDF_REAL8 : | |
790 | + case CDF_DOUBLE : | |
791 | + case CDF_EPOCH : | |
792 | + { | |
793 | + double* d = (double*)p; | |
794 | + value = (double)(*d); | |
795 | + break; | |
796 | + } | |
797 | + default : | |
798 | + return false; | |
799 | + } | |
800 | + | |
801 | + return true; | |
802 | +} | |
803 | + | |
804 | +bool FileReaderCDF::extractEpoch16(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
805 | + long dataType, long numBytes, double value[]) | |
806 | +{ | |
807 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
808 | + | |
809 | + switch(dataType) | |
810 | + { | |
811 | + case CDF_EPOCH16 : | |
812 | + { | |
813 | + std::memcpy(value, p, 2*sizeof(double)); | |
814 | + return true; | |
815 | + } | |
816 | + default : | |
817 | + return false; | |
818 | + } | |
819 | + | |
820 | + return true; | |
821 | +} | |
822 | + | |
823 | +bool FileReaderCDF::extractTT2000(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
824 | + long dataType, long numBytes, long long& value) | |
825 | +{ | |
826 | + void *p = (void*)((intptr_t)_workingBuffers->getBuffer(bufferType) + (recIndex*dimSize + dimIndex)*numBytes); | |
827 | + | |
828 | + switch(dataType) | |
829 | + { | |
830 | + case CDF_TIME_TT2000 : | |
831 | + { | |
832 | + long long* ll = (long long*)p; | |
833 | + value = (long long)(*ll); | |
834 | + break; | |
835 | + } | |
836 | + default : | |
837 | + return false; | |
838 | + } | |
839 | + | |
840 | + return true; | |
841 | +} | |
842 | + | |
843 | +/* | |
844 | + * @brief Get an information | |
845 | + */ | |
846 | +bool FileReaderCDF::getInfo(const char* pInfoName, std::vector<double>& res) | |
847 | +{ | |
848 | + LOG4CXX_DEBUG(gLogger, "FileReaderCDF::getInfo"); | |
849 | + | |
850 | + boost::mutex::scoped_lock scoped_lock(AMDA::Parameters::ParameterManager::mutexCDFLib); | |
851 | + | |
852 | + //get CDF var info | |
853 | + CDFVarInfo varInfo; | |
854 | + if (getCDFVarInfo(pInfoName, varInfo)) { | |
855 | + scoped_lock.unlock(); | |
856 | + std::string emptyTimeStr = ""; | |
857 | + std::string paramName = pInfoName; | |
858 | + SpeasyProxyParamType paramType; | |
859 | + int dim1Size, dim2Size; | |
860 | + getParamInfo(paramName, paramType, dim1Size, dim2Size); | |
861 | + | |
862 | + SpeasyProxyParamDataPacket packet; | |
863 | + | |
864 | + SpeasyProxyContainerType containerType = CONTAINER_SCALAR; | |
865 | + if ((dim1Size > 1) && (dim2Size <= 1)) | |
866 | + containerType = CONTAINER_VECTOR; | |
867 | + else if ((dim1Size > 1) && (dim2Size > 1)) | |
868 | + containerType = CONTAINER_MATRIX; | |
869 | + | |
870 | + packet.init(containerType,paramType,dim1Size,dim2Size); | |
871 | + getParamPacketData(emptyTimeStr, paramName, &packet); | |
872 | + if (packet.getNbData() > 0) { | |
873 | + for (int i = 0; i < dim1Size; ++i) { | |
874 | + for (int j = 0; j < dim2Size; ++j) { | |
875 | + switch (paramType) | |
876 | + { | |
877 | + case TYPE_FLOAT : | |
878 | + { | |
879 | + float f = 0.; | |
880 | + packet.getDataValue(&f, 0, i, j); | |
881 | + res.push_back(f); | |
882 | + break; | |
883 | + } | |
884 | + case TYPE_DOUBLE : | |
885 | + { | |
886 | + double d = 0;; | |
887 | + packet.getDataValue(&d, 0, i, j); | |
888 | + res.push_back(d); | |
889 | + break; | |
890 | + } | |
891 | + case TYPE_SHORT : | |
892 | + { | |
893 | + short s = 0; | |
894 | + packet.getDataValue(&s, 0, i, j); | |
895 | + res.push_back(s); | |
896 | + break; | |
897 | + } | |
898 | + case TYPE_INT : | |
899 | + { | |
900 | + int d = 0; | |
901 | + packet.getDataValue(&d, 0, i, j); | |
902 | + res.push_back(d); | |
903 | + break; | |
904 | + } | |
905 | + default: | |
906 | + return false; | |
907 | + } | |
908 | + } | |
909 | + } | |
910 | + packet.free(); | |
911 | + return true; | |
912 | + } | |
913 | + } | |
914 | + | |
915 | + return false; | |
916 | +} | |
917 | + | |
918 | +} /* SpeasyProxyInterface */ | |
919 | +} /* AMDA */ | ... | ... |
... | ... | @@ -0,0 +1,305 @@ |
1 | +/* | |
2 | + * FileReaderCDF.hh | |
3 | + * | |
4 | + * Created on: Nov 24, 2014 | |
5 | + * Author: AKKA | |
6 | + */ | |
7 | + | |
8 | +#ifndef FILEREADERCDF_HH_ | |
9 | +#define FILEREADERCDF_HH_ | |
10 | +#include <string> | |
11 | +#include "SpeasyProxyParamData.hh" | |
12 | + | |
13 | +#include "cdf.h" | |
14 | + | |
15 | +namespace AMDA { | |
16 | +namespace SpeasyProxyInterface { | |
17 | + | |
18 | + | |
19 | +/* | |
20 | + * @brief Status for getParamPacketData function | |
21 | + */ | |
22 | +typedef enum | |
23 | +{ | |
24 | + //more data is needed (ie. the paket is full and must be proceed before to continue) | |
25 | + FRS_MORE, | |
26 | + //end of file | |
27 | + FRS_EOF, | |
28 | + //stop time is reached | |
29 | + FRS_FINISH, | |
30 | + //error detected | |
31 | + FRS_ERROR | |
32 | +} FileReaderStatus; | |
33 | +/* | |
34 | + * @brief Implementation of the class FileReaderAbstract to load a CDF file format | |
35 | + */ | |
36 | +class FileReaderCDF | |
37 | +{ | |
38 | +public: | |
39 | + /* | |
40 | + * @brief Constructor | |
41 | + */ | |
42 | + FileReaderCDF(); | |
43 | + | |
44 | + /* | |
45 | + * @brief Destructor | |
46 | + */ | |
47 | + ~FileReaderCDF(); | |
48 | + | |
49 | + /* | |
50 | + * @brief Open a CDF file | |
51 | + */ | |
52 | + bool open(std::string filePath); | |
53 | + | |
54 | + /* | |
55 | + * @brief Close the CDF file | |
56 | + */ | |
57 | + bool close(void); | |
58 | + | |
59 | + /* | |
60 | + * @brief Test if a CDF file is currently opened | |
61 | + */ | |
62 | + bool isOpened(void); | |
63 | + | |
64 | + /* | |
65 | + * @brief Get the id of the time param to use. For the CDF format, it's the first CDF_EPOCH var | |
66 | + */ | |
67 | + std::string getTimeParamId(void); | |
68 | + | |
69 | + /* | |
70 | + * @brief Get a param type and a param size in the CDF file | |
71 | + */ | |
72 | + bool getParamInfo(std::string& paramId, SpeasyProxyParamType& paramType, int& dim1Size, int& dim2Size); | |
73 | + | |
74 | + /* | |
75 | + * @brief Get the index of the nearest record of time (the higher one) in the CDF file | |
76 | + */ | |
77 | + int getRecordIndex(std::string& timeId, double time); | |
78 | + | |
79 | + /* | |
80 | + * @brief Get a param packet from the CDF file | |
81 | + */ | |
82 | + FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId, SpeasyProxyParamDataPacket *packet); | |
83 | + | |
84 | + /* | |
85 | + * @brief Get an information | |
86 | + */ | |
87 | + bool getInfo(const char* pInfoName, std::vector<double>& res); | |
88 | + | |
89 | +protected: | |
90 | + /* | |
91 | + * @brief TimeStamp (Unix time) to EPOCH time conversion | |
92 | + */ | |
93 | + double timeStampToEPOCHTime(double timeStamp); | |
94 | + | |
95 | + /* | |
96 | + * @brief EPOCH time to TimeStamp conversion | |
97 | + */ | |
98 | + double epochTimeToTimeStamp(double epochTime); | |
99 | + | |
100 | + /* | |
101 | + * @brief EPOCH16 time to EPOCH conversion | |
102 | + */ | |
103 | + double epoch16ToEpochTime(double epoch16Time[]); | |
104 | + | |
105 | + /* | |
106 | + * @brief TT2000 time to EPOCH conversion | |
107 | + */ | |
108 | + double tt2000ToEpochTime(long long tt2000Time); | |
109 | + | |
110 | +private: | |
111 | + | |
112 | + /* | |
113 | + * @brief CDF var type : rVariable or zVariable | |
114 | + */ | |
115 | + typedef enum {CDFVT_R,CDFVT_Z} CDFVarType; | |
116 | + | |
117 | + /* | |
118 | + * @brief Working structure to contain CDF variable info | |
119 | + */ | |
120 | + typedef struct | |
121 | + { | |
122 | + //variable name | |
123 | + char _name[CDF_VAR_NAME_LEN256+1]; | |
124 | + //rVariable or zVariable | |
125 | + CDFVarType _type; | |
126 | + //variable number | |
127 | + long _num; | |
128 | + //data type | |
129 | + long _dataType; | |
130 | + //number of bytes for the data type | |
131 | + long _numBytes; | |
132 | + //number of elements (of the data type) | |
133 | + long _numElts; | |
134 | + //number of dimensions | |
135 | + long _numDims; | |
136 | + //dimension sizes | |
137 | + long _dimSizes[CDF_MAX_DIMS]; | |
138 | + //record variance | |
139 | + long _recVary; | |
140 | + //dimension variances | |
141 | + long _dimVarys[CDF_MAX_DIMS]; | |
142 | + //maximum record number | |
143 | + long _maxRecNum; | |
144 | + } CDFVarInfo; | |
145 | + | |
146 | + /* | |
147 | + * @brief Working buffers container | |
148 | + */ | |
149 | + class CDFWorkingBuffers | |
150 | + { | |
151 | + public: | |
152 | + /* | |
153 | + * @brief Buffer type: | |
154 | + */ | |
155 | + typedef enum { | |
156 | + //buffer used to store time data | |
157 | + BUFFER_TIME, | |
158 | + //buffer used to store param data | |
159 | + BUFFER_DATA, | |
160 | + //buffer used to store packet data for one record | |
161 | + BUFFER_PACKETREC | |
162 | + } BufferType; | |
163 | + | |
164 | + /* | |
165 | + * @brief Constructor | |
166 | + */ | |
167 | + CDFWorkingBuffers() : _timeBuffer(NULL), _dataBuffer(NULL), _packetRecBuffer(NULL) | |
168 | + { | |
169 | + } | |
170 | + | |
171 | + /* | |
172 | + * @brief Destructor | |
173 | + */ | |
174 | + ~CDFWorkingBuffers() | |
175 | + { | |
176 | + //free all buffers | |
177 | + if (_timeBuffer != NULL) | |
178 | + free(_timeBuffer); | |
179 | + if (_dataBuffer != NULL) | |
180 | + free(_dataBuffer); | |
181 | + if (_packetRecBuffer != NULL) | |
182 | + free(_packetRecBuffer); | |
183 | + } | |
184 | + | |
185 | + /* | |
186 | + * @brief Get buffer pointer from a buffer type | |
187 | + */ | |
188 | + void* getBuffer(BufferType type) | |
189 | + { | |
190 | + switch (type) | |
191 | + { | |
192 | + case BUFFER_TIME: | |
193 | + return _timeBuffer; | |
194 | + case BUFFER_DATA: | |
195 | + return _dataBuffer; | |
196 | + case BUFFER_PACKETREC: | |
197 | + return _packetRecBuffer; | |
198 | + } | |
199 | + return NULL; | |
200 | + } | |
201 | + | |
202 | + /* | |
203 | + * @brief Reallocate a buffer from a buffer type | |
204 | + */ | |
205 | + void reallocBuffer(BufferType type, long size) | |
206 | + { | |
207 | + switch (type) | |
208 | + { | |
209 | + case BUFFER_TIME: | |
210 | + if (_timeBuffer != NULL) | |
211 | + free(_timeBuffer); | |
212 | + _timeBuffer = malloc(size); | |
213 | + break; | |
214 | + case BUFFER_DATA: | |
215 | + if (_dataBuffer != NULL) | |
216 | + free(_dataBuffer); | |
217 | + _dataBuffer = malloc(size); | |
218 | + break; | |
219 | + case BUFFER_PACKETREC: | |
220 | + if (_packetRecBuffer != NULL) | |
221 | + free(_packetRecBuffer); | |
222 | + _packetRecBuffer = malloc(size); | |
223 | + break; | |
224 | + } | |
225 | + } | |
226 | + | |
227 | + private: | |
228 | + /* | |
229 | + * @brief Buffer for time data | |
230 | + */ | |
231 | + void* _timeBuffer; | |
232 | + | |
233 | + /* | |
234 | + * @brief Buffer for param data | |
235 | + */ | |
236 | + void* _dataBuffer; | |
237 | + | |
238 | + /* | |
239 | + * @brief Buffer for one record packet data | |
240 | + */ | |
241 | + void* _packetRecBuffer; | |
242 | + }; | |
243 | + | |
244 | + /* | |
245 | + * @brief CDF identifier | |
246 | + */ | |
247 | + CDFid _cdfid; | |
248 | + | |
249 | + /* | |
250 | + * @brief Working buffers container | |
251 | + */ | |
252 | + boost::shared_ptr<CDFWorkingBuffers> _workingBuffers; | |
253 | + | |
254 | + /* | |
255 | + * @brief Get CDF variable Info from param name | |
256 | + */ | |
257 | + bool getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo); | |
258 | + | |
259 | + /* | |
260 | + * @brief Get CDF data for paramId from startRec to the end of the file | |
261 | + */ | |
262 | + bool getCDFData(std::string& varId, long startRec, CDFWorkingBuffers::BufferType bufferType, | |
263 | + long& dataType, long& numBytes, long& nbRec, long& dimSize); | |
264 | + | |
265 | + /* | |
266 | + * @brief Extract a short to a CDF data buffer | |
267 | + */ | |
268 | + bool extractShort(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
269 | + long dataType, long numBytes, short& value); | |
270 | + | |
271 | + /* | |
272 | + * @brief Extract a int to a CDF data buffer | |
273 | + */ | |
274 | + bool extractInt(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
275 | + long dataType, long numBytes, int& value); | |
276 | + | |
277 | + /* | |
278 | + * @brief Extract a float to a CDF data buffer | |
279 | + */ | |
280 | + bool extractFloat(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
281 | + long dataType, long numBytes, float& value); | |
282 | + | |
283 | + /* | |
284 | + * @brief Extract a int to a CDF data buffer | |
285 | + */ | |
286 | + bool extractDouble(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
287 | + long dataType, long numBytes, double& value); | |
288 | + | |
289 | + /* | |
290 | + * @brief Extract a Epoch16 to a CDF data buffer | |
291 | + */ | |
292 | + bool extractEpoch16(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
293 | + long dataType, long numBytes, double value[]); | |
294 | + | |
295 | + /* | |
296 | + * @brief Extract a TT2000 to a CDF data buffer | |
297 | + */ | |
298 | + bool extractTT2000(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize, | |
299 | + long dataType, long numBytes, long long& value); | |
300 | +}; | |
301 | + | |
302 | +} /* SpeasyProxyInterface */ | |
303 | +} /* AMDA */ | |
304 | + | |
305 | +#endif /* FILEREADERCDF_HH_ */ | ... | ... |
src/ParamGetImpl/SpeasyProxyInterface/GetSpeasyProxyNode.cc
... | ... | @@ -15,13 +15,15 @@ |
15 | 15 | #include "ParamGetSpeasyProxy.hh" |
16 | 16 | #include "ParameterManager.hh" |
17 | 17 | |
18 | +#include <boost/algorithm/string.hpp> | |
19 | +#include <boost/lexical_cast.hpp> | |
20 | + | |
18 | 21 | using namespace AMDA::Parameters; |
19 | 22 | |
20 | 23 | #include "Constant.hh" |
21 | 24 | |
22 | 25 | #include "Config.hh" |
23 | 26 | #include "GetSpeasyProxyNode.hh" |
24 | -// #include "LocalParamData.hh" | |
25 | 27 | |
26 | 28 | using namespace AMDA::XMLConfigurator; |
27 | 29 | |
... | ... | @@ -71,6 +73,61 @@ public: |
71 | 73 | lParamGet->setParamId(paramIdStr.c_str()); |
72 | 74 | lParameter->setDataWriter(lDataWriter); |
73 | 75 | |
76 | + //type | |
77 | + xmlChar* value = NULL; | |
78 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"type")) != NULL) | |
79 | + { | |
80 | + if (strcmp((const char*)value,"float") == 0) | |
81 | + lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_FLOAT); | |
82 | + else if (strcmp((const char*)value,"double") == 0) | |
83 | + lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_DOUBLE); | |
84 | + else if (strcmp((const char*)value,"short") == 0) | |
85 | + lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_SHORT); | |
86 | + else if ((strcmp((const char*)value,"int") == 0) || (strcmp((const char*)value,"integer") == 0)) | |
87 | + lParamGet->setType(AMDA::SpeasyProxyInterface::SpeasyProxyParamType::TYPE_INT); | |
88 | + else | |
89 | + { | |
90 | + LOG4CXX_ERROR(gLogger, "SpeasyProxyParamNode::proceed - Unknown data type " << ((const char*)value)) | |
91 | + } | |
92 | + xmlFree(value); | |
93 | + } | |
94 | + | |
95 | + //dim1 | |
96 | + | |
97 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"dim1")) != NULL) | |
98 | + { | |
99 | + std::string dim1Str = std::string((const char*) value); | |
100 | + boost::trim(dim1Str); | |
101 | + int dim1 = boost::lexical_cast<int>(dim1Str); | |
102 | + if(dim1 >= 0 && dim1 <= 3) | |
103 | + lParamGet->setDim1(dim1); | |
104 | + else | |
105 | + lParamGet->setDim1(1); | |
106 | + xmlFree(value); | |
107 | + | |
108 | + } | |
109 | + | |
110 | + //dim2 | |
111 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"dim2")) != NULL) | |
112 | + { | |
113 | + std::string dim2Str = std::string((const char*) value); | |
114 | + boost::trim(dim2Str); | |
115 | + int dim2 = boost::lexical_cast<int>(dim2Str); | |
116 | + if(dim2 >= 0 && dim2 <= 3) | |
117 | + lParamGet->setDim2(dim2); | |
118 | + else | |
119 | + lParamGet->setDim2(1); | |
120 | + xmlFree(value); | |
121 | + | |
122 | + } | |
123 | + | |
124 | + //minSampling | |
125 | + if ((value = xmlGetProp(pNode, (const xmlChar*)"minSampling")) != NULL) | |
126 | + { | |
127 | + lParamGet->setMinSampling(atof((const char*)value)); | |
128 | + xmlFree(value); | |
129 | + } | |
130 | + | |
74 | 131 | AMDA::Parameters::CfgContext lContext(pContext); |
75 | 132 | lContext.push<AMDA::SpeasyProxyInterface::ParamGetSpeasyProxy*>(lParamGet.get()); |
76 | 133 | NodeGrpCfg::proceed(pNode, lContext); | ... | ... |
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc
... | ... | @@ -9,6 +9,8 @@ |
9 | 9 | #include "ParamGetSpeasyProxy.hh" |
10 | 10 | // #include "VirtualInstrumentManager.hh" |
11 | 11 | |
12 | +#include "FileReaderCDF.hh" | |
13 | + | |
12 | 14 | #include <stdlib.h> |
13 | 15 | |
14 | 16 | #include "Parameter.hh" |
... | ... | @@ -29,15 +31,18 @@ namespace SpeasyProxyInterface { |
29 | 31 | |
30 | 32 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(Parameter ¶meter) : |
31 | 33 | ParamGet_CRTP<ParamGetSpeasyProxy>(parameter), |
32 | - _paramId(""),_timeStamp(0),_type(TYPE_FLOAT), _container(CONTAINER_SCALAR) | |
34 | + _paramId(""),_type(TYPE_FLOAT),_dim1(1), _dim2(1), _minSampling(1), _container(CONTAINER_SCALAR),_timeStamp(0) | |
33 | 35 | { |
34 | 36 | |
35 | 37 | } |
36 | 38 | |
37 | 39 | ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpeasyProxy, Parameter ¶meter) : |
38 | 40 | ParamGet_CRTP<ParamGetSpeasyProxy>(pParamGetSpeasyProxy, parameter), |
39 | - _paramId(pParamGetSpeasyProxy._paramId), _timeStamp(pParamGetSpeasyProxy._timeStamp), | |
40 | - _type(pParamGetSpeasyProxy._type), _container(pParamGetSpeasyProxy._container) | |
41 | + _paramId(pParamGetSpeasyProxy._paramId), _type(pParamGetSpeasyProxy._type), | |
42 | + _dim1(pParamGetSpeasyProxy._dim1), _dim2(pParamGetSpeasyProxy._dim2), | |
43 | + _minSampling(pParamGetSpeasyProxy._minSampling), _container(pParamGetSpeasyProxy._container), | |
44 | + _timeStamp(pParamGetSpeasyProxy._timeStamp) | |
45 | + | |
41 | 46 | { |
42 | 47 | |
43 | 48 | } |
... | ... | @@ -49,14 +54,6 @@ ParamGetSpeasyProxy::~ParamGetSpeasyProxy() |
49 | 54 | // delete _pusher; |
50 | 55 | } |
51 | 56 | |
52 | -/* | |
53 | - * @overload DataWriter::getMinSampling | |
54 | - */ | |
55 | -double ParamGetSpeasyProxy::getMinSampling() | |
56 | -{ | |
57 | - return 0; | |
58 | -} | |
59 | - | |
60 | 57 | std::string ParamGetSpeasyProxy::readFile(const std::string& filename) { |
61 | 58 | // Create an input file stream |
62 | 59 | std::ifstream file(filename); |
... | ... | @@ -142,16 +139,97 @@ std::string ParamGetSpeasyProxy::download(const std::string& pPath) { |
142 | 139 | TimeStamp ParamGetSpeasyProxy::init() |
143 | 140 | { |
144 | 141 | LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init"); |
145 | - // Test si proxy accessible | |
146 | - // A Faire | |
142 | + | |
143 | + // Ici, instanciation du Pusher (en fonction du type et des dim définis dans le fichier XML) | |
144 | + | |
145 | + _currentInterval = _timeIntervalList->begin(); | |
146 | + | |
147 | + // get the right container | |
148 | + | |
149 | + if (_dim1 * _dim2 == 1) { | |
150 | + _container = CONTAINER_SCALAR; | |
151 | + } | |
152 | + else if ((_dim1 > 1) && (_dim2 > 1)) { | |
153 | + _container = CONTAINER_MATRIX; | |
154 | + } | |
155 | + else { | |
156 | + _container = CONTAINER_VECTOR; | |
157 | + } | |
158 | + | |
159 | + //create pusher | |
160 | + switch (_container) { | |
161 | + case CONTAINER_SCALAR : | |
162 | + switch (_type) { | |
163 | + case TYPE_FLOAT : | |
164 | + _pusher = new Pusher<TYPE_FLOAT, CONTAINER_SCALAR>(); | |
165 | + break; | |
166 | + case TYPE_DOUBLE : | |
167 | + _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_SCALAR>(); | |
168 | + break; | |
169 | + case TYPE_SHORT : | |
170 | + _pusher = new Pusher<TYPE_SHORT, CONTAINER_SCALAR>(); | |
171 | + break; | |
172 | + case TYPE_INT : | |
173 | + _pusher = new Pusher<TYPE_INT, CONTAINER_SCALAR>(); | |
174 | + break; | |
175 | + default: | |
176 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | |
177 | + | |
178 | + } | |
179 | + break; | |
180 | + case CONTAINER_VECTOR : | |
181 | + switch (_type) { | |
182 | + case TYPE_FLOAT : | |
183 | + _pusher = new Pusher<TYPE_FLOAT, CONTAINER_VECTOR>(_dim1); | |
184 | + break; | |
185 | + case TYPE_DOUBLE : | |
186 | + _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_VECTOR>(_dim1); | |
187 | + break; | |
188 | + case TYPE_SHORT : | |
189 | + _pusher = new Pusher<TYPE_SHORT, CONTAINER_VECTOR>(_dim1); | |
190 | + break; | |
191 | + case TYPE_INT : | |
192 | + _pusher = new Pusher<TYPE_INT, CONTAINER_VECTOR>(_dim1); | |
193 | + break; | |
194 | + default: | |
195 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | |
196 | + } | |
197 | + break; | |
198 | + case CONTAINER_MATRIX : | |
199 | + switch (_type) { | |
200 | + case TYPE_FLOAT : | |
201 | + _pusher = new Pusher<TYPE_FLOAT, CONTAINER_MATRIX>(_dim1, _dim2); | |
202 | + break; | |
203 | + case TYPE_DOUBLE : | |
204 | + _pusher = new Pusher<TYPE_DOUBLE, CONTAINER_MATRIX>(_dim1, _dim2); | |
205 | + break; | |
206 | + case TYPE_SHORT : | |
207 | + _pusher = new Pusher<TYPE_SHORT, CONTAINER_MATRIX>(_dim1, _dim2); | |
208 | + break; | |
209 | + case TYPE_INT : | |
210 | + _pusher = new Pusher<TYPE_INT, CONTAINER_MATRIX>(_dim1, _dim2); | |
211 | + break; | |
212 | + default: | |
213 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown type" << (const char*)_type); | |
214 | + } | |
215 | + break; | |
216 | + default: | |
217 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasyProxy::init() - Unknown container format " << (const char*)_container); | |
218 | + | |
219 | + } | |
147 | 220 | |
221 | + //set link to the param data | |
222 | + _paramData = ParamDataSPtr(_pusher->getParamData()); | |
223 | + _paramData->setMinSampling(_minSampling); | |
148 | 224 | |
149 | - std::string link = "http://172.200.0.14:6543/get_data?path=amda%2Fimf&start_time=2008-01-01T00%3A00%3A00&stop_time=2008-01-02T00%3A00%3A00&format=json&zstd_compression=false&pickle_proto=3"; | |
150 | - std::string localPath = download(link); | |
151 | 225 | |
152 | - std::string value = readFile(localPath); | |
226 | + if (_timeStamp == 0 && _signatureTrigger != "") { | |
227 | + // _signatureTrigger must be a name of xml parameter file | |
228 | + _timeStamp = AMDA::Helpers::Helper::dateOfFile( | |
229 | + _signatureTrigger.c_str()); | |
230 | + } | |
153 | 231 | |
154 | - _container = CONTAINER_VECTOR; // For now | |
232 | + | |
155 | 233 | return _timeStamp; |
156 | 234 | } |
157 | 235 | |
... | ... | @@ -160,6 +238,56 @@ unsigned int ParamGetSpeasyProxy::write() |
160 | 238 | { |
161 | 239 | unsigned int result = 0; |
162 | 240 | |
241 | + //std::string link = "http://172.200.0.14:6543/get_data?path=amda%2Fimf&start_time=2008-01-01T00%3A00%3A00&stop_time=2008-01-02T00%3A00%3A00&format=json&zstd_compression=false&pickle_proto=3"; | |
242 | + std::string localPath = "/home/amda_admin/AMDA/AMDA_Kernel/cdf_speasy.cdf"; | |
243 | + FileReaderCDF* fileReaderPtr = new FileReaderCDF(); | |
244 | + bool isOpen = fileReaderPtr->open(localPath); | |
245 | + if(isOpen) | |
246 | + { | |
247 | + std::string timeParamId = "time"; | |
248 | + std::string croptedParamId = _paramId; | |
249 | + std::string delim = "/"; | |
250 | + croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); | |
251 | + | |
252 | + // Call to getParamPacketData to get CDF data | |
253 | + | |
254 | + SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket(); | |
255 | + packet->init(_container,_type,_dim1,_dim2); | |
256 | + | |
257 | + fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, packet); | |
258 | + | |
259 | + | |
260 | + // Call to the put function of pusher to initiate the ParamData | |
261 | + // result == nb of data in ParamData | |
262 | + result += _pusher->put(packet); | |
263 | + | |
264 | + // Push up the information if all time interval was processed. | |
265 | + _paramData->getIndexInfo()._timeIntToProcessChanged = true; // ATTENTION - valeur forcée pour les tests!!!!! | |
266 | + if (true) { | |
267 | + ++_currentInterval; | |
268 | + _paramData->getIndexInfo()._noMoreTimeInt = (_currentInterval == _timeIntervalList->end()); | |
269 | + } | |
270 | + | |
271 | + _paramData->getIndexInfo()._nbDataToProcess = result; | |
272 | + | |
273 | + // if time interval changed store index which delimit the end of the time interval. | |
274 | + if (_paramData->getIndexInfo()._timeIntToProcessChanged) { | |
275 | + unsigned int lEndTimeIntIndex = _paramData->getIndexInfo()._nbDataToProcess; | |
276 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lEndTimeIntIndex); | |
277 | + } | |
278 | + else { | |
279 | + // Nothing to do. | |
280 | + } | |
281 | + | |
282 | + return result; | |
283 | + } | |
284 | + | |
285 | + //close the file | |
286 | + if (!fileReaderPtr->close()) | |
287 | + { | |
288 | + LOG4CXX_ERROR(gLogger, "ParamGetSpeasy::init - Cannot close file " << localPath); | |
289 | + } | |
290 | + | |
163 | 291 | return result; |
164 | 292 | } |
165 | 293 | ... | ... |
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh
... | ... | @@ -45,7 +45,7 @@ public: |
45 | 45 | virtual ~ParamGetSpeasyProxy(); |
46 | 46 | |
47 | 47 | /* |
48 | - * @brief Get param id in local base | |
48 | + * @brief Get param id in speasy xml | |
49 | 49 | */ |
50 | 50 | const std::string& getParamId() const |
51 | 51 | { |
... | ... | @@ -53,7 +53,7 @@ public: |
53 | 53 | } |
54 | 54 | |
55 | 55 | /* |
56 | - * @brief Set param id in local base | |
56 | + * @brief Set param id in speasy xml | |
57 | 57 | */ |
58 | 58 | void setParamId(const char* paramId) |
59 | 59 | { |
... | ... | @@ -66,9 +66,84 @@ public: |
66 | 66 | virtual unsigned int write(); |
67 | 67 | |
68 | 68 | /* |
69 | - * @overload DataWriter::getMinSampling | |
69 | + * @brief Get param type in speasy xml | |
70 | 70 | */ |
71 | - virtual double getMinSampling(); | |
71 | + SpeasyProxyParamType getType() | |
72 | + { | |
73 | + return _type; | |
74 | + } | |
75 | + | |
76 | + /* | |
77 | + * @brief Set param type in speasy xml | |
78 | + */ | |
79 | + void setType(SpeasyProxyParamType type) | |
80 | + { | |
81 | + _type = type; | |
82 | + } | |
83 | + | |
84 | + /* | |
85 | + * @brief Get param dim1 size in speasy xml | |
86 | + */ | |
87 | + int getDim1(void) | |
88 | + { | |
89 | + return _dim1; | |
90 | + } | |
91 | + | |
92 | + /* | |
93 | + * @brief Set param dim1 size in speasy xml | |
94 | + */ | |
95 | + void setDim1(int size) | |
96 | + { | |
97 | + _dim1 = size; | |
98 | + } | |
99 | + | |
100 | + /* | |
101 | + * @brief Get param dim2 size in speasy xml | |
102 | + */ | |
103 | + int getDim2(void) | |
104 | + { | |
105 | + return _dim2; | |
106 | + } | |
107 | + | |
108 | + /* | |
109 | + * @brief Set param dim2 size in speasy xml | |
110 | + */ | |
111 | + void setDim2(int size) | |
112 | + { | |
113 | + _dim2 = size; | |
114 | + } | |
115 | + | |
116 | + /* | |
117 | + * @brief Get param min sampling in speasy xml | |
118 | + */ | |
119 | + double getMinSampling(void) | |
120 | + { | |
121 | + return _minSampling; | |
122 | + } | |
123 | + | |
124 | + /* | |
125 | + * @brief Set param min sampling in speasy xml | |
126 | + */ | |
127 | + void setMinSampling(double minSampling) | |
128 | + { | |
129 | + _minSampling = minSampling; | |
130 | + } | |
131 | + | |
132 | + // /* | |
133 | + // * @brief Get param max sampling in speasy xml | |
134 | + // */ | |
135 | + // double getMaxSampling(void) | |
136 | + // { | |
137 | + // return _maxSampling; | |
138 | + // } | |
139 | + | |
140 | + // /* | |
141 | + // * @brief Set param max sampling in speasy xml | |
142 | + // */ | |
143 | + // void setMaxSampling(double maxSampling) | |
144 | + // { | |
145 | + // _maxSampling = maxSampling; | |
146 | + // } | |
72 | 147 | |
73 | 148 | /* |
74 | 149 | * @brief Init |
... | ... | @@ -93,8 +168,33 @@ protected: |
93 | 168 | */ |
94 | 169 | std::string _paramId; |
95 | 170 | |
171 | + /* | |
172 | + * @brief Local Param type | |
173 | + */ | |
174 | + | |
96 | 175 | SpeasyProxyParamType _type; |
97 | 176 | |
177 | + /* | |
178 | + * @brief Local Param dim1 size | |
179 | + */ | |
180 | + int _dim1; | |
181 | + | |
182 | + /* | |
183 | + * @brief Local Param dim2 size | |
184 | + */ | |
185 | + int _dim2; | |
186 | + | |
187 | + /* | |
188 | + * @brief Local Param min sampling | |
189 | + */ | |
190 | + double _minSampling; | |
191 | + | |
192 | + // /* | |
193 | + // * @brief Local Param max sampling | |
194 | + // */ | |
195 | + // double _maxSampling; | |
196 | + | |
197 | + | |
98 | 198 | SpeasyProxyContainerType _container; |
99 | 199 | |
100 | 200 | /* |
... | ... | @@ -102,6 +202,8 @@ protected: |
102 | 202 | */ |
103 | 203 | TimeStamp _timeStamp; |
104 | 204 | |
205 | + TimeIntervalList::iterator _currentInterval; | |
206 | + | |
105 | 207 | /* |
106 | 208 | * @brief Data pusher |
107 | 209 | */ | ... | ... |
src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh
... | ... | @@ -29,7 +29,7 @@ public: |
29 | 29 | /* |
30 | 30 | * @brief Constructor |
31 | 31 | */ |
32 | - PusherBase (double sampling, double value, int dim1 = 1, int dim2 = 1) : _paramData(NULL), _sampling(sampling), _value(value), _dim1(dim1), _dim2(dim2) | |
32 | + PusherBase (int dim1 = 1, int dim2 = 1) : _paramData(NULL), _dim1(dim1), _dim2(dim2) | |
33 | 33 | { |
34 | 34 | } |
35 | 35 | |
... | ... | @@ -51,7 +51,7 @@ public: |
51 | 51 | /* |
52 | 52 | * @brief Virtual method to put a packet in the ParamData |
53 | 53 | */ |
54 | - virtual int put(double startTime, double stopTime, int lastIndex) = 0; | |
54 | + virtual int put(SpeasyProxyParamDataPacket* packet) = 0; | |
55 | 55 | |
56 | 56 | protected: |
57 | 57 | /* |
... | ... | @@ -60,16 +60,6 @@ protected: |
60 | 60 | AMDA::Parameters::ParamData* _paramData; |
61 | 61 | |
62 | 62 | /* |
63 | - * @brief Sampling value | |
64 | - */ | |
65 | - double _sampling; | |
66 | - | |
67 | - /* | |
68 | - * @brief Constant value | |
69 | - */ | |
70 | - double _value; | |
71 | - | |
72 | - /* | |
73 | 63 | * @brief For Vector and Tab2D dimension |
74 | 64 | */ |
75 | 65 | int _dim1; |
... | ... | @@ -117,7 +107,7 @@ public: |
117 | 107 | /* |
118 | 108 | * @brief Constructor |
119 | 109 | */ |
120 | - Pusher(double sampling, double value, int dim1, int dim2) : PusherBase(sampling, value, dim1, dim2) | |
110 | + Pusher(int dim1, int dim2) : PusherBase( dim1, dim2) | |
121 | 111 | { |
122 | 112 | _paramData = _specParamData = createParamData(); |
123 | 113 | // _nbDataByPacket = getNbDataByPacket(type, dim1, dim2); |
... | ... | @@ -126,35 +116,45 @@ public: |
126 | 116 | /* |
127 | 117 | * @brief Put packet in a "vector" ParamData |
128 | 118 | */ |
129 | - virtual int put(double startTime, double stopTime, int lastIndex) | |
119 | + virtual int put(SpeasyProxyParamDataPacket* packet) | |
130 | 120 | { |
131 | - // _specParamData->getDataList().resize(_nbDataByPacket); | |
132 | - | |
133 | - // for (int index = 0; index < _nbDataByPacket; ++index) | |
134 | - // { | |
135 | - // //get time | |
136 | - // double time = startTime + (lastIndex + index) * _sampling; | |
137 | - // if (time > stopTime) { | |
138 | - // return index; | |
139 | - // } | |
140 | - // //this element will be deleted by the Container designed by "_specParamData->getDataList()" | |
141 | - // ElemenType elem = ElemenType(_dim1,_dim2); | |
142 | - // for (int dim1Index = 0; dim1Index < _dim1; ++dim1Index) | |
143 | - // { | |
144 | - // for (int dim2Index = 0; dim2Index < _dim2; ++dim2Index) | |
145 | - // { | |
146 | - // BaseElemenType baseElem = _value; | |
147 | - // elem[dim1Index][dim2Index] = baseElem; | |
148 | - // } | |
149 | - // } | |
150 | - | |
151 | - // //push time and element in the ParamData | |
152 | - // _specParamData->getDataList().push_back(elem); | |
153 | - // _specParamData->getTimeList().push_back(time); | |
154 | - // } | |
155 | - | |
156 | - // //return nb of processed records | |
157 | - // return _nbDataByPacket; | |
121 | + //ParamData is created, add data | |
122 | + | |
123 | + _specParamData->getDataList().resize(packet->getNbData()); | |
124 | + | |
125 | + // BaseElemenType fillEl = _fillValue; | |
126 | + | |
127 | + for (int index = 0; index < packet->getNbData(); ++index) | |
128 | + { | |
129 | + //get time | |
130 | + double time = packet->getTime(index); | |
131 | + //this element will be deleted by the Container designed by "_specParamData->getDataList()" | |
132 | + ElemenType elem = ElemenType(packet->getDim1Size(),packet->getDim2Size()); | |
133 | + for (int dim1Index = 0; dim1Index < packet->getDim1Size(); ++dim1Index) | |
134 | + { | |
135 | + for (int dim2Index = 0; dim2Index < packet->getDim2Size(); ++dim2Index) | |
136 | + { | |
137 | + BaseElemenType baseElem; | |
138 | + //get data element | |
139 | + if (packet->getDataValue(&baseElem,index,dim1Index,dim2Index)) | |
140 | + { | |
141 | + // if (!isnan(_fillValue)) | |
142 | + // if (baseElem == fillEl) | |
143 | + // baseElem << NotANumber(); | |
144 | + } | |
145 | + else | |
146 | + baseElem << NotANumber(); | |
147 | + elem[dim1Index][dim2Index] = baseElem; | |
148 | + } | |
149 | + } | |
150 | + | |
151 | + //push time and element in the ParamData | |
152 | + _specParamData->getDataList().push_back(elem); | |
153 | + _specParamData->getTimeList().push_back(time); | |
154 | + } | |
155 | + | |
156 | + //return nb of processed records | |
157 | + return packet->getNbData(); | |
158 | 158 | |
159 | 159 | return 0; |
160 | 160 | } |
... | ... | @@ -187,7 +187,7 @@ public: |
187 | 187 | /* |
188 | 188 | * @brief Constructor |
189 | 189 | */ |
190 | - Pusher(double sampling, double value, int dim) : PusherBase(sampling, value, dim) | |
190 | + Pusher(int dim) : PusherBase(dim) | |
191 | 191 | { |
192 | 192 | _paramData = _specParamData = createParamData(); |
193 | 193 | // _nbDataByPacket = getNbDataByPacket(type, dim, 1); |
... | ... | @@ -196,33 +196,42 @@ public: |
196 | 196 | /* |
197 | 197 | * @brief Put packet in a "vector" ParamData |
198 | 198 | */ |
199 | - virtual int put(double startTime, double stopTime, int lastIndex) | |
199 | + virtual int put(SpeasyProxyParamDataPacket* packet) | |
200 | 200 | { |
201 | - // _specParamData->getDataList().resize(_nbDataByPacket); | |
202 | - | |
203 | - // for (int index = 0; index < _nbDataByPacket; ++index) | |
204 | - // { | |
205 | - // //get time | |
206 | - // double time = startTime + (lastIndex + index) * _sampling; | |
207 | - // if (time > stopTime) { | |
208 | - // return index; | |
209 | - // }; | |
210 | - | |
211 | - // ElemenType elem; | |
212 | - // for (int dimIndex = 0; dimIndex < _dim1; ++dimIndex) | |
213 | - // { | |
214 | - // BaseElemenType baseElem = _value; | |
215 | - // elem.push_back(baseElem); | |
216 | - // } | |
217 | - | |
218 | - // //push time and element in the ParamData | |
219 | - // _specParamData->getDataList().push_back(elem); | |
220 | - // _specParamData->getTimeList().push_back(time); | |
221 | - // } | |
222 | - | |
223 | - // //return nb of processed records | |
224 | - // return _nbDataByPacket; | |
225 | - return 0; | |
201 | + //ParamData is created, add data | |
202 | + _specParamData->getDataList().resize(packet->getNbData()); | |
203 | + | |
204 | + //BaseElemenType fillEl = _fillValue; | |
205 | + | |
206 | + for (int index = 0; index < packet->getNbData(); ++index) | |
207 | + { | |
208 | + //get time | |
209 | + double time = packet->getTime(index); | |
210 | + | |
211 | + ElemenType elem; | |
212 | + for (int dimIndex = 0; dimIndex < packet->getDim1Size(); ++dimIndex) | |
213 | + { | |
214 | + BaseElemenType baseElem; | |
215 | + //get data element | |
216 | + if (packet->getDataValue(&baseElem,index,dimIndex)) | |
217 | + { | |
218 | + // if (!isnan(_fillValue)) | |
219 | + // if (baseElem == fillEl) | |
220 | + // baseElem << NotANumber(); | |
221 | + } | |
222 | + else | |
223 | + baseElem << NotANumber(); | |
224 | + //push data base element | |
225 | + elem.push_back(baseElem); | |
226 | + } | |
227 | + | |
228 | + //push time and element in the ParamData | |
229 | + _specParamData->getDataList().push_back(elem); | |
230 | + _specParamData->getTimeList().push_back(time); | |
231 | + } | |
232 | + | |
233 | + //return nb of processed records | |
234 | + return packet->getNbData(); | |
226 | 235 | } |
227 | 236 | |
228 | 237 | /* |
... | ... | @@ -252,7 +261,7 @@ public: |
252 | 261 | /* |
253 | 262 | * @brief Constructor |
254 | 263 | */ |
255 | - Pusher(double sampling, double value) : PusherBase(sampling, value) | |
264 | + Pusher() : PusherBase() | |
256 | 265 | { |
257 | 266 | _paramData = _specParamData = createParamData(); |
258 | 267 | // _nbDataByPacket = getNbDataByPacket(type, 1, 1); |
... | ... | @@ -261,28 +270,37 @@ public: |
261 | 270 | /* |
262 | 271 | * @brief Put packet in a "scalar" ParamData |
263 | 272 | */ |
264 | - virtual int put(double startTime, double stopTime, int lastIndex) | |
273 | + virtual int put(SpeasyProxyParamDataPacket* packet) | |
265 | 274 | { |
266 | - // //ParamData is created, add data | |
267 | - // _specParamData->getDataList().resize(_nbDataByPacket); | |
268 | - | |
269 | - // for (int index = 0; index < _nbDataByPacket; ++index) | |
270 | - // { | |
271 | - // //get time | |
272 | - // double time = startTime + (lastIndex + index) * _sampling; | |
273 | - // if (time > stopTime) { | |
274 | - // return index; | |
275 | - // } | |
276 | - | |
277 | - // BaseElemenType baseElem = _value; | |
278 | - | |
279 | - // //push time and element in the ParamData | |
280 | - // _specParamData->getDataList().push_back(baseElem); | |
281 | - // _specParamData->getTimeList().push_back(time); | |
282 | - // } | |
283 | - | |
284 | - // return _nbDataByPacket; | |
285 | - return 0; | |
275 | + //ParamData is created, add data | |
276 | + _specParamData->getDataList().resize(packet->getNbData()); | |
277 | + | |
278 | + // BaseElemenType fillEl = _fillValue; | |
279 | + | |
280 | + for (int index = 0; index < packet->getNbData(); ++index) | |
281 | + { | |
282 | + //get time | |
283 | + double time = packet->getTime(index); | |
284 | + | |
285 | + BaseElemenType baseElem; | |
286 | + //get element | |
287 | + if (packet->getDataValue(&baseElem,index)) | |
288 | + { | |
289 | + // if (!isnan(_fillValue)) | |
290 | + // { | |
291 | + // if (baseElem == fillEl) | |
292 | + // baseElem << NotANumber(); | |
293 | + // } | |
294 | + } | |
295 | + else | |
296 | + baseElem << NotANumber(); | |
297 | + | |
298 | + //push time and element in the ParamData | |
299 | + _specParamData->getDataList().push_back(baseElem); | |
300 | + _specParamData->getTimeList().push_back(time); | |
301 | + } | |
302 | + | |
303 | + return packet->getNbData(); | |
286 | 304 | } |
287 | 305 | |
288 | 306 | SpecParamData* createParamData() { | ... | ... |
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh
... | ... | @@ -9,6 +9,12 @@ |
9 | 9 | #ifndef SPEASYPROXYPARAMDATA_HH_ |
10 | 10 | #define SPEASYPROXYPARAMDATA_HH_ |
11 | 11 | |
12 | +#include "SpeasyProxyInterfaceConfig.hh" | |
13 | + | |
14 | +#include <cstring> | |
15 | +#include <cstdint> | |
16 | + | |
17 | + | |
12 | 18 | namespace AMDA { |
13 | 19 | namespace SpeasyProxyInterface { |
14 | 20 | |
... | ... | @@ -37,10 +43,435 @@ enum SpeasyProxyParamType |
37 | 43 | }; |
38 | 44 | |
39 | 45 | /* |
46 | + * @brief Define the maximum dimension size | |
47 | + */ | |
48 | +#define PARAMPACKET_MAX_DIMSIZE 10000 | |
49 | + | |
50 | +/* | |
40 | 51 | * @brief Define the maximum bytes available for one packet |
41 | 52 | */ |
42 | -// #define PARAMPACKET_MAX_DATABYTES 80000 | |
43 | -// #define PARAMPACKET_MIN_NBDATABYPACKET 1000 | |
53 | +#define PARAMPACKET_MAX_DATABYTES 80000 | |
54 | +/* | |
55 | + * @brief Define a packet to push to a ParamData | |
56 | + */ | |
57 | +class SpeasyProxyParamDataPacket | |
58 | +{ | |
59 | +public: | |
60 | + /* | |
61 | + * @brief Constructor | |
62 | + */ | |
63 | + SpeasyProxyParamDataPacket(void) : _isInit(false), _containerType(CONTAINER_SCALAR), | |
64 | + _paramType(TYPE_UNKNOWN), _nbData(0), _nbMaxData(0), _dims(NULL), _size(0), | |
65 | + _times(NULL), _datas(NULL), _noData(false), _startTime(0.), _stopTime(0.) | |
66 | + { | |
67 | + } | |
68 | + | |
69 | + /* | |
70 | + * @brief Destructor | |
71 | + */ | |
72 | + ~SpeasyProxyParamDataPacket(void) | |
73 | + { | |
74 | + //free allocated data if needed | |
75 | + free(); | |
76 | + } | |
77 | + | |
78 | + /* | |
79 | + * @brief Init the packet. This function allocate all buffers used by a packet | |
80 | + */ | |
81 | + bool init(SpeasyProxyContainerType containerType, | |
82 | + SpeasyProxyParamType paramType, int dim1 = 0, int dim2 = 0) | |
83 | + { | |
84 | + if (_isInit) | |
85 | + //already init | |
86 | + return false; | |
87 | + | |
88 | + _containerType = containerType; | |
89 | + _paramType = paramType; | |
90 | + _size = 0; | |
91 | + | |
92 | + //compute dimSize | |
93 | + switch (_containerType) | |
94 | + { | |
95 | + case CONTAINER_SCALAR : | |
96 | + //for a scalar, no dims defined and the size is 1 | |
97 | + _size = 1; | |
98 | + _dims = NULL; | |
99 | + break; | |
100 | + case CONTAINER_VECTOR : | |
101 | + //for a vector, 1 "dims" defined and the size is egal to this dimension size | |
102 | + if (dim1 <= 0) | |
103 | + return false; | |
104 | + _size = dim1; | |
105 | + _dims = new int[1]; | |
106 | + _dims[0] = dim1; | |
107 | + break; | |
108 | + case CONTAINER_MATRIX : | |
109 | + //for a matrix, 2 "dims" defined and the size is egal to the multiplication of the two dimensions sizes | |
110 | + if ((dim1 <= 0) || (dim2 <= 0)) | |
111 | + return false; | |
112 | + _size = dim1 * dim2; | |
113 | + _dims = new int[2]; | |
114 | + _dims[0] = dim1; | |
115 | + _dims[1] = dim2; | |
116 | + break; | |
117 | + default: | |
118 | + return false; | |
119 | + } | |
120 | + | |
121 | + //check dimSize | |
122 | + if ((_size <= 0) || (_size >= PARAMPACKET_MAX_DIMSIZE)) | |
123 | + { | |
124 | + if (_dims != NULL) | |
125 | + { | |
126 | + delete[] _dims; | |
127 | + _dims = NULL; | |
128 | + } | |
129 | + return false; | |
130 | + } | |
131 | + | |
132 | + //init times and datas | |
133 | + //use the PARAMPACKET_MAX_DATABYTES to determine the maximum data that's a packet can contain | |
134 | + _nbData = 0; | |
135 | + switch (_paramType) | |
136 | + { | |
137 | + case TYPE_FLOAT : | |
138 | + _nbMaxData = PARAMPACKET_MAX_DATABYTES / (_size * sizeof(float)); | |
139 | + if (_nbMaxData < 1) | |
140 | + _nbMaxData = 1; | |
141 | + _times = new double[_nbMaxData]; | |
142 | + _datas = new float[_nbMaxData*_size]; | |
143 | + break; | |
144 | + case TYPE_DOUBLE : | |
145 | + _nbMaxData = PARAMPACKET_MAX_DATABYTES / (_size * sizeof(double)); | |
146 | + if (_nbMaxData < 1) | |
147 | + _nbMaxData = 1; | |
148 | + _times = new double[_nbMaxData]; | |
149 | + _datas = new double[_nbMaxData*_size]; | |
150 | + break; | |
151 | + case TYPE_SHORT : | |
152 | + _nbMaxData = PARAMPACKET_MAX_DATABYTES / (_size * sizeof(short)); | |
153 | + if (_nbMaxData < 1) | |
154 | + _nbMaxData = 1; | |
155 | + _times = new double[_nbMaxData]; | |
156 | + _datas = new short[_nbMaxData*_size]; | |
157 | + break; | |
158 | + case TYPE_INT : | |
159 | + _nbMaxData = PARAMPACKET_MAX_DATABYTES / (_size * sizeof(int)); | |
160 | + if (_nbMaxData < 1) | |
161 | + _nbMaxData = 1; | |
162 | + _times = new double[_nbMaxData]; | |
163 | + _datas = new int[_nbMaxData*_size]; | |
164 | + break; | |
165 | + default : | |
166 | + if (_dims != NULL) | |
167 | + { | |
168 | + delete[] _dims; | |
169 | + _dims = NULL; | |
170 | + } | |
171 | + return false; | |
172 | + } | |
173 | + | |
174 | + _isInit = true; | |
175 | + return true; | |
176 | + } | |
177 | + | |
178 | + /* | |
179 | + * @brief Free all allocated buffers. This function is called in the destructor | |
180 | + */ | |
181 | + void free() | |
182 | + { | |
183 | + if (!_isInit) | |
184 | + return; | |
185 | + | |
186 | + //free all allocated buffers | |
187 | + if (_dims != NULL) | |
188 | + { | |
189 | + delete[] _dims; | |
190 | + _dims = NULL; | |
191 | + } | |
192 | + | |
193 | + if (_times != NULL) | |
194 | + { | |
195 | + delete[] _times; | |
196 | + _times = NULL; | |
197 | + } | |
198 | + | |
199 | + if (_datas != NULL) | |
200 | + { | |
201 | + switch (_paramType) | |
202 | + { | |
203 | + case TYPE_FLOAT : | |
204 | + delete[] (float*)_datas; | |
205 | + _datas = NULL; | |
206 | + break; | |
207 | + case TYPE_DOUBLE : | |
208 | + delete[] (double*)_datas; | |
209 | + _datas = NULL; | |
210 | + break; | |
211 | + case TYPE_SHORT : | |
212 | + delete[] (short*)_datas; | |
213 | + _datas = NULL; | |
214 | + break; | |
215 | + case TYPE_INT : | |
216 | + delete[] (int*)_datas; | |
217 | + _datas = NULL; | |
218 | + break; | |
219 | + default : | |
220 | + throw; | |
221 | + } | |
222 | + } | |
223 | + | |
224 | + _isInit = false; | |
225 | + } | |
226 | + | |
227 | + /* | |
228 | + * @brief Add one record (a pair of one time and a data) | |
229 | + * If the result is false and "full" parameter is true => the packet is full | |
230 | + */ | |
231 | + bool addData(double time, void* data, bool& full) | |
232 | + { | |
233 | + //add a record in the packet | |
234 | + full = false; | |
235 | + | |
236 | + if (!_isInit) | |
237 | + return false; | |
238 | + | |
239 | + full = (_nbData >= _nbMaxData); | |
240 | + if (full) | |
241 | + //cannot add more data in the packet | |
242 | + return false; | |
243 | + | |
244 | + //set data | |
245 | + void *pos = _datas; | |
246 | + int sizeToCopy; | |
247 | + | |
248 | + switch (_paramType) | |
249 | + { | |
250 | + case TYPE_FLOAT : | |
251 | + sizeToCopy = _size * sizeof(float); | |
252 | + break; | |
253 | + case TYPE_DOUBLE : | |
254 | + sizeToCopy = _size * sizeof(double); | |
255 | + break; | |
256 | + case TYPE_SHORT : | |
257 | + sizeToCopy = _size * sizeof(short); | |
258 | + break; | |
259 | + case TYPE_INT : | |
260 | + sizeToCopy = _size * sizeof(int); | |
261 | + break; | |
262 | + default: | |
263 | + return false; | |
264 | + } | |
265 | + pos = (void*)((intptr_t)pos + (_nbData * sizeToCopy)); | |
266 | + | |
267 | + memcpy(pos,data,sizeToCopy); | |
268 | + | |
269 | + //set time | |
270 | + _times[_nbData] = time; | |
271 | + | |
272 | + ++_nbData; | |
273 | + | |
274 | + full = (_nbData >= _nbMaxData); | |
275 | + return true; | |
276 | + } | |
277 | + | |
278 | + /* | |
279 | + * @brief Get number of record contained by the packet | |
280 | + */ | |
281 | + int getNbData(void) | |
282 | + { | |
283 | + if (!_isInit) | |
284 | + return 0; | |
285 | + return _nbData; | |
286 | + } | |
287 | + | |
288 | + /* | |
289 | + * @brief Get one time by record index | |
290 | + */ | |
291 | + double getTime(int index) | |
292 | + { | |
293 | + if (!_isInit) | |
294 | + return 0.; | |
295 | + if (index >= _nbData) | |
296 | + return 0.; | |
297 | + return _times[index]; | |
298 | + } | |
299 | + | |
300 | + /* | |
301 | + * @brief Get the first dimension size. | |
302 | + */ | |
303 | + int getDim1Size(void) | |
304 | + { | |
305 | + if (!_isInit) | |
306 | + return 0; | |
307 | + switch (_containerType) | |
308 | + { | |
309 | + case CONTAINER_VECTOR : | |
310 | + case CONTAINER_MATRIX : | |
311 | + if (_dims != NULL) | |
312 | + return _dims[0]; | |
313 | + break; | |
314 | + default: | |
315 | + return 0; | |
316 | + } | |
317 | + return 0; | |
318 | + } | |
319 | + | |
320 | + /* | |
321 | + * @brief Get the second dimension size. | |
322 | + */ | |
323 | + int getDim2Size(void) | |
324 | + { | |
325 | + if (!_isInit) | |
326 | + return 0; | |
327 | + switch (_containerType) | |
328 | + { | |
329 | + case CONTAINER_MATRIX : | |
330 | + if (_dims != NULL) | |
331 | + return _dims[1]; | |
332 | + break; | |
333 | + default: | |
334 | + return 0; | |
335 | + } | |
336 | + return 0; | |
337 | + } | |
338 | + | |
339 | + /* | |
340 | + * @brief Get the full size of a data of a record | |
341 | + */ | |
342 | + int getDimsSize(void) | |
343 | + { | |
344 | + return _size; | |
345 | + } | |
346 | + | |
347 | + /* | |
348 | + * @brief Get data type for a record | |
349 | + */ | |
350 | + SpeasyProxyParamType getType() | |
351 | + { | |
352 | + return _paramType; | |
353 | + } | |
354 | + | |
355 | + /* | |
356 | + * @brief Get one data value from record with the index "index" | |
357 | + * And from the dimensions indexes | |
358 | + */ | |
359 | + bool getDataValue(void *val, int index, int dim1Index = 0, int dim2Index = 0) | |
360 | + { | |
361 | + if (!_isInit) | |
362 | + return false; | |
363 | + void *pos = NULL; | |
364 | + | |
365 | + int valueSize = 0; | |
366 | + switch (_paramType) | |
367 | + { | |
368 | + case TYPE_FLOAT : | |
369 | + valueSize = sizeof(float); | |
370 | + break; | |
371 | + case TYPE_DOUBLE : | |
372 | + valueSize = sizeof(double); | |
373 | + break; | |
374 | + case TYPE_SHORT : | |
375 | + valueSize = sizeof(short); | |
376 | + break; | |
377 | + case TYPE_INT : | |
378 | + valueSize = sizeof(int); | |
379 | + break; | |
380 | + default: | |
381 | + return false; | |
382 | + } | |
383 | + | |
384 | + switch (_containerType) | |
385 | + { | |
386 | + case CONTAINER_SCALAR : | |
387 | + pos = (void*)((intptr_t)_datas + (valueSize * _size * index)); | |
388 | + break; | |
389 | + case CONTAINER_VECTOR : | |
390 | + pos = (void*)((intptr_t)_datas + (valueSize * _size * index)); | |
391 | + pos = (void*)((intptr_t)pos + (dim1Index * valueSize)); | |
392 | + break; | |
393 | + case CONTAINER_MATRIX : | |
394 | + pos = (void*)((intptr_t)_datas + (valueSize * _size * index)); | |
395 | + pos = (void*)((intptr_t)pos + (dim1Index * _dims[1] * valueSize)); | |
396 | + pos = (void*)((intptr_t)pos + (dim2Index * valueSize)); | |
397 | + break; | |
398 | + default : | |
399 | + return false; | |
400 | + } | |
401 | + memcpy(val,pos,valueSize); | |
402 | + return true; | |
403 | + } | |
404 | + | |
405 | + bool isNoData() { | |
406 | + return _noData; | |
407 | + } | |
408 | + | |
409 | + double getStartTime() { | |
410 | + return _startTime; | |
411 | + } | |
412 | + | |
413 | + double getStopTime() { | |
414 | + return _stopTime; | |
415 | + } | |
416 | + | |
417 | + void setNoData(double startTime, double stopTime) { | |
418 | + _noData = true; | |
419 | + _startTime = startTime; | |
420 | + _stopTime = stopTime; | |
421 | + } | |
422 | + | |
423 | +private: | |
424 | + /* | |
425 | + * @brief Flag to know if the packet is init | |
426 | + */ | |
427 | + bool _isInit; | |
428 | + | |
429 | + /* | |
430 | + * @brief Container type for data of the packet | |
431 | + */ | |
432 | + SpeasyProxyContainerType _containerType; | |
433 | + | |
434 | + /* | |
435 | + * @brief Param type for data of the packet | |
436 | + */ | |
437 | + SpeasyProxyParamType _paramType; | |
438 | + | |
439 | + /* | |
440 | + * @brief Number of record defined in the packet | |
441 | + */ | |
442 | + int _nbData; | |
443 | + | |
444 | + /* | |
445 | + * @brief Maximum number of record that's can be defined in the packet | |
446 | + */ | |
447 | + int _nbMaxData; | |
448 | + | |
449 | + /* | |
450 | + * @brief Dimensions definition | |
451 | + */ | |
452 | + int* _dims; | |
453 | + | |
454 | + /* | |
455 | + * @brief Full size of a data of a record | |
456 | + */ | |
457 | + int _size; | |
458 | + | |
459 | + /* | |
460 | + * @brief times buffer | |
461 | + */ | |
462 | + double* _times; | |
463 | + | |
464 | + /* | |
465 | + * @brief record data buffer | |
466 | + */ | |
467 | + void* _datas; | |
468 | + | |
469 | + bool _noData; | |
470 | + | |
471 | + double _startTime; | |
472 | + | |
473 | + double _stopTime; | |
474 | +}; | |
44 | 475 | |
45 | 476 | } /* SpeasyProxyInterface */ |
46 | 477 | } /* AMDA */ | ... | ... |