Commit deefda790c186d7312982fd55a6f38c1dc1b336b
1 parent
097dfbf9
Exists in
master
and in
79 other branches
Addapt resampling under ref. parameter to be useable in a parameter definition (#7018)
Showing
9 changed files
with
109 additions
and
22 deletions
Show diff stats
src/InternLib/MultiParamProcess.cc
... | ... | @@ -238,7 +238,12 @@ double MultiParamProcess::getMinSampling() |
238 | 238 | { |
239 | 239 | ParameterSPtr& parameter = param.second.first; |
240 | 240 | double paramMinSampling = 0; |
241 | - if (parameter->getTimeResolution() > 0) | |
241 | + if (!parameter->getReferenceParameter().empty()) { | |
242 | + std::string refParamId = parameter->getReferenceParameter(); | |
243 | + ParameterSPtr refParam = parameter->getParameterManager().getParameter(refParamId); | |
244 | + paramMinSampling = refParam->getDataWriterTemplate()->getMinSampling(); | |
245 | + } | |
246 | + else if (parameter->getTimeResolution() > 0) | |
242 | 247 | paramMinSampling = parameter->getTimeResolution(); |
243 | 248 | else if (parameter->getDataWriterTemplate() != nullptr) |
244 | 249 | paramMinSampling = parameter->getDataWriterTemplate()->getMinSampling(); | ... | ... |
src/InternLib/ProcessSamplingUnderRefParam.cc
... | ... | @@ -38,10 +38,18 @@ ProcessSamplingUnderRefParam::~ProcessSamplingUnderRefParam() { |
38 | 38 | |
39 | 39 | |
40 | 40 | void ProcessSamplingUnderRefParam::establishConnection() { |
41 | - if (_refParameterSPtr != nullptr) | |
41 | + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) { | |
42 | 42 | _refParameterSPtr->openConnection(this); |
43 | + } | |
43 | 44 | |
44 | 45 | SingleParamProcess_CRTP::establishConnection(); |
46 | + | |
47 | + if ((_refParameterSPtr == nullptr) && (_attributList.size() == 1) ) { | |
48 | + _refParameterSPtr = _parameterInput->getParameterManager().getParameter(_attributList[0]); | |
49 | + if ((_refParameterSPtr != nullptr) && (_refParameterSPtr != _parameterInput)) { | |
50 | + _refParameterSPtr->openConnection(this); | |
51 | + } | |
52 | + } | |
45 | 53 | } |
46 | 54 | |
47 | 55 | TimeStamp ProcessSamplingUnderRefParam::init() { |
... | ... | @@ -81,15 +89,26 @@ unsigned int ProcessSamplingUnderRefParam::write() |
81 | 89 | { |
82 | 90 | _paramRefInput = _refParameterSPtr->getParamData(this).get(); |
83 | 91 | |
84 | - ParamDataIndexInfo lRefParamDataIndexInfo = _paramRefInput->getIndexInfo(); | |
85 | - while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt) { | |
86 | - lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get(); | |
92 | + if ((_refParameterSPtr != _parameterInput)) { | |
93 | + ParamDataIndexInfo lRefParamDataIndexInfo; | |
94 | + do { | |
95 | + lRefParamDataIndexInfo = _refParameterSPtr->getAsync(this).get(); | |
96 | + for (unsigned int index = lRefParamDataIndexInfo._startIndex; index < lRefParamDataIndexInfo._startIndex + lRefParamDataIndexInfo._nbDataToProcess; index++) { | |
97 | + static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index)); | |
98 | + } | |
99 | + } while (!lRefParamDataIndexInfo._timeIntToProcessChanged && !lRefParamDataIndexInfo._noMoreTimeInt); | |
87 | 100 | } |
88 | 101 | |
89 | - | |
90 | 102 | int ret = 0; |
91 | 103 | unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber(); |
92 | 104 | ParamDataIndexInfo lParamDataIndexInfo = _parameterInput->getAsync(this).get(); |
105 | + | |
106 | + if ((_refParameterSPtr == _parameterInput)) { | |
107 | + for (unsigned int index = lParamDataIndexInfo._startIndex; index < lParamDataIndexInfo._startIndex + lParamDataIndexInfo._nbDataToProcess; index++) { | |
108 | + static_cast<Resampling::ResamplingAbstract*>(_operation)->pushTime(_paramRefInput->getTime(index)); | |
109 | + } | |
110 | + } | |
111 | + | |
93 | 112 | _operation->write(lParamDataIndexInfo); |
94 | 113 | ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; |
95 | 114 | ... | ... |
src/InternLib/Resampling.hh
... | ... | @@ -90,14 +90,14 @@ public: |
90 | 90 | std::advance(it, currentTimeIntervalIndex-1); |
91 | 91 | _crtRefIndex = *it; |
92 | 92 | } |
93 | - while (pStartTime > _refParamDataPtr->getTime(_crtRefIndex)) { | |
93 | + while (pStartTime > _refTimes[_crtRefIndex]) { | |
94 | 94 | ++_crtRefIndex; |
95 | 95 | if (_crtRefIndex >= (int)_refParamDataPtr->getDataNumber()) { |
96 | 96 | _crtRefIndex = -1; |
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | } |
100 | - return setTargetTime(_refParamDataPtr->getTime(_crtRefIndex)); | |
100 | + return setTargetTime(_refTimes[_crtRefIndex]); | |
101 | 101 | } |
102 | 102 | |
103 | 103 | bool nextTarget() { |
... | ... | @@ -113,17 +113,23 @@ public: |
113 | 113 | _crtRefIndex = -1; |
114 | 114 | return false; |
115 | 115 | } |
116 | - return setTargetTime(_refParamDataPtr->getTime(_crtRefIndex)); | |
116 | + return setTargetTime(_refTimes[_crtRefIndex]); | |
117 | 117 | } |
118 | 118 | |
119 | 119 | bool isFinished() { |
120 | 120 | return (_crtRefIndex == -1); |
121 | 121 | } |
122 | 122 | |
123 | + void pushTime(double time) { | |
124 | + _refTimes.push_back(time); | |
125 | + } | |
126 | + | |
123 | 127 | private: |
124 | 128 | ParamData* _refParamDataPtr; |
125 | 129 | |
126 | 130 | int _crtRefIndex; |
131 | + | |
132 | + std::vector<double> _refTimes; | |
127 | 133 | }; |
128 | 134 | |
129 | 135 | class MarkerSampling: public MarkerAbstract { |
... | ... | @@ -188,6 +194,8 @@ public: |
188 | 194 | */ |
189 | 195 | virtual void resetResampling() = 0; |
190 | 196 | |
197 | + virtual void pushTime(double time) = 0; | |
198 | + | |
191 | 199 | protected: |
192 | 200 | /** |
193 | 201 | *@brief tag to know if a new time interval is set |
... | ... | @@ -520,6 +528,7 @@ public: |
520 | 528 | |
521 | 529 | virtual double getSampling() = 0; |
522 | 530 | |
531 | + | |
523 | 532 | /** |
524 | 533 | * @brief sampling mode |
525 | 534 | */ |
... | ... | @@ -619,6 +628,10 @@ public: |
619 | 628 | return _samplingTime; |
620 | 629 | } |
621 | 630 | |
631 | + void pushTime(double /*time*/) { | |
632 | + //Not used | |
633 | + } | |
634 | + | |
622 | 635 | private: |
623 | 636 | MarkerSampling _marker; |
624 | 637 | |
... | ... | @@ -653,6 +666,10 @@ public: |
653 | 666 | return _refParamData.getMinSampling(); |
654 | 667 | } |
655 | 668 | |
669 | + void pushTime(double time) { | |
670 | + _marker.pushTime(time); | |
671 | + } | |
672 | + | |
656 | 673 | private: |
657 | 674 | MarkerRefParam _marker; |
658 | 675 | ... | ... |
src/InternLib/SingleParamProcess.cc
... | ... | @@ -141,7 +141,12 @@ namespace AMDA { |
141 | 141 | _expressionParsed = true; |
142 | 142 | if (_parameterInput == nullptr) |
143 | 143 | return 0; |
144 | - if (_parameterInput->getTimeResolution() > 0) | |
144 | + if (!_parameterInput->getReferenceParameter().empty()) { | |
145 | + std::string paramRefId = _parameterInput->getReferenceParameter(); | |
146 | + ParameterSPtr refParam = _parameterInput->getParameterManager().getParameter(paramRefId); | |
147 | + return refParam->getDataWriterTemplate()->getMinSampling(); | |
148 | + } | |
149 | + else if (_parameterInput->getTimeResolution() > 0) | |
145 | 150 | return _parameterInput->getTimeResolution(); |
146 | 151 | if (_parameterInput->getDataWriterTemplate() == nullptr) |
147 | 152 | return 0; | ... | ... |
src/ParamOutputImpl/Plot/PanelPlotOutput.cc
... | ... | @@ -2655,6 +2655,10 @@ AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameter(AMDA::Pa |
2655 | 2655 | */ |
2656 | 2656 | AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameterUnderReferenceParameter(AMDA::Parameters::ParameterSPtr& originalParam, AMDA::Parameters::ParameterSPtr& refParam) |
2657 | 2657 | { |
2658 | + /*if (originalParam == refParam) { | |
2659 | + return originalParam; | |
2660 | + }*/ | |
2661 | + | |
2658 | 2662 | AMDA::Parameters::ParameterSPtr sampledParam = _parameterManager.getSampledParameterUnderRefParam( |
2659 | 2663 | originalParam->getId(), |
2660 | 2664 | refParam->getId(), true | ... | ... |
src/Parameters/Parameter.cc
src/Parameters/Parameter.hh
... | ... | @@ -77,6 +77,10 @@ namespace AMDA { |
77 | 77 | return _gapThreshold; |
78 | 78 | } |
79 | 79 | |
80 | + std::string getReferenceParameter() { | |
81 | + return _referenceParameter; | |
82 | + } | |
83 | + | |
80 | 84 | /** |
81 | 85 | * @brief get list of CalibrationInfoWriter |
82 | 86 | */ |
... | ... | @@ -122,6 +126,10 @@ namespace AMDA { |
122 | 126 | _gapThreshold = pGapThreshold; |
123 | 127 | } |
124 | 128 | |
129 | + void setReferenceParameter(std::string& pReferenceParameter) { | |
130 | + _referenceParameter = pReferenceParameter; | |
131 | + } | |
132 | + | |
125 | 133 | /** |
126 | 134 | * Add additional Information values. |
127 | 135 | */ |
... | ... | @@ -247,6 +255,8 @@ namespace AMDA { |
247 | 255 | */ |
248 | 256 | double _gapThreshold; |
249 | 257 | |
258 | + std::string _referenceParameter; | |
259 | + | |
250 | 260 | /** |
251 | 261 | * list of functor to write callibration info |
252 | 262 | */ | ... | ... |
src/XMLParameterConfigurator/ParamNode.cc
... | ... | @@ -56,12 +56,24 @@ namespace AMDA { |
56 | 56 | } |
57 | 57 | }; |
58 | 58 | |
59 | + class NodeReferenceParameter: public AMDA::XMLConfigurator::NodeCfg { | |
60 | + public: | |
61 | + void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) { | |
62 | + LOG4CXX_DEBUG(gLogger, "NodeReferenceParameter::proceed") | |
63 | + Parameter* p = context.get<Parameter*>(); | |
64 | + if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') { | |
65 | + std::string refParam = (char*)pNode->children->content; | |
66 | + p->setReferenceParameter(refParam); | |
67 | + } | |
68 | + } | |
69 | + }; | |
59 | 70 | |
60 | 71 | ParamNode::ParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() |
61 | 72 | { |
62 | 73 | LOG4CXX_DEBUG(gLogger, "ParamNode Constructor") |
63 | 74 | getChildList()["time_resolution"]=NodeCfgSPtr(new NodeTimeResolution); |
64 | 75 | getChildList()["gap_threshold"]=NodeCfgSPtr(new NodeGapThreshold); |
76 | + getChildList()["reference_parameter"]=NodeCfgSPtr(new NodeReferenceParameter); | |
65 | 77 | getChildList()["process"]=NodeCfgSPtr(new ProcessNode()); |
66 | 78 | getChildList()["clbManual"]=NodeCfgSPtr(new ManualCalibrationNode()); |
67 | 79 | getChildList()["clbProcess"]=NodeCfgSPtr(new CalibrationNode()); | ... | ... |
src/XMLParameterConfigurator/ProcessNode.cc
... | ... | @@ -33,7 +33,7 @@ ProcessNode::ProcessNode() : NodeCfg() { |
33 | 33 | ProcessNode::~ProcessNode() { |
34 | 34 | } |
35 | 35 | |
36 | -std::string injectResamplingIntoProcess(const double& pTimeresolution, const double& pGapThreshold, const std::string& pExpression) { | |
36 | +std::string injectResamplingIntoProcess(const std::string& pProcessName, const std::string& pProcessParams, const std::string& pExpression) { | |
37 | 37 | std::stringstream lBuffer; |
38 | 38 | bool isAParam = false; |
39 | 39 | |
... | ... | @@ -47,7 +47,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou |
47 | 47 | int patternSize = std::string("#sum_into_table_range($").size(); |
48 | 48 | i += patternSize; |
49 | 49 | //special case with sum_into_table_range |
50 | - lBuffer << "#sampling_classic(#sum_into_table_range($"; | |
50 | + lBuffer << "#" << pProcessName << "(#sum_into_table_range($"; | |
51 | 51 | part = part.substr(patternSize); |
52 | 52 | std::size_t pos = part.find(";"); |
53 | 53 | lBuffer << part.substr(0, pos); |
... | ... | @@ -56,7 +56,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou |
56 | 56 | pos = part.find(")"); |
57 | 57 | lBuffer << part.substr(0, pos); |
58 | 58 | i += pos; |
59 | - lBuffer << ");" << pTimeresolution << ";" << pGapThreshold << ")"; | |
59 | + lBuffer << ");" << pProcessParams << ")"; | |
60 | 60 | } |
61 | 61 | else { |
62 | 62 | lBuffer << pExpression[i]; |
... | ... | @@ -64,11 +64,11 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou |
64 | 64 | break; |
65 | 65 | case '$': |
66 | 66 | isAParam = true; |
67 | - lBuffer << "#sampling_classic($"; | |
67 | + lBuffer << "#" << pProcessName << "($"; | |
68 | 68 | break; |
69 | 69 | default: |
70 | 70 | if( isAParam && ! (isalnum(pExpression[i]) || (pExpression[i]=='_'))) { |
71 | - lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; | |
71 | + lBuffer << ";" << pProcessParams << ")"; | |
72 | 72 | isAParam=false; |
73 | 73 | } |
74 | 74 | lBuffer << pExpression[i]; |
... | ... | @@ -76,7 +76,7 @@ std::string injectResamplingIntoProcess(const double& pTimeresolution, const dou |
76 | 76 | } |
77 | 77 | } |
78 | 78 | if (isAParam) { |
79 | - lBuffer << ";" << pTimeresolution << ";" << pGapThreshold << ")"; | |
79 | + lBuffer << ";" << pProcessParams << ")"; | |
80 | 80 | } |
81 | 81 | |
82 | 82 | return std::string(lBuffer.str()); |
... | ... | @@ -88,6 +88,7 @@ void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& |
88 | 88 | |
89 | 89 | double lTimeResolution = lParameter->getTimeResolution(); |
90 | 90 | double lGapThreshold = lParameter->getGapThreshold(); |
91 | + std::string lReferenceParam = lParameter->getReferenceParameter(); | |
91 | 92 | Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter); |
92 | 93 | |
93 | 94 | //process description |
... | ... | @@ -115,17 +116,30 @@ void ProcessNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& |
115 | 116 | std::string expression = std::string((char*)pNode->children->content); |
116 | 117 | // Remove all aspaces |
117 | 118 | expression.erase(std::remove(expression.begin(), expression.end(), ' '), expression.end()); |
118 | - if ( lTimeResolution != 0 ) { | |
119 | + if (!lReferenceParam.empty()) { | |
120 | + // Inject Resampling with reference param | |
121 | + expression = injectResamplingIntoProcess("sampling_under_refparam", lReferenceParam, expression.c_str()); | |
122 | + } | |
123 | + else if ( lTimeResolution != 0 ) { | |
119 | 124 | // Inject Resampling |
120 | - expression = injectResamplingIntoProcess(lTimeResolution, lGapThreshold, expression.c_str()); | |
121 | - lProcess->setExpression(expression); | |
122 | - } else { | |
123 | - lProcess->setExpression(expression.c_str()); | |
125 | + std::stringstream lProcessParams; | |
126 | + lProcessParams << lTimeResolution << ";" << lGapThreshold; | |
127 | + expression = injectResamplingIntoProcess("sampling_classic", lProcessParams.str(), expression.c_str()); | |
124 | 128 | } |
129 | + lProcess->setExpression(expression); | |
125 | 130 | } else { |
126 | 131 | if ( lParameter->getParameterList().size() == 1 ) { |
127 | 132 | // Inject Resampling |
128 | - if ( lTimeResolution != 0 ) { | |
133 | + if (!lReferenceParam.empty()) { | |
134 | + lProcess = ServicesServer::getInstance()->getProcess("sampling_under_refparam",*lParameter); | |
135 | + std::stringstream lBuffer; | |
136 | + lProcess->getAttributList().push_back(lReferenceParam); | |
137 | + lBuffer.str(""); lBuffer << "$" << (*lParameter->getParameterList().begin())->getId(); | |
138 | + lProcess->setExpression(lBuffer.str()); | |
139 | + lDataWriter.reset( lProcess); | |
140 | + lParameter->setDataWriter(lDataWriter); | |
141 | + } | |
142 | + else if ( lTimeResolution != 0 ) { | |
129 | 143 | lProcess = ServicesServer::getInstance()->getProcess("sampling_classic",*lParameter); |
130 | 144 | std::stringstream lBuffer; |
131 | 145 | lBuffer.str(""); lBuffer << lTimeResolution; | ... | ... |