Commit d1d8375e68fd7721c0ddf85a11c601c18f82a3f2

Authored by Benjamin Renard
1 parent 55abc789

Fix a bug with sampling under reference parameter and sliding average

src/ExternLib/SlidingAverage/SlidingAverageProcess.cc
@@ -51,17 +51,25 @@ TimeStamp SlidingAverageProcess::init() { @@ -51,17 +51,25 @@ TimeStamp SlidingAverageProcess::init() {
51 if (_SlidingAverageTime <= 0) { 51 if (_SlidingAverageTime <= 0) {
52 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("Sliding Average Time must be greater than 0."))); 52 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("Sliding Average Time must be greater than 0.")));
53 } 53 }
54 -  
55 - TimeIntervalListSPtr lTimeIntervalList(new TimeIntervalList()); 54 +
  55 + TimeIntervalListSPtr lTimeIntervalList(new TimeIntervalList());
56 56
57 // Add shift time for each time interval 57 // Add shift time for each time interval
58 for (TimeIntervalList::iterator it = _timeIntervalList->begin(); it != _timeIntervalList->end(); ++it) { 58 for (TimeIntervalList::iterator it = _timeIntervalList->begin(); it != _timeIntervalList->end(); ++it) {
59 - lTimeIntervalList->push_back(TimeInterval( (*it)._startTime - _SlidingAverageTime/2., (*it)._stopTime + _SlidingAverageTime/2.)); 59 + if ((*it)._startTime - _SlidingAverageTime/2. > 0) {
  60 + lTimeIntervalList->push_back(TimeInterval( (*it)._startTime - _SlidingAverageTime/2., (*it)._stopTime + _SlidingAverageTime/2.));
  61 + }
  62 + else {
  63 + lTimeIntervalList->push_back(TimeInterval( 0, (*it)._stopTime + _SlidingAverageTime/2.));
  64 + }
60 } 65 }
61 66
62 TimeStamp timeStamp = _parameterInput->init( this, lTimeIntervalList); 67 TimeStamp timeStamp = _parameterInput->init( this, lTimeIntervalList);
  68 +
63 Parameter::InfoList lInfoList = _parameterInput->getInfoList(); 69 Parameter::InfoList lInfoList = _parameterInput->getInfoList();
  70 +
64 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end()); 71 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
  72 +
65 _paramInput = _parameterInput->getParamData(this).get(); 73 _paramInput = _parameterInput->getParamData(this).get();
66 74
67 SlidingAverageCreator lSlidingAverageCreator(*this,*_paramInput,_timeIntervalList,_SlidingAverageTime); 75 SlidingAverageCreator lSlidingAverageCreator(*this,*_paramInput,_timeIntervalList,_SlidingAverageTime);
src/InternLib/ProcessSamplingUnderRefParam.cc
@@ -27,6 +27,7 @@ ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(Parameter &amp;parameter) @@ -27,6 +27,7 @@ ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(Parameter &amp;parameter)
27 27
28 ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(const ProcessSamplingUnderRefParam& pProcess, Parameter &parameter) 28 ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(const ProcessSamplingUnderRefParam& pProcess, Parameter &parameter)
29 : SingleParamProcess_CRTP(pProcess,parameter), _paramRefInput(pProcess._paramRefInput) { 29 : SingleParamProcess_CRTP(pProcess,parameter), _paramRefInput(pProcess._paramRefInput) {
  30 + establishConnection();
30 } 31 }
31 32
32 ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() { 33 ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() {
@@ -38,47 +39,50 @@ ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() { @@ -38,47 +39,50 @@ ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() {
38 39
39 40
40 void ProcessSamplingUnderRefParam::establishConnection() { 41 void ProcessSamplingUnderRefParam::establishConnection() {
41 - if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {  
42 - _refParameterSPtr->openConnection(this); 42 + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
  43 + _refParameterSPtr->openConnection(this);
43 } 44 }
44 45
45 SingleParamProcess_CRTP::establishConnection(); 46 SingleParamProcess_CRTP::establishConnection();
46 - 47 +
47 if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) { 48 if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) {
48 _refParameterSPtr = _parameterInput->getParameterManager().getParameter(_attributList[0]); 49 _refParameterSPtr = _parameterInput->getParameterManager().getParameter(_attributList[0]);
49 - if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {  
50 - _refParameterSPtr->openConnection(this); 50 + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
  51 + _refParameterSPtr->openConnection(this);
51 } 52 }
52 } 53 }
53 } 54 }
54 55
55 TimeStamp ProcessSamplingUnderRefParam::init() { 56 TimeStamp ProcessSamplingUnderRefParam::init() {
56 - /// Init input parameter 57 + /// Init input parameter
57 TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList); 58 TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList);
58 - /// Calibration information copy 59 +
  60 + /// Calibration information copy
