@@ -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 | 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, | |
|
33 | const SqpRange &rangeRequested); | |
|
27 | /// This class aims to hande the cache strategy. | |
|
28 | class SCIQLOP_CORE_EXPORT VariableCacheStrategy { | |
|
34 | 29 | |
|
35 | private: | |
|
36 | class VariableCacheStrategyPrivate; | |
|
37 | spimpl::unique_impl_ptr<VariableCacheStrategyPrivate> impl; | |
|
30 | public: | |
|
31 | virtual std::pair<SqpRange, SqpRange> computeRange(const SqpRange &vRange, | |
|
32 | const SqpRange &rangeRequested) | |
|
33 | = 0; | |
|
38 | 34 | }; |
|
39 | 35 | |
|
36 | ||
|
40 | 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 | 4 | #include <Variable/VariableController.h> |
|
5 | 5 | #include <Variable/VariableModel.h> |
|
6 | 6 | #include <Variable/VariableSynchronizationGroup.h> |
|
7 | #include <Variable/cachestrategyfactory.h> | |
|
7 | 8 | |
|
8 | 9 | #include <Data/DataProviderParameters.h> |
|
9 | 10 | #include <Data/IDataProvider.h> |
@@ -79,7 +80,9 struct VariableController::VariableControllerPrivate { | |||
|
79 | 80 | : m_WorkingMutex{}, |
|
80 | 81 | m_VariableModel{new VariableModel{parent}}, |
|
81 | 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 | 86 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, |
|
84 | 87 | q{parent} |
|
85 | 88 | { |
@@ -145,8 +148,8 struct VariableController::VariableControllerPrivate { | |||
|
145 | 148 | VariableController::VariableController(QObject *parent) |
|
146 | 149 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
147 | 150 | { |
|
148 |
qCDebug(LOG_VariableController()) |
|
|
149 | << QThread::currentThread(); | |
|
151 | qCDebug(LOG_VariableController()) | |
|
152 | << tr("VariableController construction") << QThread::currentThread(); | |
|
150 | 153 | |
|
151 | 154 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
152 | 155 | &VariableController::onAbortProgressRequested); |
@@ -173,8 +176,8 VariableController::VariableController(QObject *parent) | |||
|
173 | 176 | |
|
174 | 177 | VariableController::~VariableController() |
|
175 | 178 | { |
|
176 |
qCDebug(LOG_VariableController()) |
|
|
177 | << QThread::currentThread(); | |
|
179 | qCDebug(LOG_VariableController()) | |
|
180 | << tr("VariableController destruction") << QThread::currentThread(); | |
|
178 | 181 | this->waitForFinish(); |
|
179 | 182 | } |
|
180 | 183 | |
@@ -293,8 +296,8 VariableController::createVariable(const QString &name, const QVariantHash &meta | |||
|
293 | 296 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
294 | 297 | { |
|
295 | 298 | // TODO check synchronisation and Rescale |
|
296 |
qCDebug(LOG_VariableController()) |
|
|
297 | << QThread::currentThread()->objectName(); | |
|
299 | qCDebug(LOG_VariableController()) | |
|
300 | << "VariableController::onDateTimeOnSelection" << QThread::currentThread()->objectName(); | |
|
298 | 301 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
299 | 302 | auto varRequestId = QUuid::createUuid(); |
|
300 | 303 | |
@@ -380,9 +383,9 void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) | |||
|
380 | 383 | |
|
381 | 384 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
382 | 385 | { |
|
383 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" | |
|
384 | << QThread::currentThread()->objectName() | |
|
385 | << synchronizationGroupId; | |
|
386 | qCDebug(LOG_VariableController()) | |
|
387 | << "TORM: VariableController::onAddSynchronizationGroupId" | |
|
388 | << QThread::currentThread()->objectName() << synchronizationGroupId; | |
|
386 | 389 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); |
|
387 | 390 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( |
|
388 | 391 | std::make_pair(synchronizationGroupId, vSynchroGroup)); |
@@ -397,8 +400,8 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, | |||
|
397 | 400 | QUuid synchronizationGroupId) |
|
398 | 401 | |
|
399 | 402 | { |
|
400 |
qCDebug(LOG_VariableController()) |
|
|
401 | << synchronizationGroupId; | |
|
403 | qCDebug(LOG_VariableController()) | |
|
404 | << "TORM: VariableController::onAddSynchronized" << synchronizationGroupId; | |
|
402 | 405 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); |
|
403 | 406 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
404 | 407 | auto groupIdToVSGIt |
@@ -503,8 +506,8 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> | |||
|
503 | 506 | // Don't process already processed var |
|
504 | 507 | if (!variables.contains(var)) { |
|
505 | 508 | if (var != nullptr) { |
|
506 |
qCDebug(LOG_VariableController()) |
|
|
507 | << var->name(); | |
|
509 | qCDebug(LOG_VariableController()) | |
|
510 | << "processRequest synchro for" << var->name(); | |
|
508 | 511 | auto vSyncRangeRequested = computeSynchroRangeRequested( |
|
509 | 512 | var->range(), range, groupIdToOldRangeMap.at(gId)); |
|
510 | 513 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; |
@@ -573,7 +576,7 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||
|
573 | 576 | auto varId = m_VariableToIdentifierMap.at(var); |
|
574 | 577 | |
|
575 | 578 | auto varStrategyRangesRequested |
|
576 |
= m_VariableCacheStrategy->compute |
|
|
579 | = m_VariableCacheStrategy->computeRange(var->range(), rangeRequested); | |
|
577 | 580 | |
|
578 | 581 | auto notInCacheRangeList = QVector<SqpRange>{varStrategyRangesRequested.second}; |
|
579 | 582 | auto inCacheRangeList = QVector<SqpRange>{}; |
@@ -598,8 +601,8 void VariableController::VariableControllerPrivate::processRequest(std::shared_p | |||
|
598 | 601 | varProvider); |
|
599 | 602 | |
|
600 | 603 | if (!varRequestIdCanceled.isNull()) { |
|
601 |
qCDebug(LOG_VariableAcquisitionWorker()) |
|
|
602 | << varRequestIdCanceled; | |
|
604 | qCDebug(LOG_VariableAcquisitionWorker()) | |
|
605 | << tr("vsarRequestIdCanceled: ") << varRequestIdCanceled; | |
|
603 | 606 | cancelVariableRequest(varRequestIdCanceled); |
|
604 | 607 | } |
|
605 | 608 | } |
@@ -644,8 +647,8 VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) | |||
|
644 | 647 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( |
|
645 | 648 | const QVector<AcquisitionDataPacket> acqDataPacketVector) |
|
646 | 649 | { |
|
647 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") | |
|
648 | << acqDataPacketVector.size(); | |
|
650 | qCDebug(LOG_VariableController()) | |
|
651 | << tr("TORM: retrieveDataSeries acqDataPacketVector size") << acqDataPacketVector.size(); | |
|
649 | 652 | std::shared_ptr<IDataSeries> dataSeries; |
|
650 | 653 | if (!acqDataPacketVector.isEmpty()) { |
|
651 | 654 | dataSeries = acqDataPacketVector[0].m_DateSeries; |
@@ -662,8 +665,8 void VariableController::VariableControllerPrivate::registerProvider( | |||
|
662 | 665 | std::shared_ptr<IDataProvider> provider) |
|
663 | 666 | { |
|
664 | 667 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { |
|
665 |
qCDebug(LOG_VariableController()) |
|
|
666 |
|
|
|
668 | qCDebug(LOG_VariableController()) | |
|
669 | << tr("Registering of a new provider") << provider->objectName(); | |
|
667 | 670 | m_ProviderSet.insert(provider); |
|
668 | 671 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), |
|
669 | 672 | &VariableAcquisitionWorker::onVariableDataAcquired); |
@@ -769,8 +772,8 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid | |||
|
769 | 772 | (varIdToVarRequestMapIt != varIdToVarRequestMap.cend()) && processVariableUpdate; |
|
770 | 773 | ++varIdToVarRequestMapIt) { |
|
771 | 774 | processVariableUpdate &= varIdToVarRequestMapIt->second.m_CanUpdate; |
|
772 |
qCDebug(LOG_VariableController()) |
|
|
773 |
|
|
|
775 | qCDebug(LOG_VariableController()) | |
|
776 | << tr("updateVariableRequest") << processVariableUpdate; | |
|
774 | 777 | } |
|
775 | 778 | |
|
776 | 779 | if (processVariableUpdate) { |
@@ -780,13 +783,13 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid | |||
|
780 | 783 | auto &varRequest = varIdToVarRequestMapIt->second; |
|
781 | 784 | var->setRange(varRequest.m_RangeRequested); |
|
782 | 785 | var->setCacheRange(varRequest.m_CacheRangeRequested); |
|
783 |
qCDebug(LOG_VariableController()) |
|
|
784 |
|
|
|
785 |
qCDebug(LOG_VariableController()) |
|
|
786 |
|
|
|
786 | qCDebug(LOG_VariableController()) | |
|
787 | << tr("1: onDataProvided") << varRequest.m_RangeRequested; | |
|
788 | qCDebug(LOG_VariableController()) | |
|
789 | << tr("2: onDataProvided") << varRequest.m_CacheRangeRequested; | |
|
787 | 790 | var->mergeDataSeries(varRequest.m_DataSeries); |
|
788 |
qCDebug(LOG_VariableController()) |
|
|
789 |
|
|
|
791 | qCDebug(LOG_VariableController()) | |
|
792 | << tr("3: onDataProvided") << varRequest.m_DataSeries->range(); | |
|
790 | 793 | qCDebug(LOG_VariableController()) << tr("4: onDataProvided"); |
|
791 | 794 | |
|
792 | 795 | /// @todo MPL: confirm |
@@ -804,11 +807,11 void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid | |||
|
804 | 807 | } |
|
805 | 808 | |
|
806 | 809 | // cleaning varRequestId |
|
807 |
qCDebug(LOG_VariableController()) |
|
|
808 |
|
|
|
810 | qCDebug(LOG_VariableController()) | |
|
811 | << tr("0: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size(); | |
|
809 | 812 | m_VarRequestIdToVarIdVarRequestMap.erase(varRequestId); |
|
810 |
qCDebug(LOG_VariableController()) |
|
|
811 |
|
|
|
813 | qCDebug(LOG_VariableController()) | |
|
814 | << tr("1: erase REQUEST in MAP ?") << m_VarRequestIdToVarIdVarRequestMap.size(); | |
|
812 | 815 | } |
|
813 | 816 | } |
|
814 | 817 | else { |
General Comments 0
You need to be logged in to leave comments.
Login now