##// END OF EJS Templates
@@ -0,0 +1,35
1 #ifndef CACHESTRATEGYFACTORY_H
2 #define CACHESTRATEGYFACTORY_H
3
4
5 #include <memory>
6 #include <stdexcept>
7
8 #include "VariableCacheStrategy.h"
9 #include "singlethresholdcachestrategy.h"
10
11
12 enum class CacheStrategy { SingleThreshold, TwoThreashold };
13
14
15 class CacheStrategyFactory {
16
17 using cacheStratPtr = std::unique_ptr<VariableCacheStrategy>;
18
19 public:
20 static cacheStratPtr createCacheStrategy(CacheStrategy specificStrategy)
21 {
22 switch (specificStrategy) {
23 case CacheStrategy::SingleThreshold:
24 return std::unique_ptr<VariableCacheStrategy>{new SingleThresholdCacheStrategy{}};
25
26 case CacheStrategy::TwoThreashold:
27 throw std::runtime_error("cache strategy not implemented yet");
28 }
29
30 throw std::runtime_error("Unknown cache strategy");
31 }
32 };
33
34
35 #endif // CACHESTRATEGYFACTORY_H
@@ -0,0 +1,32
1 #ifndef SINGLETHRESHOLDCACHESTRATEGY_H
2 #define SINGLETHRESHOLDCACHESTRATEGY_H
3
4 #include "Settings/SqpSettingsDefs.h"
5 #include "VariableCacheStrategy.h"
6
7
8 /// This class aims to hande the cache strategy.
9 class SCIQLOP_CORE_EXPORT SingleThresholdCacheStrategy : public VariableCacheStrategy {
10 public:
11 SingleThresholdCacheStrategy() = default;
12
13 std::pair<SqpRange, SqpRange> computeRange(const SqpRange &vRange,
14 const SqpRange &rangeRequested) override
15 {
16
17 auto varRanges = std::pair<SqpRange, SqpRange>{};
18
19 auto toleranceFactor = SqpSettings::toleranceValue(
20 GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
21 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
22
23 varRanges.first = rangeRequested;
24 varRanges.second
25 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
26
27 return varRanges;
28 }
29 };
30
31
32 #endif // SINGLETHRESHOLDCACHESTRATEGY_H
@@ -21,20 +21,17 class Variable;
21 /**
21 /**
22 * Possible types of zoom operation
22 * Possible types of zoom operation
23 */
23 */
24 enum class CacheStrategy { FixedTolerance, TwoThreashold };
24 // enum class CacheStrategy { FixedTolerance, TwoThreashold };
25
25
26 /// This class aims to hande the cache strategy.
27 class SCIQLOP_CORE_EXPORT VariableCacheStrategy : public QObject {
28 Q_OBJECT
29 public:
30 explicit VariableCacheStrategy(QObject *parent = 0);
31
26
32 std::pair<SqpRange, SqpRange> computeStrategyRanges(const SqpRange &vRange,
27 /// This class aims to hande the cache strategy.
33 const SqpRange &rangeRequested);
28 class SCIQLOP_CORE_EXPORT VariableCacheStrategy {
34
29
35 private:
30 public:
36 class VariableCacheStrategyPrivate;
31 virtual std::pair<SqpRange, SqpRange> computeRange(const SqpRange &vRange,
37 spimpl::unique_impl_ptr<VariableCacheStrategyPrivate> impl;
32 const SqpRange &rangeRequested)
33 = 0;
38 };
34 };
39
35
36
40 #endif // SCIQLOP_VARIABLECACHESTRATEGY_H
37 #endif // SCIQLOP_VARIABLECACHESTRATEGY_H
@@ -1,52 +0,0
1 #include "Variable/VariableCacheStrategy.h"
2
3 #include "Settings/SqpSettingsDefs.h"
4
5 #include "Variable/Variable.h"
6 #include "Variable/VariableController.h"
7
8 Q_LOGGING_CATEGORY(LOG_VariableCacheStrategy, "VariableCacheStrategy")
9
10 struct VariableCacheStrategy::VariableCacheStrategyPrivate {
11 VariableCacheStrategyPrivate() : m_CacheStrategy{CacheStrategy::FixedTolerance} {}
12
13 CacheStrategy m_CacheStrategy;
14 };
15
16
17 VariableCacheStrategy::VariableCacheStrategy(QObject *parent)
18 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheStrategyPrivate>()}
19 {
20 }
21
22 std::pair<SqpRange, SqpRange>
23 VariableCacheStrategy::computeStrategyRanges(const SqpRange &vRange, const SqpRange &rangeRequested)
24 {
25
26 auto varRanges = std::pair<SqpRange, SqpRange>{};
27
28 auto toleranceFactor = SqpSettings::toleranceValue(GENERAL_TOLERANCE_AT_UPDATE_KEY,
29 GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE);
30 auto tolerance = toleranceFactor * (rangeRequested.m_TEnd - rangeRequested.m_TStart);
31
32 switch (impl->m_CacheStrategy) {
33 case CacheStrategy::FixedTolerance: {
34 varRanges.first = rangeRequested;
35 varRanges.second
36 = SqpRange{rangeRequested.m_TStart - tolerance, rangeRequested.m_TEnd + tolerance};
37 break;
38 }
39
40 case CacheStrategy::TwoThreashold: {
41 // TODO Implement
42 break;
43 }
44 default:
45 qCCritical(LOG_VariableCacheStrategy())
46 << tr("Impossible to use compute the cache range with an unknow cache strategy");
47 // No action
48 break;
49 }
50
51 return varRanges;
52 }
@@ -4,6 +4,7
4 #include <Variable/VariableController.h>
4 #include <Variable/VariableController.h>
5 #include <Variable/VariableModel.h>
5 #include <Variable/VariableModel.h>
6 #include <Variable/VariableSynchronizationGroup.h>
6 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/cachestrategyfactory.h>
7
8
8 #include <Data/DataProviderParameters.h>
9 #include <Data/DataProviderParameters.h>
9 #include <Data/IDataProvider.h>
10 #include <Data/IDataProvider.h>
@@ -79,7 +80,9 struct VariableController::VariableControllerPrivate {
79 : m_WorkingMutex{},
80 : m_WorkingMutex{},
80 m_VariableModel{new VariableModel{parent}},
81 m_VariableModel{new VariableModel{parent}},
81 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
82 m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
83 // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()},
84 m_VariableCacheStrategy{
85 CacheStrategyFactory::createCacheStrategy(CacheStrategy::SingleThreshold)},
83 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
86 m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()},
84 q{parent}
87 q{parent}
85 {
88 {
@@ -145,8 +148,8 struct VariableController::VariableControllerPrivate {
145 VariableController::VariableController(QObject *parent)
148 VariableController::VariableController(QObject *parent)
146 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
149 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
147 {
150 {
148 qCDebug(LOG_VariableController()) << tr("VariableController construction")
151 qCDebug(LOG_VariableController())
149 << QThread::currentThread();
152 << tr("VariableController construction") << QThread::currentThread();
150
153
151 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
154 connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this,
152 &VariableController::onAbortProgressRequested);
155 &VariableController::onAbortProgressRequested);
@@ -173,8 +176,8 VariableController::VariableController(QObject *parent)
173
176
174 VariableController::~VariableController()
177 VariableController::~VariableController()
175 {
178 {
176 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
179 qCDebug(LOG_VariableController())
177 << QThread::currentThread();
180 << tr("VariableController destruction") << QThread::currentThread();
178 this->waitForFinish();
181 this->waitForFinish();
179 }
182 }
180
183
@@ -293,8 +296,8 VariableController::createVariable(const QString &name, const QVariantHash &meta
293 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
296 void VariableController::onDateTimeOnSelection(const SqpRange &dateTime)
294 {
297 {
295 // TODO check synchronisation and Rescale
298 // TODO check synchronisation and Rescale
296 qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection"
299 qCDebug(LOG_VariableController())
297 << QThread::currentThread()->objectName();
300 << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName();
298 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
301 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
299 auto varRequestId = QUuid::createUuid();
302 auto varRequestId = QUuid::createUuid();
300
303
@@ -380,9 +383,9 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier)
380
383
381 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
384 void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId)
382 {
385 {
383 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId"
386 qCDebug(LOG_VariableController())
384 << QThread::currentThread()->objectName()
387 << "TORM: VariableController::onAddSynchronizationGroupId"
385 << synchronizationGroupId;
388 << QThread::currentThread()->objectName() << synchronizationGroupId;
386 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
389 auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>();
387 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
390 impl->m_GroupIdToVariableSynchronizationGroupMap.insert(
388 std::make_pair(synchronizationGroupId, vSynchroGroup));
391 std::make_pair(synchronizationGroupId, vSynchroGroup));
@@ -397,8 +400,8 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
397 QUuid synchronizationGroupId)
400 QUuid synchronizationGroupId)
398
401
399 {
402 {
400 qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized"
403 qCDebug(LOG_VariableController())
401 << synchronizationGroupId;
404 << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId;
402 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
405 auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable);
403 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
406 if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) {
404 auto groupIdToVSGIt
407 auto groupIdToVSGIt
@@ -503,8 +506,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable>
503 // Don't process already processed var
506 // Don't process already processed var
504 if (!variables.contains(var)) {
507 if (!variables.contains(var)) {
505 if (var != nullptr) {
508 if (var != nullptr) {
506 qCDebug(LOG_VariableController()) << "processRequest synchro for"
509 qCDebug(LOG_VariableController())
507 << var->name();
510 << "processRequest synchro for" << var->name();
508 auto vSyncRangeRequested = computeSynchroRangeRequested(
511 auto vSyncRangeRequested = computeSynchroRangeRequested(
509 var->range(), range, groupIdToOldRangeMap.at(gId));
512 var->range(), range, groupIdToOldRangeMap.at(gId));
510 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
513 qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested;
@@ -573,7 +576,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
573 auto varId = m_VariableToIdentifierMap.at(var);
576 auto varId = m_VariableToIdentifierMap.at(var);
574
577
575 auto varStrategyRangesRequested
578 auto varStrategyRangesRequested
576 = m_VariableCacheStrategy->computeStrategyRanges(var->range(), rangeRequested);
579 = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested);
577
580
578 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
581 auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second};
579 auto inCacheRangeList = QVector<SqpRange>{};
582 auto inCacheRangeList = QVector<SqpRange>{};
@@ -598,8 +601,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p
598 varProvider);
601 varProvider);
599
602
600 if (!varRequestIdCanceled.isNull()) {
603 if (!varRequestIdCanceled.isNull()) {
601 qCDebug(LOG_VariableAcquisitionWorker()) << tr("vsarRequestIdCanceled: ")
604 qCDebug(LOG_VariableAcquisitionWorker())
602 << varRequestIdCanceled;
605 << tr("vsarRequestIdCanceled: ") << varRequestIdCanceled;
603 cancelVariableRequest(varRequestIdCanceled);
606 cancelVariableRequest(varRequestIdCanceled);
604 }
607 }
605 }
608 }
@@ -644,8 +647,8 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier)
644 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
647 std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries(
645 const QVector<AcquisitionDataPacket> acqDataPacketVector)
648 const QVector<AcquisitionDataPacket> acqDataPacketVector)
646 {
649 {
647 qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size")
650 qCDebug(LOG_VariableController())
648 << acqDataPacketVector.size();
651 << tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size();
649 std::shared_ptr<IDataSeries> dataSeries;
652 std::shared_ptr<IDataSeries> dataSeries;
650 if (!acqDataPacketVector.isEmpty()) {
653 if (!acqDataPacketVector.isEmpty()) {
651 dataSeries = acqDataPacketVector[0].m_DateSeries;
654 dataSeries = acqDataPacketVector[0].m_DateSeries;
@@ -662,8 +665,8 void VariableController::VariableControllerPrivate::registerProvider(
662 std::shared_ptr<IDataProvider> provider)
665 std::shared_ptr<IDataProvider> provider)
663 {
666 {
664 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
667 if (m_ProviderSet.find(provider) == m_ProviderSet.end()) {
665 qCDebug(LOG_VariableController()) << tr("Registering of a new provider")
668 qCDebug(LOG_VariableController())
666 << provider->objectName();
669 << tr("Registering of a new provider") << provider->objectName();
667 m_ProviderSet.insert(provider);
670 m_ProviderSet.insert(provider);
668 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
671 connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(),
669 &VariableAcquisitionWorker::onVariableDataAcquired);
672 &VariableAcquisitionWorker::onVariableDataAcquired);
@@ -769,8 +772,8 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
769 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
772 (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate;
770 ++varIdToVarRequestMapIt) {
773 ++varIdToVarRequestMapIt) {
771 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
774 processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate;
772 qCDebug(LOG_VariableController()) << tr("updateVariableRequest")
775 qCDebug(LOG_VariableController())
773 << processVariableUpdate;
776 << tr("updateVariableRequest") << processVariableUpdate;
774 }
777 }
775
778
776 if (processVariableUpdate) {
779 if (processVariableUpdate) {
@@ -780,13 +783,13 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
780 auto &varRequest = varIdToVarRequestMapIt->second;
783 auto &varRequest = varIdToVarRequestMapIt->second;
781 var->setRange(varRequest.m_RangeRequested);
784 var->setRange(varRequest.m_RangeRequested);
782 var->setCacheRange(varRequest.m_CacheRangeRequested);
785 var->setCacheRange(varRequest.m_CacheRangeRequested);
783 qCDebug(LOG_VariableController()) << tr("1: onDataProvided")
786 qCDebug(LOG_VariableController())
784 << varRequest.m_RangeRequested;
787 << tr("1: onDataProvided") << varRequest.m_RangeRequested;
785 qCDebug(LOG_VariableController()) << tr("2: onDataProvided")
788 qCDebug(LOG_VariableController())
786 << varRequest.m_CacheRangeRequested;
789 << tr("2: onDataProvided") << varRequest.m_CacheRangeRequested;
787 var->mergeDataSeries(varRequest.m_DataSeries);
790 var->mergeDataSeries(varRequest.m_DataSeries);
788 qCDebug(LOG_VariableController()) << tr("3: onDataProvided")
791 qCDebug(LOG_VariableController())
789 << varRequest.m_DataSeries->range();
792 << tr("3: onDataProvided") << varRequest.m_DataSeries->range();
790 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
793 qCDebug(LOG_VariableController()) << tr("4: onDataProvided");
791
794
792 /// @todo MPL: confirm
795 /// @todo MPL: confirm
@@ -804,11 +807,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid
804 }
807 }
805
808
806 // cleaning varRequestId
809 // cleaning varRequestId
807 qCDebug(LOG_VariableController()) << tr("0: erase REQUEST in MAP ?")
810 qCDebug(LOG_VariableController())
808 << m_VarRequestIdToVarIdVarRequestMap.size();
811 << tr("0: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
809 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
812 m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId);
810 qCDebug(LOG_VariableController()) << tr("1: erase REQUEST in MAP ?")
813 qCDebug(LOG_VariableController())
811 << m_VarRequestIdToVarIdVarRequestMap.size();
814 << tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size();
812 }
815 }
813 }
816 }
814 else {
817 else {
General Comments 0
You need to be logged in to leave comments. Login now