59 Parameter::InfoList lInfoList = _parameterInput->getInfoList(); 61 Parameter::InfoList lInfoList = _parameterInput->getInfoList();
60 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end()); 62 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
61 _paramInput = _parameterInput->getParamData(this).get(); 63 _paramInput = _parameterInput->getParamData(this).get();
62 - 64 +
63 // check reference parameter 65 // check reference parameter
64 if (_refParameterSPtr == nullptr) { 66 if (_refParameterSPtr == nullptr) {
65 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSamplingUnderRefParam : cannot retrieve reference parameter "))); 67 BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(std::string("ProcessSamplingUnderRefParam : cannot retrieve reference parameter ")));
66 } 68 }
67 69
68 - timeStamp = std::max(timeStamp, _refParameterSPtr->init( this, _timeIntervalList));  
69 - 70 + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) {
  71 + timeStamp = std::max(timeStamp, _refParameterSPtr->init( this, _timeIntervalList));
  72 + }
  73 +
70 _paramRefInput = _refParameterSPtr->getParamData(this).get(); 74 _paramRefInput = _refParameterSPtr->getParamData(this).get();
71 75
72 double computedGapSize = _refParameterSPtr->getParameterManager().getComputedGapSize(_parameterInput->getGapThreshold(), _paramInput->getMinSampling()); 76 double computedGapSize = _refParameterSPtr->getParameterManager().getComputedGapSize(_parameterInput->getGapThreshold(), _paramInput->getMinSampling());
73 //_parameter.setGapThreshold(computedGapSize/_paramRefInput->getMinSampling()); 77 //_parameter.setGapThreshold(computedGapSize/_paramRefInput->getMinSampling());
74 - 78 +
75 // ProcessSamplingClassic _operation creation 79 // ProcessSamplingClassic _operation creation
76 Resampling::CreateResampling lCreateResampling(*this, _timeIntervalList, 80 Resampling::CreateResampling lCreateResampling(*this, _timeIntervalList,
77 *_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue(), _refParameterSPtr == _parameterInput); 81 *_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue(), _refParameterSPtr == _parameterInput);
78 _operation = lCreateResampling.getResampling(); 82 _operation = lCreateResampling.getResampling();
79 83
80 static_cast<Resampling::ResamplingAbstract*>(_operation)->init(); 84 static_cast<Resampling::ResamplingAbstract*>(_operation)->init();
81 - 85 +
82 /// Get result ParamData 86 /// Get result ParamData
83 _paramData = ParamDataSPtr(_operation->getParamOutput()); 87 _paramData = ParamDataSPtr(_operation->getParamOutput());
84 88
@@ -168,7 +172,7 @@ void ProcessSamplingUnderRefParam::updateInfo(Parameter &amp; parameter) @@ -168,7 +172,7 @@ void ProcessSamplingUnderRefParam::updateInfo(Parameter &amp; parameter)
168 processInfo += _refParameterSPtr->getId(); 172 processInfo += _refParameterSPtr->getId();
169 processInfo += "'"; 173 processInfo += "'";
170 174
171 - if (_parameterInput->getDataWriterTemplate()->useNearestValue()) 175 + if (_parameterInput->getDataWriterTemplate()->useNearestValue())
172 processInfo += ". Use nearest value."; 176 processInfo += ". Use nearest value.";
173 177
174 paramInfo->setProcessInfo(processInfo); 178 paramInfo->setProcessInfo(processInfo);