Commit a05672161a289f06d8dec86d26e78e213dc5dec6

Authored by Benjamin Renard
1 parent 71f1b8e1
Exists in SpeasyGet

Fix some bugs

src/ParamGetImpl/SpeasyProxyInterface/FileReaderCDF.cc
... ... @@ -195,19 +195,19 @@ bool FileReaderCDF::getParamInfo(std::string& paramId, SpeasyProxyParamType& par
195 195  
196 196 bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo)
197 197 {
198   - if (paramName.empty())
  198 + if (paramName.empty())
199 199 {
200 200 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Empty param name");
201 201 return false;
202 202 }
203 203  
204   - if (paramName.size() >= CDF_VAR_NAME_LEN256)
  204 + if (paramName.size() >= CDF_VAR_NAME_LEN256)
205 205 {
206 206 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Param name too large");
207 207 return false;
208 208 }
209 209  
210   - //reset info structure
  210 + //reset info structure
211 211 memset(&varInfo,0,sizeof(CDFVarInfo));
212 212  
213 213 //confirm variable existence
... ... @@ -216,20 +216,20 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo)
216 216  
217 217 varInfo._num = CDFgetVarNum(_cdfid,varInfo._name);
218 218  
219   - if (varInfo._num < 0)
  219 + if (varInfo._num < 0)
220 220 {
221 221 LOG4CXX_INFO(gLogger, "FileReaderCDF::getCDFVarInfo - Cannot find variable");
222 222 return false;
223 223 }
224 224  
225   - //Is it a zVariable?
  225 + //Is it a zVariable?
226 226 CDFstatus status = CDFconfirmzVarExistence(_cdfid,varInfo._name);
227 227  
228 228 bool isZVar = (status == CDF_OK);
229 229  
230 230 if (isZVar)
231 231 {
232   - //get info about a zVariable
  232 + //get info about a zVariable
233 233 varInfo._type = CDFVT_Z;
234 234  
235 235 status = CDFinquirezVar(_cdfid, varInfo._num, varInfo._name, &varInfo._dataType,
... ... @@ -243,7 +243,7 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo&amp; varInfo)
243 243 }
244 244  
245 245 status = CDFgetzVarMaxWrittenRecNum(_cdfid, varInfo._num, &varInfo._maxRecNum);
246   -
  246 +
247 247 if (status != CDF_OK)
248 248 {
249 249 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFVarInfo - Error to call CDFgetzVarMaxWrittenRecNum");
... ... @@ -260,7 +260,7 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo&amp; varInfo)
260 260 }
261 261 else
262 262 {
263   - //get info about a rVariable
  263 + //get info about a rVariable
264 264 varInfo._type = CDFVT_R;
265 265  
266 266 status = CDFvarInquire(_cdfid, varInfo._num, varInfo._name,
... ... @@ -293,7 +293,7 @@ bool FileReaderCDF::getCDFVarInfo(std::string paramName, CDFVarInfo&amp; varInfo)
293 293 return false;
294 294 }
295 295 }
296   -
  296 +
297 297 return true;
298 298 }
299 299  
... ... @@ -418,6 +418,10 @@ FileReaderStatus FileReaderCDF::getParamPacketData(std::string&amp; timeId, std::str
418 418 nbTimeRec = 1;
419 419 }
420 420  
  421 + if (nbTimeRec == 0) {
  422 + return FRS_EOF;
  423 + }
  424 +
421 425 //get data
422 426 long nbRec;
423 427 long dimSize;
... ... @@ -430,7 +434,7 @@ FileReaderStatus FileReaderCDF::getParamPacketData(std::string&amp; timeId, std::str
430 434 }
431 435  
432 436 //check dimension integrity
433   - if (dimSize != packet->getDimsSize())
  437 + if (dimSize != packet->getDimsSize())
