From 4e7b3226237de377793db0e01ce32155119851fc 2017-08-14 12:52:49 From: mperrinel Date: 2017-08-14 12:52:49 Subject: [PATCH] The dataSeries of a variable is now shared istead of uniq to avoid multithread bug between display and merge operation --- diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index b929238..04fac1c 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -25,7 +25,7 @@ struct Variable::VariablePrivate { SqpRange m_Range; SqpRange m_CacheRange; QVariantHash m_Metadata; - std::unique_ptr m_DataSeries; + std::shared_ptr m_DataSeries; QReadWriteLock m_Lock; }; @@ -75,7 +75,8 @@ void Variable::setCacheRange(const SqpRange &cacheRange) noexcept void Variable::setDataSeries(std::shared_ptr dataSeries) noexcept { - qCInfo(LOG_Variable()) << "Variable::setDataSeries" << QThread::currentThread()->objectName(); + qCDebug(LOG_Variable()) << "TORM Variable::setDataSeries" + << QThread::currentThread()->objectName(); if (!dataSeries) { /// @todo ALX : log return; @@ -87,7 +88,7 @@ void Variable::setDataSeries(std::shared_ptr dataSeries) noexcept void Variable::mergeDataSeries(std::shared_ptr dataSeries) noexcept { - qCDebug(LOG_Variable()) << "Variable::mergeDataSeries" + qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries" << QThread::currentThread()->objectName(); if (!dataSeries) { /// @todo ALX : log @@ -107,16 +108,15 @@ void Variable::mergeDataSeries(std::shared_ptr dataSeries) noexcept // sub the data auto subData = this->dataSeries()->subData(this->cacheRange()); - qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); + qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries sub" << subData->range(); this->setDataSeries(subData); - qCCritical(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" - << this->dataSeries()->range(); + qCDebug(LOG_Variable()) << "TORM: Variable::mergeDataSeries set" << this->dataSeries()->range(); } -IDataSeries *Variable::dataSeries() const noexcept +std::shared_ptr Variable::dataSeries() const noexcept { impl->lockRead(); - auto dataSeries = impl->m_DataSeries.get(); + auto dataSeries = impl->m_DataSeries; impl->unlock(); return dataSeries; diff --git a/core/src/Variable/VariableAcquisitionWorker.cpp b/core/src/Variable/VariableAcquisitionWorker.cpp index ae8a0e9..e84ab16 100644 --- a/core/src/Variable/VariableAcquisitionWorker.cpp +++ b/core/src/Variable/VariableAcquisitionWorker.cpp @@ -51,7 +51,7 @@ void VariableAcquisitionWorker::pushVariableRequest(QUuid vIdentifier, SqpRange DataProviderParameters parameters, std::shared_ptr provider) { - qCDebug(LOG_VariableAcquisitionWorker()) + qCInfo(LOG_VariableAcquisitionWorker()) << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; // Request creation @@ -173,7 +173,7 @@ void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) { - qCDebug(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); + qCInfo(LOG_VariableAcquisitionWorker()) << tr("onExecuteRequest") << QThread::currentThread(); impl->lockRead(); auto it = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 50bc7a1..b2703f8 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -274,6 +274,7 @@ void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &range qCDebug(LOG_VariableController()) << tr("3: onDataProvided") << retrievedDataSeries->range(); var->mergeDataSeries(retrievedDataSeries); + qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); emit var->updated(); } else { @@ -358,8 +359,8 @@ void VariableController::onRequestDataLoading(QVector { // NOTE: oldRange isn't really necessary since oldRange == variable->range(). - qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" - << QThread::currentThread()->objectName(); + qCInfo(LOG_VariableController()) << "VariableController::onRequestDataLoading" + << QThread::currentThread()->objectName(); // we want to load data of the variable for the dateTime. // First we check if the cache contains some of them. // For the other, we ask the provider to give them. @@ -466,8 +467,6 @@ void VariableController::VariableControllerPrivate::processRequest(std::shared_p auto notInCacheRangeList = var->provideNotInCacheRangeList(varRangesRequested.second); if (!notInCacheRangeList.empty()) { - // Display part of data which are already there - // Ask the provider for each data on the dateTimeListNotInCache auto identifier = m_VariableToIdentifierMap.at(var); auto varProvider = m_VariableToProviderMap.at(var); if (varProvider != nullptr) { @@ -511,8 +510,8 @@ VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) std::shared_ptr VariableController::VariableControllerPrivate::retrieveDataSeries( const QVector acqDataPacketVector) { - qCInfo(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") - << acqDataPacketVector.size(); + qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") + << acqDataPacketVector.size(); std::shared_ptr dataSeries; if (!acqDataPacketVector.isEmpty()) { dataSeries = acqDataPacketVector[0].m_DateSeries; @@ -520,7 +519,8 @@ std::shared_ptr VariableController::VariableControllerPrivate::retr dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); } } - + qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") + << acqDataPacketVector.size(); return dataSeries; } @@ -528,8 +528,8 @@ void VariableController::VariableControllerPrivate::registerProvider( std::shared_ptr provider) { if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { - qCInfo(LOG_VariableController()) << tr("Registering of a new provider") - << provider->objectName(); + qCDebug(LOG_VariableController()) << tr("Registering of a new provider") + << provider->objectName(); m_ProviderSet.insert(provider); connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::onVariableDataAcquired); diff --git a/gui/include/Visualization/VisualizationGraphHelper.h b/gui/include/Visualization/VisualizationGraphHelper.h index efdb6f2..c0d4b3d 100644 --- a/gui/include/Visualization/VisualizationGraphHelper.h +++ b/gui/include/Visualization/VisualizationGraphHelper.h @@ -31,8 +31,8 @@ struct VisualizationGraphHelper { static QVector create(std::shared_ptr variable, QCustomPlot &plot) noexcept; - static void updateData(QVector plotableVect, IDataSeries *dataSeries, - const SqpRange &dateTime); + static void updateData(QVector plotableVect, + std::shared_ptr dataSeries, const SqpRange &dateTime); }; #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index b0a98c7..a67534c 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -35,21 +35,21 @@ QSharedPointer axisTicker(bool isTimeAxis) } } -void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries, +void updateScalarData(QCPAbstractPlottable *component, std::shared_ptr scalarSeries, const SqpRange &dateTime) { qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData" << QThread::currentThread()->objectName(); if (auto qcpGraph = dynamic_cast(component)) { - scalarSeries.lockRead(); + scalarSeries->lockRead(); { - const auto &xData = scalarSeries.xAxisData()->cdata(); - const auto &valuesData = scalarSeries.valuesData()->cdata(); + const auto &xData = scalarSeries->xAxisData()->cdata(); + const auto &valuesData = scalarSeries->valuesData()->cdata(); auto xDataBegin = xData.cbegin(); auto xDataEnd = xData.cend(); - qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" + qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points in cache" << xData.count(); auto sqpDataContainer = QSharedPointer::create(); @@ -65,10 +65,10 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie sqpDataContainer->appendGraphData(QCPGraphData(*xAxisDataIt, *valuesDataIt)); } - qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" + qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points displayed" << sqpDataContainer->size(); } - scalarSeries.unlock(); + scalarSeries->unlock(); // Display all data @@ -79,14 +79,14 @@ void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie } } -QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot, - const SqpRange &dateTime) +QCPAbstractPlottable *createScalarSeriesComponent(std::shared_ptr scalarSeries, + QCustomPlot &plot, const SqpRange &dateTime) { auto component = plot.addGraph(); if (component) { // // Graph data - component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), + component->setData(scalarSeries->xAxisData()->data(), scalarSeries->valuesData()->data(), true); updateScalarData(component, scalarSeries, dateTime); @@ -102,8 +102,8 @@ QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QC // ticker (depending on the type of unit) axis->setTicker(axisTicker(unit.m_TimeUnit)); }; - setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); - setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); + setAxisProperties(plot.xAxis, scalarSeries->xAxisUnit()); + setAxisProperties(plot.yAxis, scalarSeries->valuesUnit()); // Display all data component->rescaleAxes(); @@ -127,8 +127,8 @@ QVector VisualizationGraphHelper::create(std::shared_ptr if (variable) { // Gets the data series of the variable to call the creation of the right components // according to its type - if (auto scalarSeries = dynamic_cast(variable->dataSeries())) { - result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->range())); + if (auto scalarSeries = std::dynamic_pointer_cast(variable->dataSeries())) { + result.append(createScalarSeriesComponent(scalarSeries, plot, variable->range())); } else { qCDebug(LOG_VisualizationGraphHelper()) @@ -144,11 +144,12 @@ QVector VisualizationGraphHelper::create(std::shared_ptr } void VisualizationGraphHelper::updateData(QVector plotableVect, - IDataSeries *dataSeries, const SqpRange &dateTime) + std::shared_ptr dataSeries, + const SqpRange &dateTime) { - if (auto scalarSeries = dynamic_cast(dataSeries)) { + if (auto scalarSeries = std::dynamic_pointer_cast(dataSeries)) { if (plotableVect.size() == 1) { - updateScalarData(plotableVect.at(0), *scalarSeries, dateTime); + updateScalarData(plotableVect.at(0), scalarSeries, dateTime); } else { qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr( diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index bc6a4e7..1ed0384 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -235,7 +235,7 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange !impl->m_IsCalibration); if (!impl->m_IsCalibration) { - qCInfo(LOG_VisualizationGraphWidget()) + qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") << QThread::currentThread()->objectName() << graphRange << oldGraphRange; emit synchronize(graphRange, oldGraphRange); diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index ec77d32..ab3b4c0 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -81,6 +81,7 @@ void CosinusProvider::requestDataLoading(QUuid acqIdentifier, for (const auto &dateTime : qAsConst(times)) { if (m_VariableToEnableProvider[acqIdentifier]) { auto scalarSeries = this->retrieveData(acqIdentifier, dateTime); + qCCritical(LOG_CosinusProvider()) << "CosinusProvider::dataProvided"; emit dataProvided(acqIdentifier, scalarSeries, dateTime); } }