From deefda790c186d7312982fd55a6f38c1dc1b336b Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 22 Sep 2020 15:43:45 +0200 Subject: [PATCH] Addapt resampling under ref. parameter to be useable in a parameter definition (#7018) --- src/InternLib/MultiParamProcess.cc | 7 ++++++- src/InternLib/ProcessSamplingUnderRefParam.cc | 29 ++++++++++++++++++++++++----- src/InternLib/Resampling.hh | 23 ++++++++++++++++++++--- src/InternLib/SingleParamProcess.cc | 7 ++++++- src/ParamOutputImpl/Plot/PanelPlotOutput.cc | 4 ++++ src/Parameters/Parameter.cc | 1 + src/Parameters/Parameter.hh | 10 ++++++++++ src/XMLParameterConfigurator/ParamNode.cc | 12 ++++++++++++ src/XMLParameterConfigurator/ProcessNode.cc | 38 ++++++++++++++++++++++++++------------ 9 files changed, 109 insertions(+), 22 deletions(-) diff --git a/src/InternLib/MultiParamProcess.cc b/src/InternLib/MultiParamProcess.cc index 42f5d7b..f8fa45b 100644 --- a/src/InternLib/MultiParamProcess.cc +++ b/src/InternLib/MultiParamProcess.cc @@ -238,7 +238,12 @@ double MultiParamProcess::getMinSampling() { ParameterSPtr& parameter = param.second.first; double paramMinSampling = 0; - if (parameter->getTimeResolution() > 0) + if (!parameter->getReferenceParameter().empty()) { + std::string refParamId = parameter->getReferenceParameter(); + ParameterSPtr refParam = parameter->getParameterManager().getParameter(refParamId); + paramMinSampling = refParam->getDataWriterTemplate()->getMinSampling(); + } + else if (parameter->getTimeResolution() > 0) paramMinSampling = parameter->getTimeResolution(); else if (parameter->getDataWriterTemplate() != nullptr) paramMinSampling = parameter->getDataWriterTemplate()->getMinSampling(); diff --git a/src/InternLib/ProcessSamplingUnderRefParam.cc b/src/InternLib/ProcessSamplingUnderRefParam.cc index d398c43..678f5b8 100644 --- a/src/InternLib/ProcessSamplingUnderRefParam.cc +++ b/src/InternLib/ProcessSamplingUnderRefParam.cc @@ -38,10 +38,18 @@ ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() { void ProcessSamplingUnderRefParam::establishConnection() { - if (_refParameterSPtr != nullptr) + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) { _refParameterSPtr->openConnection(this); + } SingleParamProcess_CRTP::establishConnection(); + + if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) { + _refParameterSPtr = _parameterInput->getParameterManager().getParameter(_attributList[0]); + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) { + _refParameterSPtr->openConnection(this); + } + } } TimeStamp ProcessSamplingUnderRefParam::init() { @@ -81,15 +89,26 @@ unsigned int ProcessSamplingUnderRefParam::write() { _paramRefInput = _refParameterSPtr->getParamData(this).get(); - ParamDataIndexInfo lRefParamDataIndexInfo = _paramRefInput->getIndexInfo(); - while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt) { - lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get(); + if ((_refParameterSPtr != _parameterInput)) { + ParamDataIndexInfo lRefParamDataIndexInfo; + do { + lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get(); + for (unsigned int index = lRefParamDataIndexInfo._startIndex; index < lRefParamDataIndexInfo._startIndex + lRefParamDataIndexInfo._nbDataToProcess; index++) { + static_cast(_operation)->pushTime(_paramRefInput->getTime(index)); + } + } while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt); } - int ret = 0; unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber(); ParamDataIndexInfo lParamDataIndexInfo = _parameterInput->getAsync(this).get(); + + if ((_refParameterSPtr == _parameterInput)) { + for (unsigned int index = lParamDataIndexInfo._startIndex; index < lParamDataIndexInfo._startIndex + lParamDataIndexInfo._nbDataToProcess; index++) { + static_cast(_operation)->pushTime(_paramRefInput->getTime(index)); + } + } + _operation->write(lParamDataIndexInfo); ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; diff --git a/src/InternLib/Resampling.hh b/src/InternLib/Resampling.hh index 76aa9b2..beee227 100644 --- a/src/InternLib/Resampling.hh +++ b/src/InternLib/Resampling.hh @@ -90,14 +90,14 @@ public: std::advance(it, currentTimeIntervalIndex-1); _crtRefIndex = *it; } - while (pStartTime > _refParamDataPtr->getTime(_crtRefIndex)) { + while (pStartTime > _refTimes[_crtRefIndex]) { ++_crtRefIndex; if (_crtRefIndex >= (int)_refParamDataPtr->getDataNumber()) { _crtRefIndex = -1; return false; } } - return setTargetTime(_refParamDataPtr->getTime(_crtRefIndex)); + return setTargetTime(_refTimes[_crtRefIndex]); } bool nextTarget() { @@ -113,17 +113,23 @@ public: _crtRefIndex = -1; return false; } - return setTargetTime(_refParamDataPtr->getTime(_crtRefIndex)); + return setTargetTime(_refTimes[_crtRefIndex]); } bool isFinished() { return (_crtRefIndex == -1); } + void pushTime(double time) { + _refTimes.push_back(time); + } + private: ParamData* _refParamDataPtr; int _crtRefIndex; + + std::vector _refTimes; }; class MarkerSampling: public MarkerAbstract { @@ -188,6 +194,8 @@ public: */ virtual void resetResampling() = 0; + virtual void pushTime(double time) = 0; + protected: /** *@brief tag to know if a new time interval is set @@ -520,6 +528,7 @@ public: virtual double getSampling() = 0; + /** * @brief sampling mode */ @@ -619,6 +628,10 @@ public: return _samplingTime; } + void pushTime(double /*time*/) { + //Not used + } + private: MarkerSampling _marker; @@ -653,6 +666,10 @@ public: return _refParamData.getMinSampling(); } + void pushTime(double time) { + _marker.pushTime(time); + } + private: MarkerRefParam _marker; diff --git a/src/InternLib/SingleParamProcess.cc b/src/InternLib/SingleParamProcess.cc index 16530fc..e73b622 100644 --- a/src/InternLib/SingleParamProcess.cc +++ b/src/InternLib/SingleParamProcess.cc @@ -141,7 +141,12 @@ namespace AMDA { _expressionParsed = true; if (_parameterInput == nullptr) return 0; - if (_parameterInput->getTimeResolution() > 0) + if (!_parameterInput->getReferenceParameter().empty()) { + std::string paramRefId = _parameterInput->getReferenceParameter(); + ParameterSPtr refParam = _parameterInput->getParameterManager().getParameter(paramRefId); + return refParam->getDataWriterTemplate()->getMinSampling(); + } + else if (_parameterInput->getTimeResolution() > 0) return _parameterInput->getTimeResolution(); if (_parameterInput->getDataWriterTemplate() == nullptr) return 0; diff --git a/src/ParamOutputImpl/Plot/PanelPlotOutput.cc b/src/ParamOutputImpl/Plot/PanelPlotOutput.cc index e0ac843..1859d13 100644 --- a/src/ParamOutputImpl/Plot/PanelPlotOutput.cc +++ b/src/ParamOutputImpl/Plot/PanelPlotOutput.cc @@ -2655,6 +2655,10 @@ AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameter(AMDA::Pa */ AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameterUnderReferenceParameter(AMDA::Parameters::ParameterSPtr& originalParam, AMDA::Parameters::ParameterSPtr& refParam) { + /*if (originalParam == refParam) { + return originalParam; + }*/ + AMDA::Parameters::ParameterSPtr sampledParam = _parameterManager.getSampledParameterUnderRefParam( originalParam->getId(), refParam->getId(), true diff --git a/src/Parameters/Parameter.cc b/src/Parameters/Parameter.cc index 0609b18..47d0c91 100644 --- a/src/Parameters/Parameter.cc +++ b/src/Parameters/Parameter.cc @@ -33,6 +33,7 @@ namespace Parameters { _clientInitCall(0), _timeResolution(0) , _gapThreshold(pParamMng.getDefaultGapThreshold()) , + _referenceParameter(""), establishConnectionToDo(true){ } diff --git a/src/Parameters/Parameter.hh b/src/Parameters/Parameter.hh index db32ed8..8002826 100644 --- a/src/Parameters/Parameter.hh +++ b/src/Parameters/Parameter.hh @@ -77,6 +77,10 @@ namespace AMDA { return _gapThreshold; } + std::string getReferenceParameter() { + return _referenceParameter; + } + /** * @brief get list of CalibrationInfoWriter */ @@ -122,6 +126,10 @@ namespace AMDA { _gapThreshold = pGapThreshold; } + void setReferenceParameter(std::string& pReferenceParameter) { + _referenceParameter = pReferenceParameter; + } + /** * Add additional Information values. */ @@ -247,6 +255,8 @@ namespace AMDA { */ double _gapThreshold; + std::string _referenceParameter; + /** * list of functor to write callibration info */ diff --git a/src/XMLParameterConfigurator/ParamNode.cc b/src/XMLParameterConfigurator/ParamNode.cc index f921e76..64522da 100644 --- a/src/XMLParameterConfigurator/ParamNode.cc +++ b/src/XMLParameterConfigurator/ParamNode.cc @@ -56,12 +56,24 @@ namespace AMDA { } }; + class NodeReferenceParameter: public AMDA::XMLConfigurator::NodeCfg { + public: + void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { + LOG4CXX_DEBUG(gLogger, "NodeReferenceParameter::proceed") + Parameter* p = context.get(); + if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') { + std::string refParam = (char*)pNode->children->content; + p->setReferenceParameter(refParam); + } + } + }; ParamNode::ParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() { LOG4CXX_DEBUG(gLogger, "ParamNode Constructor") getChildList()["time_resolution"]=NodeCfgSPtr(new NodeTimeResolution); getChildList()["gap_threshold"]=NodeCfgSPtr(new NodeGapThreshold); + getChildList()["reference_parameter"]=NodeCfgSPtr(new NodeReferenceParameter); getChildList()["process"]=NodeCfgSPtr(new ProcessNode()); getChildList()["clbManual"]=NodeCfgSPtr(new ManualCalibrationNode()); getChildList()["clbProcess"]=NodeCfgSPtr(new CalibrationNode()); diff --git a/src/XMLParameterConfigurator/ProcessNode.cc b/src/XMLParameterConfigurator/ProcessNode.cc index c04597a..a207aa9 100644 --- a/src/XMLParameterConfigurator/ProcessNode.cc +++ b/src/XMLParameterConfigurator/ProcessNode.cc @@ -33,7 +33,7 @@ ProcessNode::ProcessNode() : NodeCfg() { ProcessNode::~ProcessNode() { } -std::string injectResamplingIntoProcess(const double& pTimeresolution, const double& pGapThreshold, const std::string& pExpression) { +std::string injectResamplingIntoProcess(const std::string& pProcessName, const std::string& pProcessParams, const std::string& pExpression) { std::stringstream lBuffer; bool isAParam = false; @@ -47,7 +47,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou int patternSize = std::string("#sum_into_table_range($").size(); i += patternSize; //special case with sum_into_table_range - lBuffer << "#sampling_classic(#sum_into_table_range($"; + lBuffer << "#" << pProcessName << "(#sum_into_table_range($"; part = part.substr(patternSize); std::size_t pos = part.find(";"); lBuffer << part.substr(0, pos); @@ -56,7 +56,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou pos = part.find(")"); lBuffer << part.substr(0, pos); i += pos; - lBuffer << ");" << pTimeresolution << ";" << pGapThreshold << ")"; + lBuffer << ");" << pProcessParams << ")"; } else { lBuffer << pExpression[i]; @@ -64,11 +64,11 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou break; case '$': isAParam = true; - lBuffer << "#sampling_classic($"; + lBuffer << "#" << pProcessName << "($"; break; default: if( isAParam && ! (isalnum(pExpression[i]) || (pExpression[i]=='_'))) { - lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; + lBuffer << ";" << pProcessParams << ")"; isAParam=false; } lBuffer << pExpression[i]; @@ -76,7 +76,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou } } if (isAParam) { - lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; + lBuffer << ";" << pProcessParams << ")"; } return std::string(lBuffer.str()); @@ -88,6 +88,7 @@ void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& double lTimeResolution = lParameter->getTimeResolution(); double lGapThreshold = lParameter->getGapThreshold(); + std::string lReferenceParam = lParameter->getReferenceParameter(); Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter); //process description @@ -115,17 +116,30 @@ void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& std::string expression = std::string((char*)pNode->children->content); // Remove all aspaces expression.erase(std::remove(expression.begin(), expression.end(), ' '), expression.end()); - if ( lTimeResolution != 0 ) { + if (!lReferenceParam.empty()) { + // Inject Resampling with reference param + expression = injectResamplingIntoProcess("sampling_under_refparam", lReferenceParam, expression.c_str()); + } + else if ( lTimeResolution != 0 ) { // Inject Resampling - expression = injectResamplingIntoProcess(lTimeResolution, lGapThreshold, expression.c_str()); - lProcess->setExpression(expression); - } else { - lProcess->setExpression(expression.c_str()); + std::stringstream lProcessParams; + lProcessParams << lTimeResolution << ";" << lGapThreshold; + expression = injectResamplingIntoProcess("sampling_classic", lProcessParams.str(), expression.c_str()); } + lProcess->setExpression(expression); } else { if ( lParameter->getParameterList().size() == 1 ) { // Inject Resampling - if ( lTimeResolution != 0 ) { + if (!lReferenceParam.empty()) { + lProcess = ServicesServer::getInstance()->getProcess("sampling_under_refparam",*lParameter); + std::stringstream lBuffer; + lProcess->getAttributList().push_back(lReferenceParam); + lBuffer.str(""); lBuffer << "$" << (*lParameter->getParameterList().begin())->getId(); + lProcess->setExpression(lBuffer.str()); + lDataWriter.reset( lProcess); + lParameter->setDataWriter(lDataWriter); + } + else if ( lTimeResolution != 0 ) { lProcess = ServicesServer::getInstance()->getProcess("sampling_classic",*lParameter); std::stringstream lBuffer; lBuffer.str(""); lBuffer << lTimeResolution; -- libgit2 0.21.2