434 438 {
435 439 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getParamPacketData - Incompatibility between dim size of the packet and the CDF var");
436 440 return FRS_ERROR;
... ... @@ -623,7 +627,7 @@ bool FileReaderCDF::getCDFData(std::string&amp; varId, long startRec,
623 627 nbRec = 0;
624 628 dimSize = 0;
625 629 CDFVarInfo varInfo;
626   - if (!getCDFVarInfo(varId, varInfo))
  630 + if (!getCDFVarInfo(varId, varInfo))
627 631 {
628 632 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFData - Cannot get param info " << varId);
629 633 return false;
... ... @@ -632,7 +636,7 @@ bool FileReaderCDF::getCDFData(std::string&amp; varId, long startRec,
632 636 dataType = varInfo._dataType;
633 637 numBytes = varInfo._numBytes;
634 638  
635   - if (varInfo._numElts > 1)
  639 + if (varInfo._numElts > 1)
636 640 {
637 641 //only possible if CDF_CHAR
638 642 //not implemented (CDF_CHAR variable is not a valid variable for the ParamGet)
... ... @@ -640,29 +644,29 @@ bool FileReaderCDF::getCDFData(std::string&amp; varId, long startRec,
640 644 return false;
641 645 }
642 646  
643   - if ((varInfo._maxRecNum <= 0) && (varInfo._recVary != 0))
  647 + if ((varInfo._maxRecNum < 0) && (varInfo._recVary != 0))
644 648 //no record in file
645 649 return true;
646 650  
647   - nbRec = varInfo._maxRecNum - startRec + 1;
  651 + nbRec = varInfo._maxRecNum - startRec + 1;
648 652  
649 653 dimSize = 1;
650 654 if (varInfo._numDims > 0)
651 655 for (int i = 0; i < varInfo._numDims; ++i)
652 656 dimSize *= varInfo._dimSizes[i];
653 657  
654   - _workingBuffers->reallocBuffer(bufferType, nbRec*varInfo._numBytes*dimSize);
  658 + _workingBuffers->reallocBuffer(bufferType, nbRec*varInfo._numBytes*dimSize);
655 659  
656 660 CDFstatus status = CDFgetVarRangeRecordsByVarName(_cdfid, varInfo._name, startRec,
657 661 varInfo._maxRecNum, _workingBuffers->getBuffer(bufferType));
658 662  
659   - if (status != CDF_OK)
  663 + if (status != CDF_OK)
660 664 {
661 665 LOG4CXX_ERROR(gLogger, "FileReaderCDF::getCDFData - Error to get data for " << varId);
662 666 return false;
663 667 }
664 668  
665   - return true;
  669 + return true;
666 670 }
667 671  
668 672 bool FileReaderCDF::extractShort(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize,
... ... @@ -743,7 +747,7 @@ bool FileReaderCDF::extractFloat(CDFWorkingBuffers::BufferType bufferType, long
743 747 {
744 748 //try to extract an int
745 749 int i;
746   - if (extractInt(bufferType, recIndex, dimIndex, dimSize,
  750 + if (extractInt(bufferType, recIndex, dimIndex, dimSize,
747 751 dataType, numBytes, i))
748 752 {
749 753 //cast int to float
... ... @@ -850,8 +854,8 @@ bool FileReaderCDF::getInfo(const char* pInfoName, std::vector&lt;double&gt;&amp; res)
850 854  
851 855 //get CDF var info
852 856 CDFVarInfo varInfo;
853   - if (getCDFVarInfo(pInfoName, varInfo)) {
854   - scoped_lock.unlock();
  857 + if (getCDFVarInfo(pInfoName, varInfo)) {
  858 + scoped_lock.unlock();
855 859 std::string emptyTimeStr = "";
856 860 std::string paramName = pInfoName;
857 861 SpeasyProxyParamType paramType;
... ... @@ -868,7 +872,7 @@ bool FileReaderCDF::getInfo(const char* pInfoName, std::vector&lt;double&gt;&amp; res)
868 872  
869 873 packet.init(containerType,paramType,dim1Size,dim2Size);
870 874 getParamPacketData(emptyTimeStr, paramName, 0, &packet);
871   - if (packet.getNbData() > 0) {
  875 + if (packet.getNbData() > 0) {
872 876 for (int i = 0; i < dim1Size; ++i) {
873 877 for (int j = 0; j < dim2Size; ++j) {
874 878 switch (paramType)
... ... @@ -910,7 +914,7 @@ bool FileReaderCDF::getInfo(const char* pInfoName, std::vector&lt;double&gt;&amp; res)
910 914 return true;
911 915 }
912 916 }
913   -
  917 +
914 918 return false;
915 919 }
916 920  
... ...
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc
... ... @@ -28,6 +28,7 @@
28 28 #include <curl/curl.h>
29 29 #include <curl/easy.h>
30 30 #include <cstdio>
  31 +#include <boost/filesystem.hpp>
31 32  
32 33 namespace AMDA {
33 34  
... ... @@ -296,7 +297,6 @@ unsigned int ParamGetSpeasyProxy::write()
296 297 bool isOpen = fileReaderPtr->open(localPath);
297 298  
298 299  
299   -
300 300 if(isOpen)
301 301 {
302 302 // Call to getParamPacketData to get CDF data
... ... @@ -311,13 +311,24 @@ unsigned int ParamGetSpeasyProxy::write()
311 311 status = fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, crtIndex, packet);
312 312 if (status == FRS_ERROR) {
313 313 delete packet;
  314 + remove(localPath.c_str());
314 315 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to get data from speasy"));
315 316 }
316   - crtIndex += packet->getNbData();
317   - // Call to the put function of pusher to initiate the ParamData
318   - // result == nb of data in ParamData
319   - result += _pusher->put(packet);
  317 + if (packet->getNbData() == 0) {
  318 + LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => no data packet");
  319 + _paramData->getTimeList().push_back(_currentInterval->_startTime);
  320 + _pusher->putNaN();
  321 + _paramData->getTimeList().push_back(_currentInterval->_stopTime);
  322 + _pusher->putNaN();
  323 + result += 2;
  324 + }
  325 + else {
  326 + LOG4CXX_DEBUG(gLogger, "ParamGetLocalFile::write => nb data in packet: " << packet->getNbData());
  327 + crtIndex += packet->getNbData();
  328 + result += _pusher->put(packet);
  329 + }
320 330 delete packet;
  331 + //remove(localPath.c_str());
321 332 } while (status == FRS_MORE);
322 333  
323 334  
... ... @@ -339,11 +350,11 @@ unsigned int ParamGetSpeasyProxy::write()
339 350 else {
340 351 // Nothing to do.
341 352 }
342   - // if (result != 0)
343   - // remove(localPath.c_str());
344 353 return result;
345 354 }
346 355 else {
  356 + if (boost::filesystem::exists(localPath))
  357 + remove(localPath.c_str());
347 358 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::ex_msg("Error to get data from speasy"));
348 359 }
349 360  
... ... @@ -367,6 +378,8 @@ void ParamGetSpeasyProxy::updateInfo(Parameter &amp; parameter)
367 378  
368 379 if (paramInfo == nullptr)
369 380 return;
  381 +
  382 + _pusher->setFillValue(paramInfo->getFillValue());
370 383 }
371 384  
372 385 size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
... ...
src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh
... ... @@ -29,7 +29,7 @@ public:
29 29 /*
30 30 * @brief Constructor
31 31 */
32   - PusherBase (int dim1 = 1, int dim2 = 1) : _paramData(NULL), _dim1(dim1), _dim2(dim2)
  32 + PusherBase (int dim1 = 1, int dim2 = 1) : _paramData(NULL), _dim1(dim1), _dim2(dim2), _fillValue(NAN)
33 33 {
34 34 }
35 35  
... ... @@ -48,11 +48,20 @@ public:
48 48 return _paramData;
49 49 }
50 50  
  51 + void setFillValue(double fillValue) {
  52 + _fillValue = fillValue;
  53 + }
  54 +
51 55 /*
52 56 * @brief Virtual method to put a packet in the ParamData
53 57 */
54 58 virtual int put(SpeasyProxyParamDataPacket* packet) = 0;
55 59  
  60 + /*
  61 + * @brief Virtual method to put a NAN in the ParamData
  62 + */
  63 + virtual void putNaN() = 0;
  64 +
56 65 protected:
57 66 /*
58 67 * @brief Pointer to the paramData
... ... @@ -73,6 +82,11 @@ protected:
73 82 * @brief Nb data returned by one packet
74 83 */
75 84 // int _nbDataByPacket;
  85 +
  86 + /*
  87 + * @brief Fill value
  88 + */
  89 + double _fillValue;
76 90 };
77 91  
78 92  
... ... @@ -122,7 +136,7 @@ public:
122 136  
123 137 _specParamData->getDataList().resize(packet->getNbData());
124 138  
125   - // BaseElemenType fillEl = _fillValue;
  139 + BaseElemenType fillEl = _fillValue;
126 140  
127 141 for (int index = 0; index < packet->getNbData(); ++index)
128 142 {
... ... @@ -138,9 +152,9 @@ public:
138 152 //get data element
139 153 if (packet->getDataValue(&baseElem,index,dim1Index,dim2Index))
140 154 {
141   - // if (!isnan(_fillValue))
142   - // if (baseElem == fillEl)
143   - // baseElem << NotANumber();
  155 + if (!isnan(_fillValue))
  156 + if (baseElem == fillEl)
  157 + baseElem << NotANumber();
144 158 }
145 159 else
146 160 baseElem << NotANumber();
... ... @@ -159,6 +173,17 @@ public:
159 173 return 0;
160 174 }
161 175  
  176 + virtual void putNaN() {
  177 + _specParamData->getDataList().resize(1);
  178 + ElemenType nanElem = ElemenType(_dim1,_dim2);
  179 + for(int i = 0; i < _dim1; ++i) {
  180 + for(int j = 0; j < _dim2; ++j) {
  181 + nanElem[i][j] << NotANumber();
  182 + }
  183 + }
  184 + _specParamData->getDataList().push_back(nanElem);
  185 + }
  186 +
162 187 /*
163 188 * @brief ParamData creation
164 189 */
... ... @@ -201,7 +226,7 @@ public:
201 226 //ParamData is created, add data
202 227 _specParamData->getDataList().resize(packet->getNbData());
203 228  
204   - //BaseElemenType fillEl = _fillValue;
  229 + BaseElemenType fillEl = _fillValue;
205 230  
206 231 for (int index = 0; index < packet->getNbData(); ++index)
207 232 {
... ... @@ -215,9 +240,9 @@ public:
215 240 //get data element
216 241 if (packet->getDataValue(&baseElem,index,dimIndex))
217 242 {
218   - // if (!isnan(_fillValue))
219   - // if (baseElem == fillEl)
220   - // baseElem << NotANumber();
  243 + if (!isnan(_fillValue))
  244 + if (baseElem == fillEl)
  245 + baseElem << NotANumber();
221 246 }
222 247 else
223 248 baseElem << NotANumber();
... ... @@ -234,6 +259,14 @@ public:
234 259 return packet->getNbData();
235 260 }
236 261  
  262 + virtual void putNaN() {
  263 + _specParamData->getDataList().resize(1);
  264 + ElemenType nanElem = ElemenType();
  265 + nanElem.resize(_dim1);
  266 + nanElem << NotANumber();
  267 + _specParamData->getDataList().push_back(nanElem);
  268 + }
  269 +
237 270 /*
238 271 * @brief ParamData creation
239 272 */
... ... @@ -275,7 +308,7 @@ public:
275 308 //ParamData is created, add data
276 309 _specParamData->getDataList().resize(packet->getNbData());
277 310  
278   - // BaseElemenType fillEl = _fillValue;
  311 + BaseElemenType fillEl = _fillValue;
279 312  
280 313 for (int index = 0; index < packet->getNbData(); ++index)
281 314 {
... ... @@ -286,11 +319,11 @@ public:
286 319 //get element
287 320 if (packet->getDataValue(&baseElem,index))
288 321 {
289   - // if (!isnan(_fillValue))
290   - // {
291   - // if (baseElem == fillEl)
292   - // baseElem << NotANumber();
293   - // }
  322 + if (!isnan(_fillValue))
  323 + {
  324 + if (baseElem == fillEl)
  325 + baseElem << NotANumber();
  326 + }
294 327 }
295 328 else
296 329 baseElem << NotANumber();
... ... @@ -303,6 +336,13 @@ public:
303 336 return packet->getNbData();
304 337 }
305 338  
  339 + virtual void putNaN() {
  340 + BaseElemenType valNaN;
  341 + valNaN << NotANumber();
  342 + _specParamData->getDataList().resize(1);
  343 + _specParamData->getDataList().push_back(valNaN);
  344 + }
  345 +
306 346 SpecParamData* createParamData() {
307 347 return new SpecParamData();
308 348 }
... ...
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyInterfaceConfig.cc
... ... @@ -10,6 +10,5 @@ namespace AMDA {
10 10 namespace SpeasyProxyInterface {
11 11  
12 12 log4cxx::LoggerPtr gLogger = log4cxx::Logger::getLogger("AMDA-Kernel.SpeasyProxyInterface");
13   -std::string speasy_proxy_url = "http://127.0.0.1:6543";
14 13 } // namespace SpeasyProxyInterface
15 14 } /* namespace AMDA */
... ...