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 51 if (_SlidingAverageTime <= 0) {
52 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 57 // Add shift time for each time interval
58 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 67 TimeStamp timeStamp = _parameterInput->init( this, lTimeIntervalList);
  68 +
63 69 Parameter::InfoList lInfoList = _parameterInput->getInfoList();
  70 +
64 71 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
  72 +
65 73 _paramInput = _parameterInput->getParamData(this).get();
66 74  
67 75 SlidingAverageCreator lSlidingAverageCreator(*this,*_paramInput,_timeIntervalList,_SlidingAverageTime);
... ...
src/InternLib/ProcessSamplingUnderRefParam.cc
... ... @@ -27,6 +27,7 @@ ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(Parameter &amp;parameter)
27 27  
28 28 ProcessSamplingUnderRefParam::ProcessSamplingUnderRefParam(const ProcessSamplingUnderRefParam& pProcess, Parameter &parameter)
29 29 : SingleParamProcess_CRTP(pProcess,parameter), _paramRefInput(pProcess._paramRefInput) {
  30 + establishConnection();
30 31 }
31 32  
32 33 ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() {
... ... @@ -38,47 +39,50 @@ ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() {
38 39  
39 40  
40 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 46 SingleParamProcess_CRTP::establishConnection();
46   -
  47 +
47 48 if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) {
48 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 56 TimeStamp ProcessSamplingUnderRefParam::init() {
56   - /// Init input parameter
  57 + /// Init input parameter
57 58 TimeStamp timeStamp = _parameterInput->init( this, _timeIntervalList);
58   - /// Calibration information copy
  59 +
  60 + /// Calibration information copy
59 61 Parameter::InfoList lInfoList = _parameterInput->getInfoList();
60 62 _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end());
61 63 _paramInput = _parameterInput->getParamData(this).get();
62   -
  64 +
63 65 // check reference parameter
64 66 if (_refParameterSPtr == nullptr) {
65 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 74 _paramRefInput = _refParameterSPtr->getParamData(this).get();
71 75  
72 76 double computedGapSize = _refParameterSPtr->getParameterManager().getComputedGapSize(_parameterInput->getGapThreshold(), _paramInput->getMinSampling());
73 77 //_parameter.setGapThreshold(computedGapSize/_paramRefInput->getMinSampling());
74   -
  78 +
75 79 // ProcessSamplingClassic _operation creation
76 80 Resampling::CreateResampling lCreateResampling(*this, _timeIntervalList,
77 81 *_paramInput, *_paramRefInput, computedGapSize, _parameterInput->getDataWriterTemplate()->useNearestValue(), _refParameterSPtr == _parameterInput);
78 82 _operation = lCreateResampling.getResampling();
79 83  
80 84 static_cast<Resampling::ResamplingAbstract*>(_operation)->init();
81   -
  85 +
82 86 /// Get result ParamData
83 87 _paramData = ParamDataSPtr(_operation->getParamOutput());
84 88  
... ... @@ -168,7 +172,7 @@ void ProcessSamplingUnderRefParam::updateInfo(Parameter &amp; parameter)
168 172 processInfo += _refParameterSPtr->getId();
169 173 processInfo += "'";
170 174  
171   - if (_parameterInput->getDataWriterTemplate()->useNearestValue())
  175 + if (_parameterInput->getDataWriterTemplate()->useNearestValue())
172 176 processInfo += ". Use nearest value.";
173 177  
174 178 paramInfo->setProcessInfo(processInfo);
... ...