Commit 1eac3ad2f7ecef510e7adf898bcef8cfdf4759d6
1 parent
d6c7a344
Exists in
master
and in
100 other branches
Fix tests used to know if dimensions must be updated
Showing
2 changed files
with
361 additions
and
356 deletions
Show diff stats
src/InternLib/MultiParamProcess.cc
1 | -/* | |
2 | - * MultiParamProcess.cc | |
3 | - * | |
4 | - * Created on: Jan 4, 2013 | |
5 | - * Author: f.casimir | |
6 | - */ | |
7 | - | |
8 | -#include <algorithm> | |
9 | -#include <limits> | |
10 | - | |
11 | -#include "ParamData.hh" | |
12 | -#include "Operation.hh" | |
13 | -#include "ParamMgr.hh" | |
14 | - | |
15 | -#include "MultiParamProcess.hh" | |
16 | - | |
17 | -namespace AMDA { | |
18 | -namespace Parameters { | |
19 | - | |
20 | -MultiParamProcess::MultiParamProcess(Parameter ¶meter) : | |
21 | - Process(parameter), _minSampling(std::numeric_limits<double>::max()) { | |
22 | -} | |
23 | - | |
24 | -MultiParamProcess::MultiParamProcess(const MultiParamProcess &pProcess, Parameter ¶meter) : | |
25 | - Process(pProcess,parameter), | |
26 | - _paramNameList(pProcess._paramNameList), | |
27 | - _minSampling(pProcess._minSampling) { | |
28 | - | |
29 | -} | |
30 | - | |
31 | -MultiParamProcess::~MultiParamProcess() { | |
32 | - for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
33 | - ParameterSPtr& parameter = it->second.first; | |
34 | - if ( parameter) { parameter->closeConnection(this); } | |
35 | - } | |
36 | -} | |
37 | - | |
38 | -/** | |
39 | - * @brief Connection to Parameter server. | |
40 | - */ | |
41 | -void MultiParamProcess::establishConnection() { | |
42 | - | |
43 | - for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
44 | - ParameterSPtr& parameter = it->second.first; | |
45 | - parameter->openConnection(this); | |
46 | - } | |
47 | -} | |
48 | - | |
49 | - TimeStamp MultiParamProcess::init() { | |
50 | - | |
51 | - TimeStamp time = 0; | |
52 | - for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
53 | - ParameterSPtr& parameter = it->second.first; | |
54 | - time = std::max(time, parameter->init(this, _timeIntervalList)); | |
55 | - Parameter::InfoList lInfoList = parameter->getInfoList(); | |
56 | - _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end()); | |
57 | - _minSampling = std::min(parameter->getParamData(this)->getMinSampling(), _minSampling); | |
58 | - } | |
59 | - return time; | |
60 | -} | |
61 | - | |
62 | -unsigned int MultiParamProcess::write() { | |
63 | - typedef std::list<std::pair< ParameterList::iterator,boost::shared_future<ParamDataIndexInfo> > > ParamDataIndexInfoFutureList; | |
64 | - | |
65 | - ParamDataIndexInfoFutureList lResultList; | |
66 | - unsigned int lNbTotalAvalaible = 0; | |
67 | - | |
68 | - for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) { | |
69 | - if (itParam->second.second._timeIntToProcessChanged && !_paramDataIndexInfo._timeIntToProcessChanged) | |
70 | - continue; | |
71 | - lNbTotalAvalaible = itParam->second.second._startIndex + itParam->second.second._nbDataToProcess; | |
72 | - if ( _paramDataIndexInfo._startIndex >= lNbTotalAvalaible) | |
73 | - { | |
74 | - LOG4CXX_DEBUG(_logger, "Need more data Parameter name: " << itParam->first ); | |
75 | - lResultList.push_back(make_pair(itParam,(*itParam->second.first).getAsync(this))); | |
76 | - } | |
77 | - } | |
78 | - | |
79 | - // Wait data | |
80 | - for ( ParamDataIndexInfoFutureList::iterator it= lResultList.begin();it != lResultList.end(); ++it) { | |
81 | - LOG4CXX_DEBUG(_logger, "Wait data Parameter name: " << it->first->first ); | |
82 | - it->first->second.second=it->second.get(); | |
83 | - } | |
84 | - | |
85 | - //compute minimum data available | |
86 | - ParameterList::iterator it = _paramNameList.begin(); | |
87 | - if( it != _paramNameList.end()) { | |
88 | - ParamDataIndexInfo &lParamDataIndexInfoTmp= (*it).second.second; | |
89 | - LOG4CXX_DEBUG(_logger, "Parameter name: " << it->first << " Index: " << lParamDataIndexInfoTmp._startIndex <<" nbDataToProcess " << lParamDataIndexInfoTmp._nbDataToProcess); | |
90 | - lNbTotalAvalaible = lParamDataIndexInfoTmp._nbDataToProcess + lParamDataIndexInfoTmp._startIndex ; | |
91 | - ++it; | |
92 | - for ( ;it != _paramNameList.end(); ++it) { | |
93 | - ParamDataIndexInfo &lParamDataIndexInfoTmp= (*it).second.second; | |
94 | - LOG4CXX_DEBUG(_logger, "Parameter name: " << it->first << " Index: " << lParamDataIndexInfoTmp._startIndex <<" nbDataToProcess " << lParamDataIndexInfoTmp._nbDataToProcess); | |
95 | - lNbTotalAvalaible =std::min(lNbTotalAvalaible, lParamDataIndexInfoTmp._nbDataToProcess + lParamDataIndexInfoTmp._startIndex) ; | |
96 | - } | |
97 | - } | |
98 | - | |
99 | - _paramDataIndexInfo._nbDataToProcess = lNbTotalAvalaible - _paramDataIndexInfo._startIndex; | |
100 | - | |
101 | - _operation->write(_paramDataIndexInfo); | |
102 | - | |
103 | - _paramDataIndexInfo._startIndex +=_paramDataIndexInfo._nbDataToProcess ; | |
104 | - | |
105 | - // Reset operation instance to prepare it for the next time interval. | |
106 | - bool lTimeIntToProcessChanged = true; | |
107 | - bool lNoMoreTimeInt = true; | |
108 | - | |
109 | - for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) { | |
110 | - lTimeIntToProcessChanged &= itParam->second.second._timeIntToProcessChanged; | |
111 | - lNoMoreTimeInt &= itParam->second.second._noMoreTimeInt; | |
112 | - } | |
113 | - | |
114 | - if(lTimeIntToProcessChanged) { | |
115 | - LOG4CXX_DEBUG(_logger, "MultiParamProcess => Need to change interval"); | |
116 | - _operation->reset(); | |
117 | - _paramDataIndexInfo._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
118 | - _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
119 | - } | |
120 | - // There is no more time interval to process | |
121 | - else if (lNoMoreTimeInt) { | |
122 | - _paramDataIndexInfo._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
123 | - _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
124 | - LOG4CXX_DEBUG(_logger, "MultiParamProcess => No more time interval to process; end index for this interval is " << _paramDataIndexInfo._endTimeIntIndexList.back()); | |
125 | - } else { | |
126 | - // Nothing to do. | |
127 | - } | |
128 | - | |
129 | - _paramDataIndexInfo._timeIntToProcessChanged = lTimeIntToProcessChanged; | |
130 | - _paramDataIndexInfo._noMoreTimeInt = lNoMoreTimeInt; | |
131 | - _paramData->getIndexInfo()._noMoreTimeInt = lNoMoreTimeInt; | |
132 | - _paramData->getIndexInfo()._timeIntToProcessChanged = lTimeIntToProcessChanged; | |
133 | - | |
134 | - if (_paramDataIndexInfo._nbDataToProcess > 0) | |
135 | - _paramData->updateDims(); | |
136 | - | |
137 | - return _paramDataIndexInfo._nbDataToProcess; | |
138 | -} | |
139 | - | |
140 | -/* | |
141 | - * @brief @ to know the resampling strategy to use. If it's true, the nearest value will be use | |
142 | - */ | |
143 | -bool MultiParamProcess::useNearestValue() | |
144 | -{ | |
145 | - bool useNearestValue = true; | |
146 | - for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) | |
147 | - { | |
148 | - ParameterSPtr& parameter = it->second.first; | |
149 | - useNearestValue = useNearestValue && parameter->getDataWriterTemplate()->useNearestValue(); | |
150 | - } | |
151 | - return useNearestValue; | |
152 | -} | |
153 | - | |
154 | -/** | |
155 | - * @brief update parameter info in relation to the process | |
156 | - */ | |
157 | -void MultiParamProcess::updateInfo(Parameter & parameter) | |
158 | -{ | |
159 | - LOG4CXX_DEBUG(_logger, "MultiParamProcess::updateInfo - " << parameter.getId()); | |
160 | - | |
161 | - if (parameter.getInfoId().empty()) | |
162 | - parameter.setInfoId(parameter.getId()); | |
163 | - | |
164 | - //Param info | |
165 | - AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true); | |
166 | - | |
167 | - if (paramInfo == nullptr) | |
168 | - return; | |
169 | - | |
170 | - //Derived parameter => no comes from a dataset | |
171 | - paramInfo->setDatasetId(""); | |
172 | - | |
173 | - //set name and short name = param id | |
174 | - if (paramInfo->getName().empty()) | |
175 | - paramInfo->setName(parameter.getId()); | |
176 | - if (paramInfo->getShortName().empty()) | |
177 | - paramInfo->setShortName(parameter.getId()); | |
178 | - | |
179 | - std::string processInfo = "Derived parameter from expression '"; | |
180 | - processInfo += getExpression(); | |
181 | - processInfo += "'"; | |
182 | - | |
183 | - for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) | |
184 | - paramInfo->addLinkedParamId(itParam->first); | |
185 | - | |
186 | - paramInfo->setProcessInfo(processInfo); | |
187 | - paramInfo->setProcessDescription(getDescription()); | |
188 | -} | |
189 | - | |
190 | -/* | |
191 | - * @brief Get min sampling | |
192 | - */ | |
193 | -double MultiParamProcess::getMinSampling() | |
194 | -{ | |
195 | - double minSampling = 0; | |
196 | - for (auto param : _paramNameList) | |
197 | - { | |
198 | - ParameterSPtr& parameter = param.second.first; | |
199 | - double paramMinSampling = 0; | |
200 | - if (parameter->getTimeResolution() > 0) | |
201 | - paramMinSampling = parameter->getTimeResolution(); | |
202 | - else if (parameter->getDataWriterTemplate() != nullptr) | |
203 | - paramMinSampling = parameter->getDataWriterTemplate()->getMinSampling(); | |
204 | - | |
205 | - if (minSampling == 0) | |
206 | - minSampling = paramMinSampling; | |
207 | - else if (paramMinSampling != 0) | |
208 | - minSampling = std::min(minSampling,paramMinSampling); | |
209 | - } | |
210 | - return minSampling; | |
211 | -} | |
212 | - | |
213 | - | |
214 | -} /* namespace Parameters */ | |
215 | -} /* namespace AMDA */ | |
1 | +/* | |
2 | + * MultiParamProcess.cc | |
3 | + * | |
4 | + * Created on: Jan 4, 2013 | |
5 | + * Author: f.casimir | |
6 | + */ | |
7 | + | |
8 | +#include <algorithm> | |
9 | +#include <limits> | |
10 | + | |
11 | +#include "ParamData.hh" | |
12 | +#include "Operation.hh" | |
13 | +#include "ParamMgr.hh" | |
14 | + | |
15 | +#include "MultiParamProcess.hh" | |
16 | + | |
17 | +namespace AMDA { | |
18 | +namespace Parameters { | |
19 | + | |
20 | +MultiParamProcess::MultiParamProcess(Parameter ¶meter) : | |
21 | + Process(parameter), _minSampling(std::numeric_limits<double>::max()) { | |
22 | +} | |
23 | + | |
24 | +MultiParamProcess::MultiParamProcess(const MultiParamProcess &pProcess, Parameter ¶meter) : | |
25 | + Process(pProcess,parameter), | |
26 | + _paramNameList(pProcess._paramNameList), | |
27 | + _minSampling(pProcess._minSampling) { | |
28 | + | |
29 | +} | |
30 | + | |
31 | +MultiParamProcess::~MultiParamProcess() { | |
32 | + for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
33 | + ParameterSPtr& parameter = it->second.first; | |
34 | + if ( parameter) { parameter->closeConnection(this); } | |
35 | + } | |
36 | +} | |
37 | + | |
38 | +/** | |
39 | + * @brief Connection to Parameter server. | |
40 | + */ | |
41 | +void MultiParamProcess::establishConnection() { | |
42 | + | |
43 | + for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
44 | + ParameterSPtr& parameter = it->second.first; | |
45 | + parameter->openConnection(this); | |
46 | + } | |
47 | +} | |
48 | + | |
49 | + TimeStamp MultiParamProcess::init() { | |
50 | + | |
51 | + TimeStamp time = 0; | |
52 | + for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) { | |
53 | + ParameterSPtr& parameter = it->second.first; | |
54 | + time = std::max(time, parameter->init(this, _timeIntervalList)); | |
55 | + Parameter::InfoList lInfoList = parameter->getInfoList(); | |
56 | + _parameter.getInfoList().insert(lInfoList.begin(), lInfoList.end()); | |
57 | + _minSampling = std::min(parameter->getParamData(this)->getMinSampling(), _minSampling); | |
58 | + } | |
59 | + return time; | |
60 | +} | |
61 | + | |
62 | +unsigned int MultiParamProcess::write() { | |
63 | + typedef std::list<std::pair< ParameterList::iterator,boost::shared_future<ParamDataIndexInfo> > > ParamDataIndexInfoFutureList; | |
64 | + | |
65 | + ParamDataIndexInfoFutureList lResultList; | |
66 | + unsigned int lNbTotalAvalaible = 0; | |
67 | + | |
68 | + for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) { | |
69 | + if (itParam->second.second._timeIntToProcessChanged && !_paramDataIndexInfo._timeIntToProcessChanged) | |
70 | + continue; | |
71 | + lNbTotalAvalaible = itParam->second.second._startIndex + itParam->second.second._nbDataToProcess; | |
72 | + if ( _paramDataIndexInfo._startIndex >= lNbTotalAvalaible) | |
73 | + { | |
74 | + LOG4CXX_DEBUG(_logger, "Need more data Parameter name: " << itParam->first ); | |
75 | + lResultList.push_back(make_pair(itParam,(*itParam->second.first).getAsync(this))); | |
76 | + } | |
77 | + } | |
78 | + | |
79 | + // Wait data | |
80 | + for ( ParamDataIndexInfoFutureList::iterator it= lResultList.begin();it != lResultList.end(); ++it) { | |
81 | + LOG4CXX_DEBUG(_logger, "Wait data Parameter name: " << it->first->first ); | |
82 | + it->first->second.second=it->second.get(); | |
83 | + } | |
84 | + | |
85 | + //compute minimum data available | |
86 | + ParameterList::iterator it = _paramNameList.begin(); | |
87 | + if( it != _paramNameList.end()) { | |
88 | + ParamDataIndexInfo &lParamDataIndexInfoTmp= (*it).second.second; | |
89 | + LOG4CXX_DEBUG(_logger, "Parameter name: " << it->first << " Index: " << lParamDataIndexInfoTmp._startIndex <<" nbDataToProcess " << lParamDataIndexInfoTmp._nbDataToProcess); | |
90 | + lNbTotalAvalaible = lParamDataIndexInfoTmp._nbDataToProcess + lParamDataIndexInfoTmp._startIndex ; | |
91 | + ++it; | |
92 | + for ( ;it != _paramNameList.end(); ++it) { | |
93 | + ParamDataIndexInfo &lParamDataIndexInfoTmp= (*it).second.second; | |
94 | + LOG4CXX_DEBUG(_logger, "Parameter name: " << it->first << " Index: " << lParamDataIndexInfoTmp._startIndex <<" nbDataToProcess " << lParamDataIndexInfoTmp._nbDataToProcess); | |
95 | + lNbTotalAvalaible =std::min(lNbTotalAvalaible, lParamDataIndexInfoTmp._nbDataToProcess + lParamDataIndexInfoTmp._startIndex) ; | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + _paramDataIndexInfo._nbDataToProcess = lNbTotalAvalaible - _paramDataIndexInfo._startIndex; | |
100 | + | |
101 | + _operation->write(_paramDataIndexInfo); | |
102 | + | |
103 | + bool updateDims = (_paramDataIndexInfo._nbDataToProcess > 0) && (_paramDataIndexInfo._startIndex == 0); | |
104 | + | |
105 | + _paramDataIndexInfo._startIndex +=_paramDataIndexInfo._nbDataToProcess ; | |
106 | + | |
107 | + // Reset operation instance to prepare it for the next time interval. | |
108 | + bool lTimeIntToProcessChanged = true; | |
109 | + bool lNoMoreTimeInt = true; | |
110 | + | |
111 | + for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) { | |
112 | + lTimeIntToProcessChanged &= itParam->second.second._timeIntToProcessChanged; | |
113 | + lNoMoreTimeInt &= itParam->second.second._noMoreTimeInt; | |
114 | + } | |
115 | + | |
116 | + if(lTimeIntToProcessChanged) { | |
117 | + LOG4CXX_DEBUG(_logger, "MultiParamProcess => Need to change interval"); | |
118 | + _operation->reset(); | |
119 | + _paramDataIndexInfo._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
120 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
121 | + } | |
122 | + // There is no more time interval to process | |
123 | + else if (lNoMoreTimeInt) { | |
124 | + _paramDataIndexInfo._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
125 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(lNbTotalAvalaible); | |
126 | + LOG4CXX_DEBUG(_logger, "MultiParamProcess => No more time interval to process; end index for this interval is " << _paramDataIndexInfo._endTimeIntIndexList.back()); | |
127 | + } else { | |
128 | + // Nothing to do. | |
129 | + } | |
130 | + | |
131 | + _paramDataIndexInfo._timeIntToProcessChanged = lTimeIntToProcessChanged; | |
132 | + _paramDataIndexInfo._noMoreTimeInt = lNoMoreTimeInt; | |
133 | + _paramData->getIndexInfo()._noMoreTimeInt = lNoMoreTimeInt; | |
134 | + _paramData->getIndexInfo()._timeIntToProcessChanged = lTimeIntToProcessChanged; | |
135 | + | |
136 | + if (updateDims) | |
137 | + _paramData->updateDims(); | |
138 | + | |
139 | + return _paramDataIndexInfo._nbDataToProcess; | |
140 | +} | |
141 | + | |
142 | +/* | |
143 | + * @brief @ to know the resampling strategy to use. If it's true, the nearest value will be use | |
144 | + */ | |
145 | +bool MultiParamProcess::useNearestValue() | |
146 | +{ | |
147 | + bool useNearestValue = true; | |
148 | + for (ParameterList::iterator it = _paramNameList.begin(); it != _paramNameList.end(); ++it) | |
149 | + { | |
150 | + ParameterSPtr& parameter = it->second.first; | |
151 | + useNearestValue = useNearestValue && parameter->getDataWriterTemplate()->useNearestValue(); | |
152 | + } | |
153 | + return useNearestValue; | |
154 | +} | |
155 | + | |
156 | +/** | |
157 | + * @brief update parameter info in relation to the process | |
158 | + */ | |
159 | +void MultiParamProcess::updateInfo(Parameter & parameter) | |
160 | +{ | |
161 | + LOG4CXX_DEBUG(_logger, "MultiParamProcess::updateInfo - " << parameter.getId()); | |
162 | + | |
163 | + if (parameter.getInfoId().empty()) | |
164 | + parameter.setInfoId(parameter.getId()); | |
165 | + | |
166 | + //Param info | |
167 | + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(parameter.getInfoId(),true); | |
168 | + | |
169 | + if (paramInfo == nullptr) | |
170 | + return; | |
171 | + | |
172 | + //Derived parameter => no comes from a dataset | |
173 | + paramInfo->setDatasetId(""); | |
174 | + | |
175 | + //set name and short name = param id | |
176 | + if (paramInfo->getName().empty()) | |
177 | + paramInfo->setName(parameter.getId()); | |
178 | + if (paramInfo->getShortName().empty()) | |
179 | + paramInfo->setShortName(parameter.getId()); | |
180 | + | |
181 | + std::string processInfo = "Derived parameter from expression '"; | |
182 | + processInfo += getExpression(); | |
183 | + processInfo += "'"; | |
184 | + | |
185 | + for (ParameterList::iterator itParam = _paramNameList.begin(); itParam != _paramNameList.end(); ++itParam) | |
186 | + paramInfo->addLinkedParamId(itParam->first); | |
187 | + | |
188 | + paramInfo->setProcessInfo(processInfo); | |
189 | + paramInfo->setProcessDescription(getDescription()); | |
190 | +} | |
191 | + | |
192 | +/* | |
193 | + * @brief Get min sampling | |
194 | + */ | |
195 | +double MultiParamProcess::getMinSampling() | |
196 | +{ | |
197 | + double minSampling = 0; | |
198 | + for (auto param : _paramNameList) | |
199 | + { | |
200 | + ParameterSPtr& parameter = param.second.first; | |
201 | + double paramMinSampling = 0; | |
202 | + if (parameter->getTimeResolution() > 0) | |
203 | + paramMinSampling = parameter->getTimeResolution(); | |
204 | + else if (parameter->getDataWriterTemplate() != nullptr) | |
205 | + paramMinSampling = parameter->getDataWriterTemplate()->getMinSampling(); | |
206 | + | |
207 | + if (minSampling == 0) | |
208 | + minSampling = paramMinSampling; | |
209 | + else if (paramMinSampling != 0) | |
210 | + minSampling = std::min(minSampling,paramMinSampling); | |
211 | + } | |
212 | + return minSampling; | |
213 | +} | |
214 | + | |
215 | + | |
216 | +} /* namespace Parameters */ | |
217 | +} /* namespace AMDA */ | ... | ... |
src/InternLib/SingleParamProcess.cc
1 | -/* | |
2 | - * SingleParamProcess.cc | |
3 | - * | |
4 | - * Created on: Feb 6, 2013 | |
5 | - * Author: f.casimir | |
6 | - */ | |
7 | - | |
8 | -#include "Operation.hh" | |
9 | -#include "ParamData.hh" | |
10 | -#include "SingleParamProcess.hh" | |
11 | -#include "ParameterCreatorFromExpression.hh" | |
12 | -#include "ParamMgr.hh" | |
13 | - | |
14 | -namespace AMDA { | |
15 | - namespace Parameters { | |
16 | - | |
17 | - SingleParamProcess::SingleParamProcess(Parameter ¶meter) : Process(parameter), _paramInput(NULL), _treatTerminated(false), _expressionParsed(false) | |
18 | - { | |
19 | - } | |
20 | - | |
21 | - SingleParamProcess::SingleParamProcess(const SingleParamProcess &pProcess, Parameter ¶meter) : | |
22 | - Process(pProcess,parameter), | |
23 | - _parameterInput(pProcess._parameterInput), | |
24 | - _paramInput(NULL), _treatTerminated(false), _expressionParsed(false) { | |
25 | - //Establish Connection Without Parse | |
26 | - _parameterInput->openConnection(this); | |
27 | - } | |
28 | - | |
29 | - SingleParamProcess::~SingleParamProcess() { | |
30 | - } | |
31 | - | |
32 | - void SingleParamProcess::parse() { | |
33 | - ParameterCreatorFromExpression creator(_parameter.getParameterManager()); | |
34 | - _parameterInput = creator.getOneParameterFromExpression(_parameter,_expression); | |
35 | - } | |
36 | - | |
37 | - | |
38 | - void SingleParamProcess::establishConnection() { | |
39 | - if (!_expressionParsed) | |
40 | - parse(); | |
41 | - _expressionParsed = true; | |
42 | - _parameterInput->openConnection(this); | |
43 | - } | |
44 | - | |
45 | - unsigned int SingleParamProcess::write() { | |
46 | - | |
47 | - int ret = 0; | |
48 | - unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber(); | |
49 | - ParamDataIndexInfo lParamDataIndexInfo; | |
50 | - | |
51 | - this->_treatTerminated = false; | |
52 | - | |
53 | - lParamDataIndexInfo =_parameterInput->getAsync(this).get(); | |
54 | - | |
55 | - while ((!lParamDataIndexInfo._noMoreTimeInt && !lParamDataIndexInfo._timeIntToProcessChanged) || (lParamDataIndexInfo._nbDataToProcess > 0)) | |
56 | - { | |
57 | - _operation->write(lParamDataIndexInfo); | |
58 | - ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; | |
59 | - lParamDataIndexInfo =_parameterInput->getAsync(this).get(); | |
60 | - } | |
61 | - | |
62 | - _operation->write(lParamDataIndexInfo); | |
63 | - ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; | |
64 | - | |
65 | - | |
66 | - // Reset operation to prepare static data for the next TimeInterval. | |
67 | - if (lParamDataIndexInfo._timeIntToProcessChanged) { | |
68 | - _paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber()); | |
69 | - _operation->reset(); | |
70 | - } | |
71 | - // There is no more time interval to process | |
72 | - else if (lParamDataIndexInfo._noMoreTimeInt) { | |
73 | - _paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber()); | |
74 | - } else { | |
75 | - // Nothing to do. | |
76 | - } | |
77 | - | |
78 | - // Pull up information on which time interval changed. | |
79 | - _paramData->getIndexInfo()._timeIntToProcessChanged = lParamDataIndexInfo._timeIntToProcessChanged; | |
80 | - _paramData->getIndexInfo()._noMoreTimeInt = lParamDataIndexInfo._noMoreTimeInt; | |
81 | - | |
82 | - if (lParamDataIndexInfo._nbDataToProcess > 0) | |
83 | - _paramData->updateDims(); | |
84 | - | |
85 | - return ret; | |
86 | - } | |
87 | - | |
88 | - /* | |
89 | - * @brief @ to know the resampling strategy to use. If it's true, the nearest value will be use | |
90 | - */ | |
91 | - bool SingleParamProcess::useNearestValue() | |
92 | - { | |
93 | - return _parameterInput->getDataWriterTemplate()->useNearestValue(); | |
94 | - } | |
95 | - | |
96 | - /** | |
97 | - * @brief update parameter info in relation to the process | |
98 | - */ | |
99 | - void SingleParamProcess::updateInfo(Parameter & parameter) | |
100 | - { | |
101 | - LOG4CXX_DEBUG(_logger, "SingleParamProcess::updateInfo - " << parameter.getId()); | |
102 | - | |
103 | - if (parameter.getInfoId().empty()) | |
104 | - parameter.setInfoId(parameter.getId()); | |
105 | - | |
106 | - //just clone param info from input parameter to processed parameter | |
107 | - AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->cloneParamInfoFromId(_parameterInput->getInfoId(), parameter.getInfoId()); | |
108 | - | |
109 | - if (paramInfo == nullptr) | |
110 | - return; | |
111 | - | |
112 | - //Derived parameter => no comes from a dataset | |
113 | - paramInfo->setDatasetId(""); | |
114 | - | |
115 | - std::string processInfo = "Single param process from '"; | |
116 | - processInfo += _parameterInput->getId(); | |
117 | - processInfo += "'"; | |
118 | - | |
119 | - paramInfo->addLinkedParamId(_parameterInput->getId()); | |
120 | - | |
121 | - paramInfo->setProcessInfo(processInfo); | |
122 | - } | |
123 | - | |
124 | - /* | |
125 | - * @brief Get min sampling | |
126 | - */ | |
127 | - double SingleParamProcess::getMinSampling() | |
128 | - { | |
129 | - if (!_expressionParsed) | |
130 | - parse(); | |
131 | - _expressionParsed = true; | |
132 | - if (_parameterInput == nullptr) | |
133 | - return 0; | |
134 | - if (_parameterInput->getTimeResolution() > 0) | |
135 | - return _parameterInput->getTimeResolution(); | |
136 | - if (_parameterInput->getDataWriterTemplate() == nullptr) | |
137 | - return 0; | |
138 | - return _parameterInput->getDataWriterTemplate()->getMinSampling(); | |
139 | - } | |
140 | - } /* namespace Parameters */ | |
141 | -} /* namespace AMDA */ | |
1 | +/* | |
2 | + * SingleParamProcess.cc | |
3 | + * | |
4 | + * Created on: Feb 6, 2013 | |
5 | + * Author: f.casimir | |
6 | + */ | |
7 | + | |
8 | +#include "Operation.hh" | |
9 | +#include "ParamData.hh" | |
10 | +#include "SingleParamProcess.hh" | |
11 | +#include "ParameterCreatorFromExpression.hh" | |
12 | +#include "ParamMgr.hh" | |
13 | + | |
14 | +namespace AMDA { | |
15 | + namespace Parameters { | |
16 | + | |
17 | + SingleParamProcess::SingleParamProcess(Parameter ¶meter) : Process(parameter), _paramInput(NULL), _treatTerminated(false), _expressionParsed(false) | |
18 | + { | |
19 | + } | |
20 | + | |
21 | + SingleParamProcess::SingleParamProcess(const SingleParamProcess &pProcess, Parameter ¶meter) : | |
22 | + Process(pProcess,parameter), | |
23 | + _parameterInput(pProcess._parameterInput), | |
24 | + _paramInput(NULL), _treatTerminated(false), _expressionParsed(false) { | |
25 | + //Establish Connection Without Parse | |
26 | + _parameterInput->openConnection(this); | |
27 | + } | |
28 | + | |
29 | + SingleParamProcess::~SingleParamProcess() { | |
30 | + } | |
31 | + | |
32 | + void SingleParamProcess::parse() { | |
33 | + ParameterCreatorFromExpression creator(_parameter.getParameterManager()); | |
34 | + _parameterInput = creator.getOneParameterFromExpression(_parameter,_expression); | |
35 | + } | |
36 | + | |
37 | + | |
38 | + void SingleParamProcess::establishConnection() { | |
39 | + if (!_expressionParsed) | |
40 | + parse(); | |
41 | + _expressionParsed = true; | |
42 | + _parameterInput->openConnection(this); | |
43 | + } | |
44 | + | |
45 | + unsigned int SingleParamProcess::write() { | |
46 | + | |
47 | + int ret = 0; | |
48 | + unsigned int nbDataBeforeCallProcess = _paramData->getDataNumber(); | |
49 | + ParamDataIndexInfo lParamDataIndexInfo; | |
50 | + | |
51 | + this->_treatTerminated = false; | |
52 | + | |
53 | + lParamDataIndexInfo =_parameterInput->getAsync(this).get(); | |
54 | + | |
55 | + while ((!lParamDataIndexInfo._noMoreTimeInt && !lParamDataIndexInfo._timeIntToProcessChanged) || (lParamDataIndexInfo._nbDataToProcess > 0)) | |
56 | + { | |
57 | + _operation->write(lParamDataIndexInfo); | |
58 | + ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; | |
59 | + lParamDataIndexInfo =_parameterInput->getAsync(this).get(); | |
60 | + } | |
61 | + | |
62 | + _operation->write(lParamDataIndexInfo); | |
63 | + | |
64 | + bool updateDims = (lParamDataIndexInfo._nbDataToProcess > 0) && (lParamDataIndexInfo._startIndex == 0); | |
65 | + | |
66 | + ret = _paramData->getDataNumber() - nbDataBeforeCallProcess; | |
67 | + | |
68 | + | |
69 | + // Reset operation to prepare static data for the next TimeInterval. | |
70 | + if (lParamDataIndexInfo._timeIntToProcessChanged) { | |
71 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber()); | |
72 | + _operation->reset(); | |
73 | + } | |
74 | + // There is no more time interval to process | |
75 | + else if (lParamDataIndexInfo._noMoreTimeInt) { | |
76 | + _paramData->getIndexInfo()._endTimeIntIndexList.push_back(_paramData->getDataNumber()); | |
77 | + } else { | |
78 | + // Nothing to do. | |
79 | + } | |
80 | + | |
81 | + // Pull up information on which time interval changed. | |
82 | + _paramData->getIndexInfo()._timeIntToProcessChanged = lParamDataIndexInfo._timeIntToProcessChanged; | |
83 | + _paramData->getIndexInfo()._noMoreTimeInt = lParamDataIndexInfo._noMoreTimeInt; | |
84 | + | |
85 | + if (updateDims) | |
86 | + _paramData->updateDims(); | |
87 | + | |
88 | + return ret; | |
89 | + } | |
90 | + | |
91 | + /* | |
92 | + * @brief @ to know the resampling strategy to use. If it's true, the nearest value will be use | |
93 | + */ | |
94 | + bool SingleParamProcess::useNearestValue() | |
95 | + { | |
96 | + return _parameterInput->getDataWriterTemplate()->useNearestValue(); | |
97 | + } | |
98 | + | |
99 | + /** | |
100 | + * @brief update parameter info in relation to the process | |
101 | + */ | |
102 | + void SingleParamProcess::updateInfo(Parameter & parameter) | |
103 | + { | |
104 | + LOG4CXX_DEBUG(_logger, "SingleParamProcess::updateInfo - " << parameter.getId()); | |
105 | + | |
106 | + if (parameter.getInfoId().empty()) | |
107 | + parameter.setInfoId(parameter.getId()); | |
108 | + | |
109 | + //just clone param info from input parameter to processed parameter | |
110 | + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->cloneParamInfoFromId(_parameterInput->getInfoId(), parameter.getInfoId()); | |
111 | + | |
112 | + if (paramInfo == nullptr) | |
113 | + return; | |
114 | + | |
115 | + //Derived parameter => no comes from a dataset | |
116 | + paramInfo->setDatasetId(""); | |
117 | + | |
118 | + std::string processInfo = "Single param process from '"; | |
119 | + processInfo += _parameterInput->getId(); | |
120 | + processInfo += "'"; | |
121 | + | |
122 | + paramInfo->addLinkedParamId(_parameterInput->getId()); | |
123 | + | |
124 | + paramInfo->setProcessInfo(processInfo); | |
125 | + } | |
126 | + | |
127 | + /* | |
128 | + * @brief Get min sampling | |
129 | + */ | |
130 | + double SingleParamProcess::getMinSampling() | |
131 | + { | |
132 | + if (!_expressionParsed) | |
133 | + parse(); | |
134 | + _expressionParsed = true; | |
135 | + if (_parameterInput == nullptr) | |
136 | + return 0; | |
137 | + if (_parameterInput->getTimeResolution() > 0) | |
138 | + return _parameterInput->getTimeResolution(); | |
139 | + if (_parameterInput->getDataWriterTemplate() == nullptr) | |
140 | + return 0; | |
141 | + return _parameterInput->getDataWriterTemplate()->getMinSampling(); | |
142 | + } | |
143 | + } /* namespace Parameters */ | |
144 | +} /* namespace AMDA */ | ... | ... |