##// END OF EJS Templates
Merge branch 'feature/fixAcquisitionSynchroBug' into develop
perrinel -
r824:60a224a1b89a merge
parent child
Show More
@@ -68,6 +68,12 public:
68 68 QVector<SqpRange> provideInCacheRangeList(const SqpRange &range) const noexcept;
69 69 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
70 70
71 static QVector<SqpRange> provideNotInCacheRangeList(const SqpRange &oldRange,
72 const SqpRange &nextRange);
73
74 static QVector<SqpRange> provideInCacheRangeList(const SqpRange &oldRange,
75 const SqpRange &nextRange);
76
71 77 signals:
72 78 void updated();
73 79
@@ -138,7 +138,6 void Variable::setCacheRange(const SqpRange &cacheRange) noexcept
138 138 impl->lockWrite();
139 139 if (cacheRange != impl->m_CacheRange) {
140 140 impl->m_CacheRange = cacheRange;
141 impl->purgeDataSeries();
142 141 }
143 142 impl->unlock();
144 143 }
@@ -174,6 +173,7 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
174 173 impl->unlock();
175 174 }
176 175
176
177 177 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
178 178 {
179 179 impl->lockRead();
@@ -285,7 +285,7 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
285 285
286 286 if (impl->m_CacheRange != INVALID_RANGE) {
287 287
288 if (this->intersect(range)) {
288 if (this->cacheIntersect(range)) {
289 289 if (range.m_TStart <= impl->m_CacheRange.m_TStart
290 290 && range.m_TEnd >= impl->m_CacheRange.m_TStart
291 291 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
@@ -313,3 +313,76 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &range) const
313 313
314 314 return inCache;
315 315 }
316
317
318 QVector<SqpRange> Variable::provideNotInCacheRangeList(const SqpRange &oldRange,
319 const SqpRange &nextRange)
320 {
321
322 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
323 auto notInCache = QVector<SqpRange>{};
324 if (oldRange != INVALID_RANGE) {
325
326 if (!oldRange.contains(nextRange)) {
327 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
328 notInCache << nextRange;
329 }
330 else if (nextRange.m_TStart < oldRange.m_TStart
331 && nextRange.m_TEnd <= oldRange.m_TEnd) {
332 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart};
333 }
334 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
335 notInCache << SqpRange{nextRange.m_TStart, oldRange.m_TStart}
336 << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
337 }
338 else if (nextRange.m_TStart < oldRange.m_TEnd) {
339 notInCache << SqpRange{oldRange.m_TEnd, nextRange.m_TEnd};
340 }
341 else {
342 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
343 << QThread::currentThread();
344 }
345 }
346 }
347 else {
348 notInCache << nextRange;
349 }
350
351 return notInCache;
352 }
353
354 QVector<SqpRange> Variable::provideInCacheRangeList(const SqpRange &oldRange,
355 const SqpRange &nextRange)
356 {
357 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
358
359 auto inCache = QVector<SqpRange>{};
360
361 if (oldRange != INVALID_RANGE) {
362
363 if (oldRange.intersect(nextRange)) {
364 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
365 && nextRange.m_TEnd < oldRange.m_TEnd) {
366 inCache << SqpRange{oldRange.m_TStart, nextRange.m_TEnd};
367 }
368
369 else if (nextRange.m_TStart >= oldRange.m_TStart
370 && nextRange.m_TEnd <= oldRange.m_TEnd) {
371 inCache << nextRange;
372 }
373 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
374 inCache << SqpRange{nextRange.m_TStart, oldRange.m_TEnd};
375 }
376 else if (nextRange.m_TStart <= oldRange.m_TStart
377 && nextRange.m_TEnd >= oldRange.m_TEnd) {
378 inCache << oldRange;
379 }
380 else {
381 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
382 << QThread::currentThread();
383 }
384 }
385 }
386
387 return inCache;
388 }
@@ -32,6 +32,10 struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate {
32 32 /// Remove the current request and execute the next one if exist
33 33 void updateToNextRequest(QUuid vIdentifier);
34 34
35 /// Remove and/or abort all AcqRequest in link with varRequestId
36 void cancelVarRequest(QUuid varRequestId);
37 void removeAcqRequest(QUuid acqRequestId);
38
35 39 QMutex m_WorkingMutex;
36 40 QReadWriteLock m_Lock;
37 41
@@ -67,7 +71,8 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
67 71
68 72 // Request creation
69 73 auto acqRequest = AcquisitionRequest{};
70 qCInfo(LOG_VariableAcquisitionWorker()) << tr("TpushVariableRequest ") << vIdentifier;
74 qCDebug(LOG_VariableAcquisitionWorker()) << tr("PushVariableRequest ") << vIdentifier
75 << varRequestId;
71 76 acqRequest.m_VarRequestId = varRequestId;
72 77 acqRequest.m_vIdentifier = vIdentifier;
73 78 acqRequest.m_DataProviderParameters = parameters;
@@ -85,15 +90,19 QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v
85 90 auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
86 91 if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
87 92 // A current request already exists, we can replace the next one
88 auto nextAcqId = it->second.second;
89 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(nextAcqId);
93 auto oldAcqId = it->second.second;
94 auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId);
90 95 if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) {
91 auto request = acqIdentifierToAcqRequestMapIt->second;
92 varRequestIdCanceled = request.m_VarRequestId;
96 auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second;
97 varRequestIdCanceled = oldAcqRequest.m_VarRequestId;
93 98 }
94 99
95 100 it->second.second = acqRequest.m_AcqIdentifier;
96 101 impl->unlock();
102
103 // remove old acqIdentifier from the worker
104 impl->cancelVarRequest(varRequestIdCanceled);
105 // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId);
97 106 }
98 107 else {
99 108 // First request for the variable, it must be stored and executed
@@ -122,10 +131,7 void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier)
122 131 impl->unlock();
123 132
124 133 // Remove the current request from the worker
125
126 impl->lockWrite();
127 134 impl->updateToNextRequest(vIdentifier);
128 impl->unlock();
129 135
130 136 // notify the request aborting to the provider
131 137 request.m_Provider->requestDataAborting(currentAcqId);
@@ -221,22 +227,28 void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier,
221 227 // if the counter is 0, we can return data then run the next request if it exists and
222 228 // removed the finished request
223 229 if (acqRequest.m_Size == acqRequest.m_Progression) {
230 auto varId = acqRequest.m_vIdentifier;
231 auto rangeRequested = acqRequest.m_RangeRequested;
232 auto cacheRangeRequested = acqRequest.m_CacheRangeRequested;
224 233 // Return the data
225 234 aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier);
226 235 if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) {
227 emit dataProvided(acqRequest.m_vIdentifier, acqRequest.m_RangeRequested,
228 acqRequest.m_CacheRangeRequested, aIdToADPVit->second);
236 emit dataProvided(varId, rangeRequested, cacheRangeRequested, aIdToADPVit->second);
229 237 }
238 impl->unlock();
230 239
231 240 // Update to the next request
232 241 impl->updateToNextRequest(acqRequest.m_vIdentifier);
233 242 }
243 else {
244 impl->unlock();
245 }
234 246 }
235 247 else {
248 impl->unlock();
236 249 qCWarning(LOG_VariableAcquisitionWorker())
237 250 << tr("Impossible to retrieve AcquisitionRequest for the incoming data.");
238 251 }
239 impl->unlock();
240 252 }
241 253
242 254 void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier)
@@ -296,27 +308,109 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable
296 308 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest(
297 309 QUuid vIdentifier)
298 310 {
311 lockRead();
299 312 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
300 313 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
301 314 if (it->second.second.isNull()) {
315 unlock();
302 316 // There is no next request, we can remove the variable request
303 317 removeVariableRequest(vIdentifier);
304 318 }
305 319 else {
306 320 auto acqIdentifierToRemove = it->second.first;
307 321 // Move the next request to the current request
308 it->second.first = it->second.second;
322 auto nextRequestId = it->second.second;
323 it->second.first = nextRequestId;
309 324 it->second.second = QUuid();
325 unlock();
310 326 // Remove AcquisitionRequest and results;
327 lockWrite();
311 328 m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove);
312 329 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove);
330 unlock();
313 331 // Execute the current request
314 332 QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection,
315 Q_ARG(QUuid, it->second.first));
333 Q_ARG(QUuid, nextRequestId));
316 334 }
317 335 }
318 336 else {
337 unlock();
319 338 qCCritical(LOG_VariableAcquisitionWorker())
320 339 << tr("Impossible to execute the acquisition on an unfound variable ");
321 340 }
322 341 }
342
343 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest(
344 QUuid varRequestId)
345 {
346 qCDebug(LOG_VariableAcquisitionWorker())
347 << "VariableAcquisitionWorkerPrivate::cancelVarRequest 0";
348 lockRead();
349 // get all AcqIdentifier in link with varRequestId
350 QVector<QUuid> acqIdsToRm;
351 auto cend = m_AcqIdentifierToAcqRequestMap.cend();
352 for (auto it = m_AcqIdentifierToAcqRequestMap.cbegin(); it != cend; ++it) {
353 if (it->second.m_VarRequestId == varRequestId) {
354 acqIdsToRm << it->first;
355 }
356 }
357 unlock();
358 // run aborting or removing of acqIdsToRm
359
360 for (auto acqId : acqIdsToRm) {
361 removeAcqRequest(acqId);
362 }
363 qCDebug(LOG_VariableAcquisitionWorker())
364 << "VariableAcquisitionWorkerPrivate::cancelVarRequest end";
365 }
366
367 void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqRequest(
368 QUuid acqRequestId)
369 {
370 qCDebug(LOG_VariableAcquisitionWorker())
371 << "VariableAcquisitionWorkerPrivate::removeAcqRequest";
372 QUuid vIdentifier;
373 std::shared_ptr<IDataProvider> provider;
374 lockRead();
375 auto acqIt = m_AcqIdentifierToAcqRequestMap.find(acqRequestId);
376 if (acqIt != m_AcqIdentifierToAcqRequestMap.cend()) {
377 vIdentifier = acqIt->second.m_vIdentifier;
378 provider = acqIt->second.m_Provider;
379
380 auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier);
381 if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) {
382 if (it->second.first == acqRequestId) {
383 // acqRequest is currently running -> let's aborting it
384 unlock();
385
386 // Remove the current request from the worker
387 updateToNextRequest(vIdentifier);
388
389 // notify the request aborting to the provider
390 provider->requestDataAborting(acqRequestId);
391 }
392 else if (it->second.second == acqRequestId) {
393 it->second.second = QUuid();
394 unlock();
395 }
396 else {
397 unlock();
398 }
399 }
400 else {
401 unlock();
402 }
403 }
404 else {
405 unlock();
406 }
407
408 lockWrite();
409
410 m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId);
411 m_AcqIdentifierToAcqRequestMap.erase(acqRequestId);
412
413 unlock();
414 qCDebug(LOG_VariableAcquisitionWorker())
415 << "VariableAcquisitionWorkerPrivate::removeAcqRequest END";
416 }
@@ -105,9 +105,6 struct VariableController::VariableControllerPrivate {
105 105 void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested,
106 106 QUuid varRequestId);
107 107
108 QVector<SqpRange> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
109 const SqpRange &dateTime);
110
111 108 std::shared_ptr<Variable> findVariable(QUuid vIdentifier);
112 109 std::shared_ptr<IDataSeries>
113 110 retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector);
@@ -554,23 +551,23 AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const
554 551 // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd
555 552 auto zoomType = AcquisitionZoomType::Unknown;
556 553 if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) {
557 qCCritical(LOG_VariableController()) << "zoomtype: ZoomOut";
554 qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut";
558 555 zoomType = AcquisitionZoomType::ZoomOut;
559 556 }
560 557 else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) {
561 qCCritical(LOG_VariableController()) << "zoomtype: PanRight";
558 qCDebug(LOG_VariableController()) << "zoomtype: PanRight";
562 559 zoomType = AcquisitionZoomType::PanRight;
563 560 }
564 561 else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) {
565 qCCritical(LOG_VariableController()) << "zoomtype: PanLeft";
562 qCDebug(LOG_VariableController()) << "zoomtype: PanLeft";
566 563 zoomType = AcquisitionZoomType::PanLeft;
567 564 }
568 565 else if (range.m_TStart > oldRange.m_TStart && oldRange.m_TEnd > range.m_TEnd) {
569 qCCritical(LOG_VariableController()) << "zoomtype: ZoomIn";
566 qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn";
570 567 zoomType = AcquisitionZoomType::ZoomIn;
571 568 }
572 569 else {
573 qCCritical(LOG_VariableController()) << "getZoomType: Unknown type detected";
570 qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected";
574 571 }
575 572 return zoomType;
576 573 }
@@ -596,13 +593,10 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
596 593 auto varStrategyRangesRequested
597 594 = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested);
598 595
599 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
600 auto inCacheRangeList = QVector<SqpRange>{};
601 if (m_VarIdToVarRequestIdQueueMap.find(varId) == m_VarIdToVarRequestIdQueueMap.cend()) {
602 notInCacheRangeList
603 = var->provideNotInCacheRangeList(varStrategyRangesRequested.second);
604 inCacheRangeList = var->provideInCacheRangeList(varStrategyRangesRequested.second);
605 }
596 auto notInCacheRangeList
597 = Variable::provideNotInCacheRangeList(oldRange, varStrategyRangesRequested.second);
598 auto inCacheRangeList
599 = Variable::provideInCacheRangeList(oldRange, varStrategyRangesRequested.second);
606 600
607 601 if (!notInCacheRangeList.empty()) {
608 602 varRequest.m_RangeRequested = varStrategyRangesRequested.first;
@@ -620,7 +614,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
620 614 varProvider);
621 615
622 616 if (!varRequestIdCanceled.isNull()) {
623 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
617 qCInfo(LOG_VariableAcquisitionWorker()) << tr("varRequestIdCanceled: ")
624 618 << varRequestIdCanceled;
625 619 cancelVariableRequest(varRequestIdCanceled);
626 620 }
@@ -804,26 +798,22 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
804 798 var->setRange(varRequest.m_RangeRequested);
805 799 var->setCacheRange(varRequest.m_CacheRangeRequested);
806 800 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
807 << varRequest.m_RangeRequested;
808 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
801 << varRequest.m_RangeRequested
809 802 << varRequest.m_CacheRangeRequested;
803 qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before")
804 << var->nbPoints()
805 << varRequest.m_DataSeries->nbPoints();
810 806 var->mergeDataSeries(varRequest.m_DataSeries);
811 qCDebug(LOG_VariableController()) << tr("3: onDataProvided");
807 qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after")
808 << var->nbPoints();
812 809
813 /// @todo MPL: confirm
814 // Variable update is notified only if there is no pending request for it
815 // if
816 // (m_VarIdToVarRequestIdQueueMap.count(varIdToVarRequestMapIt->first)
817 // == 0) {
818 810 emit var->updated();
819 // }
820 811 }
821 812 else {
822 813 qCCritical(LOG_VariableController())
823 814 << tr("Impossible to update data to a null variable");
824 815 }
825 816 }
826
827 817 // cleaning varRequestId
828 818 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
829 819 << m_VarRequestIdToVarIdVarRequestMap.size();
@@ -852,6 +842,8 void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid
852 842 if (varRequestIdQueue.empty()) {
853 843 varIdToVarRequestIdQueueMapIt
854 844 = m_VarIdToVarRequestIdQueueMap.erase(varIdToVarRequestIdQueueMapIt);
845
846 // Recompute if there is any next request based on the removed request.
855 847 }
856 848 else {
857 849 ++varIdToVarRequestIdQueueMapIt;
@@ -180,7 +180,6 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
180 180 for (const auto &dateTime : qAsConst(times)) {
181 181 if (m_VariableToEnableProvider[acqIdentifier]) {
182 182 auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data);
183 qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::dataProvided";
184 183 emit dataProvided(acqIdentifier, scalarSeries, dateTime);
185 184 }
186 185 }
@@ -188,7 +187,6 void CosinusProvider::requestDataLoading(QUuid acqIdentifier,
188 187
189 188 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
190 189 {
191 // TODO: Add Mutex
192 190 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier
193 191 << QThread::currentThread()->objectName();
194 192 auto it = m_VariableToEnableProvider.find(acqIdentifier);
@@ -196,7 +194,7 void CosinusProvider::requestDataAborting(QUuid acqIdentifier)
196 194 it.value() = false;
197 195 }
198 196 else {
199 qCWarning(LOG_CosinusProvider())
197 qCDebug(LOG_CosinusProvider())
200 198 << tr("Aborting progression of inexistant identifier detected !!!");
201 199 }
202 200 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now