Commit 3ff2d2289e50177f0ebef29700398a9cb3b8e427

Authored by Benjamin Renard
1 parent c4f6b4d4

Fix bug in sampling under ref param (cf. #9602)

src/InternLib/ProcessSamplingUnderRefParam.cc
... ... @@ -73,8 +73,9 @@ TimeStamp ProcessSamplingUnderRefParam::init() {
73 73  
74 74 // ProcessSamplingClassic _operation creation
75 75 Resampling::CreateResampling lCreateResampling(*this, _timeIntervalList,
76   - *_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue());
  76 + *_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue(), _refParameterSPtr == _parameterInput);
77 77 _operation = lCreateResampling.getResampling();
  78 +
78 79 static_cast<Resampling::ResamplingAbstract*>(_operation)->init();
79 80  
80 81 /// Get result ParamData
... ... @@ -87,27 +88,25 @@ TimeStamp ProcessSamplingUnderRefParam::init() {
87 88  
88 89 unsigned int ProcessSamplingUnderRefParam::write()
89 90 {
90   - if ((_refParameterSPtr != _parameterInput) && static_cast<Resampling::ResamplingAbstract*>(_operation)->isNewInt()) {
91   - _paramRefInput = _refParameterSPtr->getParamData(this).get();
92   - ParamDataIndexInfo lRefParamDataIndexInfo;
93   - do {
94   - lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get();
95   - for (unsigned int index = lRefParamDataIndexInfo._startIndex; index < lRefParamDataIndexInfo._startIndex + lRefParamDataIndexInfo._nbDataToProcess; index++) {
96   - static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index));
97   - }
98   - } while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt);
99   - }
100   -
101 91 int ret = 0;
102 92 unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber();
103   - ParamDataIndexInfo lParamDataIndexInfo = _parameterInput->getAsync(this).get();
104 93  
105   - if ((_refParameterSPtr == _parameterInput)) {
106   - for (unsigned int index = lParamDataIndexInfo._startIndex; index < lParamDataIndexInfo._startIndex + lParamDataIndexInfo._nbDataToProcess; index++) {
107   - static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index));
  94 + ParamDataIndexInfo lParamDataIndexInfo;
  95 + if (_refParameterSPtr != _parameterInput) {
  96 + if (static_cast<Resampling::ResamplingAbstract*>(_operation)->isNewInt()) {
  97 + _paramRefInput = _refParameterSPtr->getParamData(this).get();
  98 + ParamDataIndexInfo lRefParamDataIndexInfo;
  99 + do {
  100 + lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get();
  101 + for (unsigned int index = lRefParamDataIndexInfo._startIndex; index < lRefParamDataIndexInfo._startIndex + lRefParamDataIndexInfo._nbDataToProcess; index++) {
  102 + static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index));
  103 + }
  104 + } while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt);
108 105 }
109 106 }
110 107  
  108 + lParamDataIndexInfo = _parameterInput->getAsync(this).get();
  109 +
111 110 _operation->write(lParamDataIndexInfo);
112 111 ret = _paramData->getDataNumber() - nbDataBeforeCallProcess;
113 112  
... ...
src/InternLib/Resampling.hh
... ... @@ -227,13 +227,13 @@ public:
227 227 /**
228 228 * @brief Constructor
229 229 */
230   - ResamplingSimpleAbstract(Process& pProcess, MarkerAbstract* pMarkerPtr, TimeIntervalListSPtr pTimeIntervalList, double gapSize, TParamData &param, bool pUseNearestValue) :
  230 + ResamplingSimpleAbstract(Process& pProcess, MarkerAbstract* pMarkerPtr, TimeIntervalListSPtr pTimeIntervalList, double gapSize, TParamData &param, bool pUseNearestValue, bool pSameParam = false) :
