Commit 06bc83c51b97c48f9cf14d8a338bc0b33674e547
1 parent
b358ee7d
Exists in
master
and in
94 other branches
Fix bug with sliding functions (#6547)
Showing
1 changed file
with
59 additions
and
45 deletions
Show diff stats
src/ExternLib/StatisticFunctions/AbstractFunc.hh
... | ... | @@ -95,7 +95,7 @@ public: |
95 | 95 | } |
96 | 96 | ++_currentTimeInterval; |
97 | 97 | _needInit = true; |
98 | - clear(); | |
98 | + resetFunc(); | |
99 | 99 | } |
100 | 100 | |
101 | 101 | virtual bool nextTarget() = 0; |
... | ... | @@ -104,9 +104,9 @@ public: |
104 | 104 | |
105 | 105 | virtual double getSampling() = 0; |
106 | 106 | |
107 | - virtual void init(double crtTime) = 0; | |
108 | - | |
109 | - virtual void clear() = 0; | |
107 | + virtual void init() = 0; | |
108 | + | |
109 | + virtual void resetFunc() = 0; | |
110 | 110 | |
111 | 111 | private: |
112 | 112 | TimeIntervalListSPtr _timeIntervalList; |
... | ... | @@ -144,48 +144,53 @@ public: |
144 | 144 | virtual void pushData(double time, InputElemType& elem) = 0; |
145 | 145 | |
146 | 146 | virtual OutputElemType compute() = 0; |
147 | - | |
147 | + | |
148 | 148 | /** |
149 | 149 | * @overload Operation::write(ParamDataIndexInfo &pParamDataIndexInfo) |
150 | 150 | */ |
151 | 151 | |
152 | 152 | void write(ParamDataIndexInfo &pParamDataIndexInfo) { |
153 | - bool isTerminated = false; | |
154 | 153 | if ((pParamDataIndexInfo._nbDataToProcess > 0)) { |
155 | 154 | if (pParamDataIndexInfo._startIndex == 0) { |
156 | 155 | _nanVal = _paramInput.get(0); |
157 | 156 | _nanVal << NotANumber(); |
158 | 157 | } |
159 | - for (unsigned int _index = pParamDataIndexInfo._startIndex ; | |
158 | + for (unsigned int _index = pParamDataIndexInfo._startIndex ; | |
160 | 159 | _index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; |
161 | 160 | ++_index) |
162 | 161 | { |
163 | 162 | double crtTime = _paramInput.getTime(_index); |
164 | - if (needInit()) { | |
165 | - init(crtTime); | |
166 | - } | |
167 | - InputElemType crtVal = _paramInput.get(_index); | |
168 | - while (needToChangeTarget(crtTime)) { | |
169 | - _paramOutput->pushTime(getTarget()); | |
170 | - _paramOutput->push(compute()); | |
171 | - if (!nextTarget()) { | |
172 | - isTerminated = true; | |
173 | - return; | |
174 | - } | |
175 | - clear(); | |
176 | - } | |
177 | - pushData(crtTime, crtVal); | |
163 | + InputElemType crtVal = _paramInput.get(_index); | |
164 | + bool skip = false; | |
165 | + if (needToChangeTarget(crtTime)) { | |
166 | + _paramOutput->pushTime(getTarget()); | |
167 | + _paramOutput->push(compute()); | |
168 | + pushData(crtTime, crtVal); | |
169 | + nextTarget(); | |
170 | + bool skip = false; | |
171 | + while (!skip && needToChangeTarget(crtTime)) { | |
172 | + _paramOutput->pushTime(getTarget()); | |
173 | + _paramOutput->push(compute()); | |
174 | + skip = nextTarget(); | |
175 | + } | |
176 | + } | |
177 | + else { | |
178 | + pushData(crtTime, crtVal); | |
179 | + if (needInit()) { | |
180 | + init(); | |
181 | + } | |
182 | + } | |
178 | 183 | } |
179 | 184 | } |
180 | 185 | if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) { |
186 | + if (!needInit()) { | |
181 | 187 | do { |
188 | + if (inInt(getTarget())) { | |
182 | 189 | _paramOutput->pushTime(getTarget()); |
183 | 190 | _paramOutput->push(compute()); |
184 | - if (!nextTarget()) { | |
185 | - isTerminated = true; | |
186 | - } | |
187 | - clear(); | |
188 | - } while (!isTerminated); | |
191 | + } | |
192 | + } while (nextTarget()); | |
193 | + } | |
189 | 194 | } |
190 | 195 | } |
191 | 196 | |
... | ... | @@ -212,18 +217,22 @@ public: |
212 | 217 | virtual ~ClassicAbstractFunc() { |
213 | 218 | } |
214 | 219 | |
215 | - virtual void init(double /*crtTime*/) { | |
220 | + virtual void init() { | |
216 | 221 | AbstractFunc<InputElemType,OutputElemType>::setTarget(AbstractFunc<InputElemType,OutputElemType>::getIntStartTime()); |
217 | 222 | AbstractFunc<InputElemType,OutputElemType>::setNeedInit(false); |
218 | 223 | } |
219 | 224 | |
220 | 225 | virtual bool nextTarget() { |
221 | 226 | double target = AbstractFunc<InputElemType,OutputElemType>::getTarget() + AbstractFunc<InputElemType,OutputElemType>::getWindowTime(); |
222 | - return AbstractFunc<InputElemType,OutputElemType>::setTarget(target); | |
227 | + bool res = AbstractFunc<InputElemType,OutputElemType>::setTarget(target); | |
228 | + while (!_mem.empty() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(_mem.front().first)) { | |
229 | + _mem.pop_front(); | |
230 | + } | |
231 | + return res; | |
223 | 232 | } |
224 | 233 | |
225 | 234 | virtual bool needToChangeTarget(double crtTime) { |
226 | - return !AbstractFunc<InputElemType,OutputElemType>::inWindow(crtTime); | |
235 | + return !AbstractFunc<InputElemType,OutputElemType>::needInit() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(crtTime); | |
227 | 236 | } |
228 | 237 | |
229 | 238 | virtual double getSampling() { |
... | ... | @@ -233,13 +242,13 @@ public: |
233 | 242 | virtual void pushData(double time, InputElemType& elem) { |
234 | 243 | _mem.push_back(std::make_pair(time, elem)); |
235 | 244 | } |
236 | - | |
237 | - virtual void clear() { | |
238 | - _mem.clear(); | |
239 | - } | |
245 | + | |
246 | + virtual void resetFunc() { | |
247 | + _mem.clear(); | |
248 | + } | |
240 | 249 | |
241 | 250 | protected: |
242 | - std::list<std::pair<double,InputElemType>> _mem; | |
251 | + std::list<std::pair<double,InputElemType> > _mem; | |
243 | 252 | }; |
244 | 253 | |
245 | 254 | template <typename InputElemType, typename OutputElemType> |
... | ... | @@ -252,22 +261,28 @@ public: |
252 | 261 | virtual ~SmAbstractFunc() { |
253 | 262 | } |
254 | 263 | |
255 | - virtual void init(double crtTime) { | |
256 | - AbstractFunc<InputElemType,OutputElemType>::setTarget(crtTime); | |
257 | - AbstractFunc<InputElemType,OutputElemType>::setNeedInit(false); | |
264 | + virtual void init() { | |
265 | + if (!_targets.empty()) { | |
266 | + AbstractFunc<InputElemType,OutputElemType>::setTarget(_targets.front()); | |
267 | + AbstractFunc<InputElemType,OutputElemType>::setNeedInit(false); | |
268 | + _targets.pop_front(); | |
269 | + } | |
258 | 270 | } |
259 | 271 | |
260 | 272 | virtual bool nextTarget() { |
261 | 273 | if (!_targets.empty()) { |
262 | 274 | bool res = AbstractFunc<InputElemType,OutputElemType>::setTarget(_targets.front()); |
263 | 275 | _targets.pop_front(); |
276 | + while (!_mem.empty() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(_mem.front().first)) { | |
277 | + _mem.pop_front(); | |
278 | + } | |
264 | 279 | return res; |
265 | 280 | } |
266 | 281 | return false; |
267 | 282 | } |
268 | 283 | |
269 | 284 | virtual bool needToChangeTarget(double crtTime) { |
270 | - return !AbstractFunc<InputElemType,OutputElemType>::inWindow(crtTime); | |
285 | + return !AbstractFunc<InputElemType,OutputElemType>::needInit() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(crtTime) && !_targets.empty() ; | |
271 | 286 | } |
272 | 287 | |
273 | 288 | virtual double getSampling() { |
... | ... | @@ -278,17 +293,16 @@ public: |
278 | 293 | _mem.push_back(std::make_pair(time, elem)); |
279 | 294 | _targets.push_back(time); |
280 | 295 | } |
281 | - | |
282 | - virtual void clear() { | |
283 | - while (!_mem.empty() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(_mem.front().first)) { | |
284 | - _mem.pop_front(); | |
285 | - } | |
286 | - } | |
296 | + | |
297 | + virtual void resetFunc() { | |
298 | + _mem.clear(); | |
299 | + _targets.clear(); | |
300 | + } | |
287 | 301 | |
288 | 302 | protected: |
289 | 303 | std::list<double> _targets; |
290 | 304 | |
291 | - std::list<std::pair<double,OutputElemType>> _mem; | |
305 | + std::list<std::pair<double,OutputElemType> > _mem; | |
292 | 306 | }; |
293 | 307 | |
294 | 308 | } /* namespace StatisticFunctions */ | ... | ... |