From aa8a8e5f7dcd450f0000ff98a968bc6af98cd489 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 5 Oct 2016 09:02:58 +0200 Subject: [PATCH] Auto compute gap for a derived parameter --- src/InternLib/ProcessStandard.cc | 15 +++++++++++++++ src/Parameters/ParameterManager.cc | 8 +++++++- src/Parameters/ParameterManager.hh | 2 +- src/Parameters/Process.cc | 4 ++-- src/Parameters/Process.hh | 2 ++ 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/InternLib/ProcessStandard.cc b/src/InternLib/ProcessStandard.cc index c99a57f..c171552 100644 --- a/src/InternLib/ProcessStandard.cc +++ b/src/InternLib/ProcessStandard.cc @@ -102,6 +102,21 @@ TimeStamp ProcessStandard::init() { (*_processInit)(this); _paramData->setMinSampling(_minSampling); + ParameterManager& lParameterManager = _parameter.getParameterManager(); + double minGapSize = NAN; + + for (auto param : _paramNameList) { + ParameterSPtr& parameter = param.second.first; + double crtGapSize = lParameterManager.getComputedGapSize(parameter->getGapThreshold(),parameter->getDataWriterTemplate()->getMinSampling()); + if (isNAN(minGapSize) || (crtGapSize < minGapSize)) + minGapSize = crtGapSize; + } + + if (!isNAN(minGapSize)) { + double computedGapThreshold = minGapSize / _minSampling; + _parameter.setGapThreshold(computedGapThreshold); + } + return time; } diff --git a/src/Parameters/ParameterManager.cc b/src/Parameters/ParameterManager.cc index 9a5367b..fd7d2ca 100644 --- a/src/Parameters/ParameterManager.cc +++ b/src/Parameters/ParameterManager.cc @@ -219,11 +219,15 @@ ParameterSPtr ParameterManager::getSampledParameterUnderRefParam(const std::stri return lParameter; } -ParameterSPtr ParameterManager::getParameterFromExpression(const std::string& pExpression) +ParameterSPtr ParameterManager::getParameterFromExpression(const std::string& pExpression, double gapThreshold) { boost::hash string_hash; std::stringstream lIdent; lIdent << string_hash(pExpression); + if (!isNAN(gapThreshold)) { + lIdent << "_"; + lIdent << gapThreshold; + } ParameterSPtr lParameter; ParameterSPtr lparentParameter; @@ -244,6 +248,8 @@ ParameterSPtr ParameterManager::getParameterFromExpression(const std::string& pE { //set expression and create the data writer lProcess->setExpression(pExpression); + if (!isNAN(gapThreshold)) + lProcess->setGapThreshold(gapThreshold); DataWriterSPtr lDataWriter(lProcess); lParameter->setDataWriter(lDataWriter); _parameterList[lIdent.str()] = lParameter; diff --git a/src/Parameters/ParameterManager.hh b/src/Parameters/ParameterManager.hh index 946bd57..0f90fd6 100644 --- a/src/Parameters/ParameterManager.hh +++ b/src/Parameters/ParameterManager.hh @@ -73,7 +73,7 @@ namespace AMDA /** * get a parameter from an expression */ - ParameterSPtr getParameterFromExpression(const std::string& pExpression); + ParameterSPtr getParameterFromExpression(const std::string& pExpression, double gapThreshold = NAN); /** * get a parameter identify by parameterName diff --git a/src/Parameters/Process.cc b/src/Parameters/Process.cc index 09fb68b..5a4babf 100644 --- a/src/Parameters/Process.cc +++ b/src/Parameters/Process.cc @@ -28,7 +28,7 @@ Process::Process(Parameter ¶meter) : AMDA::Parameters::DataWriter(parameter) ,DataClient() ,_operation(NULL), - _refParameterSPtr(ParameterSPtr()) { + _refParameterSPtr(ParameterSPtr()), _gapThreshold(NAN) { } /** @@ -41,7 +41,7 @@ Process::Process(const Process &pProcess, Parameter ¶meter) : , _expression(pProcess._expression) , _description(pProcess._description) ,_operation(NULL), //No need clone of the operation, it is done in the 'init' method implementation - _refParameterSPtr(pProcess._refParameterSPtr) + _refParameterSPtr(pProcess._refParameterSPtr), _gapThreshold(pProcess._gapThreshold) { } diff --git a/src/Parameters/Process.hh b/src/Parameters/Process.hh index b3218d3..7d4f9f5 100644 --- a/src/Parameters/Process.hh +++ b/src/Parameters/Process.hh @@ -65,6 +65,7 @@ public: void setDescription(const std::string& description) { _description = description; } void setOperation(Operation* pOperation) { _operation = pOperation; } void setReferenceParameter( ParameterSPtr refParameterSPtr) { _refParameterSPtr = refParameterSPtr;} + void setGapThreshold(double gapThreshold) { _gapThreshold = gapThreshold; } // Others methods @@ -84,6 +85,7 @@ protected: std::string _description; Operation *_operation; ParameterSPtr _refParameterSPtr; + double _gapThreshold; }; typedef boost::shared_ptr ProcessSPtr; -- libgit2 0.21.2