231 231 ResamplingAbstract(pProcess, pUseNearestValue),
232 232 _markerPtr(pMarkerPtr),
233 233 _timeIntervalList(pTimeIntervalList),
234 234 _currentTimeInterval(_timeIntervalList->begin()), _currentTimeIntervalIndex(0), _samplingMode(INTERPOLATION), _nearestTime(NAN), _lastTime(0),
235 235 _leftEffect(true), _paramOutput(new TParamData()), _paramInput(param),
236   - _gapSize(gapSize) {
  236 + _gapSize(gapSize), _sameParam(pSameParam) {
237 237 _paramDataOutput = _paramOutput;
238 238 }
239 239  
... ... @@ -253,7 +253,7 @@ public:
253 253 * @overload ResamplingAbstract::ResamplingAbstract::write()
254 254 */
255 255 void write(ParamDataIndexInfo &pParamDataIndexInfo) {
256   - if (_isNewInt)
  256 + if (_isNewInt && !_sameParam)
257 257 {
258 258 _markerPtr->init((*_currentTimeInterval)._startTime, (*_currentTimeInterval)._stopTime, _currentTimeIntervalIndex, getSampling());
259 259 _isNewInt = false;
... ... @@ -280,6 +280,9 @@ public:
280 280 case INTERPOLATION :
281 281 writeInterpolation(pParamDataIndexInfo);
282 282 break;
  283 + case SAMEPARAM :
  284 + writeSameParam(pParamDataIndexInfo);
  285 + break;
283 286 }
284 287 }
285 288 if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
... ... @@ -291,6 +294,10 @@ public:
291 294 * @brief compute and write last value, right effect
292 295 */
293 296 virtual void terminated() {
  297 + if (_sameParam) {
  298 + return;
  299 + }
  300 +
294 301 if (_markerPtr->isFinished()) {
295 302 return;
296 303 }
... ... @@ -322,6 +329,20 @@ public:
322 329  
323 330 } while(_markerPtr->nextTarget());
324 331 break;
  332 + case SAMEPARAM :
  333 + //Nothing to do
  334 + break;
  335 + }
  336 + }
  337 +
  338 + void writeSameParam(ParamDataIndexInfo &pParamDataIndexInfo)
  339 + {
  340 + for (unsigned int index = pParamDataIndexInfo._startIndex;
  341 + index < pParamDataIndexInfo._startIndex
  342 + + pParamDataIndexInfo._nbDataToProcess; index++)
  343 + {
  344 + _paramOutput->pushTime(_paramInput.getTime(index));
  345 + _paramOutput->push(_paramInput.get(index));
325 346 }
326 347 }
327 348  
... ... @@ -492,7 +513,11 @@ public:
492 513 */
493 514 virtual void init() {
494 515 //Compute Sampling mode
495   - if (_useNearestValue)
  516 + if (_sameParam)
  517 + {
  518 + _samplingMode = SAMEPARAM;
  519 + }
  520 + else if (_useNearestValue)
496 521 {
497 522 _samplingMode = NEARESTVALUE;
498 523 _nearestValue = ElementType();
... ... @@ -537,7 +562,7 @@ public:
537 562 * @brief sampling mode
538 563 */
539 564 enum SamplingMode {
540   - INTERPOLATION, AVERAGE, NEARESTVALUE
  565 + INTERPOLATION, AVERAGE, NEARESTVALUE, SAMEPARAM
541 566 };
542 567  
543 568 private:
... ... @@ -603,6 +628,8 @@ private:
603 628 * @brief gap size for input data
604 629 */
605 630 double _gapSize;
  631 +
  632 + bool _sameParam;
606 633 }
607 634 ;
608 635  
... ... @@ -654,9 +681,9 @@ public:
654 681 * @brief Constructor
655 682 */
656 683 ResamplingWithRefParam(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
657   - TParamData &param, ParamData &refParamData, double gapSize, bool pUseNearestValue) :
  684 + TParamData &param, ParamData &refParamData, double gapSize, bool pUseNearestValue, bool pSameParam) :
658 685 ResamplingSimpleAbstract<TParamData>(pProcess, &_marker, pTimeIntervalList,
659   - gapSize, param, pUseNearestValue), _refParamData(refParamData) {
  686 + gapSize, param, pUseNearestValue, pSameParam), _refParamData(refParamData) {
660 687 _marker.setRefParamData(&refParamData);
661 688 }
662 689  
... ... @@ -698,7 +725,7 @@ public:
698 725 _type(ResamplingType::RT_WITHSAMPLINGTIME),
699 726 _process(pProcess), _paramData(paramData), _resampling(NULL), _timeIntervalList(
700 727 pTimeIntervalList), _sampling(sampling), _gapSize(
701   - gapSize), _refParamData(paramData), _useNearestValue(useNearestValue) {
  728 + gapSize), _refParamData(paramData), _useNearestValue(useNearestValue), _sameParam(false) {
702 729 _paramData.accept(*this);
703 730 }
704 731  
... ... @@ -706,11 +733,11 @@ public:
706 733 * @brief constructor
707 734 */
708 735 CreateResampling(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
709   - ParamData &paramData, ParamData& refParamData, double gapSize, bool useNearestValue) :
  736 + ParamData &paramData, ParamData& refParamData, double gapSize, bool useNearestValue, bool sameParam = false) :
710 737 _type(ResamplingType::RT_WITHREFTIMELIST),
711 738 _process(pProcess), _paramData(paramData), _resampling(NULL), _timeIntervalList(
712 739 pTimeIntervalList), _sampling(0.), _gapSize(
713   - gapSize),_refParamData(refParamData), _useNearestValue(useNearestValue) {
  740 + gapSize),_refParamData(refParamData), _useNearestValue(useNearestValue), _sameParam(sameParam) {
714 741 _paramData.accept(*this);
715 742 }
716 743  
... ... @@ -730,7 +757,7 @@ public:
730 757 _timeIntervalList,
731 758 dynamic_cast<ParamDataScalaireShort &>(_paramData),
732 759 _refParamData,
733   - _gapSize, _useNearestValue);
  760 + _gapSize, _useNearestValue, _sameParam);
734 761 break;
735 762 }
736 763 }
... ... @@ -751,7 +778,7 @@ public:
751 778 _timeIntervalList,
752 779 dynamic_cast<ParamDataScalaireFloat &>(_paramData),
753 780 _refParamData,
754   - _gapSize, _useNearestValue);
  781 + _gapSize, _useNearestValue, _sameParam);
755 782 break;
756 783 }
757 784 }
... ... @@ -772,7 +799,7 @@ public:
772 799 _timeIntervalList,
773 800 dynamic_cast<ParamDataScalaireDouble &>(_paramData),
774 801 _refParamData,
775   - _gapSize, _useNearestValue);
  802 + _gapSize, _useNearestValue, _sameParam);
776 803 break;
777 804 }
778 805 }
... ... @@ -793,7 +820,7 @@ public:
793 820 _timeIntervalList,
794 821 dynamic_cast<ParamDataScalaireLongDouble &>(_paramData),
795 822 _refParamData,
796   - _gapSize, _useNearestValue);
  823 + _gapSize, _useNearestValue, _sameParam);
797 824 break;
798 825 }
799 826 }
... ... @@ -814,7 +841,7 @@ public:
814 841 _timeIntervalList,
815 842 dynamic_cast<ParamDataScalaireInt &>(_paramData),
816 843 _refParamData,
817   - _gapSize, _useNearestValue);
  844 + _gapSize, _useNearestValue, _sameParam);
818 845 break;
819 846 }
820 847 }
... ... @@ -837,7 +864,7 @@ public:
837 864 _timeIntervalList,
838 865 dynamic_cast<ParamDataLogicalData &>(_paramData),
839 866 _refParamData,
840   - _gapSize, true);
  867 + _gapSize, true, _sameParam);
841 868 break;
842 869 }
843 870 }
... ... @@ -858,7 +885,7 @@ public:
858 885 _timeIntervalList,
859 886 dynamic_cast<ParamDataTab1DShort &>(_paramData),
860 887 _refParamData,
861   - _gapSize, _useNearestValue);
  888 + _gapSize, _useNearestValue, _sameParam);
862 889 break;
863 890 }
864 891 }
... ... @@ -879,7 +906,7 @@ public:
879 906 _timeIntervalList,
880 907 dynamic_cast<ParamDataTab1DFloat &>(_paramData),
881 908 _refParamData,
882   - _gapSize, _useNearestValue);
  909 + _gapSize, _useNearestValue, _sameParam);
883 910 break;
884 911 }
885 912 }
... ... @@ -900,7 +927,7 @@ public:
900 927 _timeIntervalList,
901 928 dynamic_cast<ParamDataTab1DDouble &>(_paramData),
902 929 _refParamData,
903   - _gapSize, _useNearestValue);
  930 + _gapSize, _useNearestValue, _sameParam);
904 931 break;
905 932 }
906 933 }
... ... @@ -921,7 +948,7 @@ public:
921 948 _timeIntervalList,
922 949 dynamic_cast<ParamDataTab1DLongDouble &>(_paramData),
923 950 _refParamData,
924   - _gapSize, _useNearestValue);
  951 + _gapSize, _useNearestValue, _sameParam);
925 952 break;
926 953 }
927 954 }
... ... @@ -942,7 +969,7 @@ public:
942 969 _timeIntervalList,
943 970 dynamic_cast<ParamDataTab1DInt &>(_paramData),
944 971 _refParamData,
945   - _gapSize, _useNearestValue);
  972 + _gapSize, _useNearestValue, _sameParam);
946 973 break;
947 974 }
948 975 }
... ... @@ -965,7 +992,7 @@ public:
965 992 _timeIntervalList,
966 993 dynamic_cast<ParamDataTab1DLogicalData &>(_paramData),
967 994 _refParamData,
968   - _gapSize, true);
  995 + _gapSize, true, _sameParam);
969 996 break;
970 997 }
971 998 }
... ... @@ -986,7 +1013,7 @@ public:
986 1013 _timeIntervalList,
987 1014 dynamic_cast<ParamDataTab2DShort &>(_paramData),
988 1015 _refParamData,
989   - _gapSize, _useNearestValue);
  1016 + _gapSize, _useNearestValue, _sameParam);
990 1017 break;
991 1018 }
992 1019 }
... ... @@ -1007,7 +1034,7 @@ public:
1007 1034 _timeIntervalList,
1008 1035 dynamic_cast<ParamDataTab2DFloat &>(_paramData),
1009 1036 _refParamData,
1010   - _gapSize, _useNearestValue);
  1037 + _gapSize, _useNearestValue, _sameParam);
1011 1038 break;
1012 1039 }
1013 1040 }
... ... @@ -1028,7 +1055,7 @@ public:
1028 1055 _timeIntervalList,
1029 1056 dynamic_cast<ParamDataTab2DDouble &>(_paramData),
1030 1057 _refParamData,
1031   - _gapSize, _useNearestValue);
  1058 + _gapSize, _useNearestValue, _sameParam);
1032 1059 break;
1033 1060 }
1034 1061 }
... ... @@ -1049,7 +1076,7 @@ public:
1049 1076 _timeIntervalList,
1050 1077 dynamic_cast<ParamDataTab2DLongDouble &>(_paramData),
1051 1078 _refParamData,
1052   - _gapSize, _useNearestValue);
  1079 + _gapSize, _useNearestValue, _sameParam);
1053 1080 break;
1054 1081 }
1055 1082 }
... ... @@ -1070,7 +1097,7 @@ public:
1070 1097 _timeIntervalList,
1071 1098 dynamic_cast<ParamDataTab2DInt &>(_paramData),
1072 1099 _refParamData,
1073   - _gapSize, _useNearestValue);
  1100 + _gapSize, _useNearestValue, _sameParam);
1074 1101 break;
1075 1102 }
1076 1103 }
... ... @@ -1093,7 +1120,7 @@ public:
1093 1120 _timeIntervalList,
1094 1121 dynamic_cast<ParamDataTab2DLogicalData &>(_paramData),
1095 1122 _refParamData,
1096   - _gapSize, true);
  1123 + _gapSize, true, _sameParam);
1097 1124 break;
1098 1125 }
1099 1126 }
... ... @@ -1114,6 +1141,7 @@ private:
1114 1141 double _gapSize;
1115 1142 ParamData& _refParamData;
1116 1143 bool _useNearestValue;
  1144 + bool _sameParam;
1117 1145 };
1118 1146  
1119 1147 } /* Resampling */
... ...