##// END OF EJS Templates
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)

File last commit:

r512:d00d6fd96c10
r1250:23206e07bbc2
Show More
VariableCacheController.cpp
225 lines | 9.3 KiB | text/x-c | CppLexer
/ core / src / Variable / VariableCacheController.cpp
Create a variable notify the variable cache parameter
r225 #include "Variable/VariableCacheController.h"
#include "Variable/Variable.h"
#include <unordered_map>
Add current progression for thread fix
r364 #include <QThread>
Add method to display cache....
r293 Q_LOGGING_CATEGORY(LOG_VariableCacheController, "VariableCacheController")
Create a variable notify the variable cache parameter
r225 struct VariableCacheController::VariableCacheControllerPrivate {
Change SqpRange for SqpDateTime
r512 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpRange> > m_VariableToSqpRangeListMap;
Implementation of the cach interval algoritm
r229
Change SqpRange for SqpDateTime
r512 void addInCacheDataByEnd(const SqpRange &dateTime, QVector<SqpRange> &dateTimeList,
QVector<SqpRange> &notInCache, int cacheIndex, double currentTStart);
Implementation of the cach interval algoritm
r229
Change SqpRange for SqpDateTime
r512 void addInCacheDataByStart(const SqpRange &dateTime, QVector<SqpRange> &dateTimeList,
QVector<SqpRange> &notInCache, int cacheIndex, double currentTStart);
Implementation of the addDateTime method of the cache
r230
Change SqpRange for SqpDateTime
r512 void addDateTimeRecurse(const SqpRange &dateTime, QVector<SqpRange> &dateTimeList,
Implementation of the addDateTime method of the cache
r230 int cacheIndex);
Create a variable notify the variable cache parameter
r225 };
VariableCacheController::VariableCacheController(QObject *parent)
Correction for pull request
r243 : QObject{parent}, impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()}
Create a variable notify the variable cache parameter
r225 {
}
void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
Change SqpRange for SqpDateTime
r512 const SqpRange &dateTime)
Create a variable notify the variable cache parameter
r225 {
Change info to debug on thread display log
r367 qCDebug(LOG_VariableCacheController()) << "VariableCacheController::addDateTime"
<< QThread::currentThread()->objectName();
Create a variable notify the variable cache parameter
r225 if (variable) {
Change SqpRange for SqpDateTime
r512 auto findVariableIte = impl->m_VariableToSqpRangeListMap.find(variable);
if (findVariableIte == impl->m_VariableToSqpRangeListMap.end()) {
impl->m_VariableToSqpRangeListMap[variable].push_back(dateTime);
Implementation of the addDateTime method of the cache
r230 }
else {
Change SqpRange for SqpDateTime
r512 // addDateTime modify the list<SqpRange> of the variable in a way to ensure
Implementation of the addDateTime method of the cache
r230 // that the list is ordered : l(0) < l(1). We assume also a < b
Change SqpRange for SqpDateTime
r512 // (with a & b of type SqpRange) means ts(b) > te(a)
Implementation of the addDateTime method of the cache
r230
// The algorithm will try the merge of two interval:
// - dateTime will be compare with the first interval of the list:
// A: if it is inferior, it will be inserted and it's finished.
// B: if it is in intersection, it will be merge then the merged one
// will be compared to the next interval. The old one is remove from the list
// C: if it is superior, we do the same with the next interval of the list
Correction MR
r300 try {
Change SqpRange for SqpDateTime
r512 impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpRangeListMap.at(variable),
0);
Correction MR
r300 }
catch (const std::out_of_range &e) {
It's now possible to create the variable and ask data to be retreived...
r319 qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what();
Correction MR
r300 }
Implementation of the addDateTime method of the cache
r230 }
Create a variable notify the variable cache parameter
r225 }
}
Implementation of the cach interval algoritm
r229
Alexandre Leroux
Variable deletion (2)...
r331 void VariableCacheController::clear(std::shared_ptr<Variable> variable) noexcept
{
if (!variable) {
qCCritical(LOG_VariableCacheController()) << "Can't clear variable cache: variable is null";
return;
}
Change SqpRange for SqpDateTime
r512 auto nbEntries = impl->m_VariableToSqpRangeListMap.erase(variable);
Alexandre Leroux
Variable deletion (2)...
r331
auto clearCacheMessage
= (nbEntries != 0)
? tr("Variable cache cleared for variable %1").arg(variable->name())
: tr("No deletion of variable cache: no cache was associated with the variable");
qCDebug(LOG_VariableCacheController()) << clearCacheMessage;
}
Change SqpRange for SqpDateTime
r512 QVector<SqpRange>
Implementation of the cach interval algoritm
r229 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
Change SqpRange for SqpDateTime
r512 const SqpRange &dateTime)
Implementation of the cach interval algoritm
r229 {
Change info to debug on thread display log
r367 qCDebug(LOG_VariableCacheController())
Add current progression for thread fix
r364 << "VariableCacheController::provideNotInCacheDateTimeList"
<< QThread::currentThread()->objectName();
Change SqpRange for SqpDateTime
r512 auto notInCache = QVector<SqpRange>{};
Implementation of the cach interval algoritm
r229
// This algorithm is recursif. The idea is to localise the start time then the end time in the
// list of date time request associated to the variable
// We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
Change SqpRange for SqpDateTime
r512 // (with a & b of type SqpRange) means ts(b) > te(a)
auto it = impl->m_VariableToSqpRangeListMap.find(variable);
if (it != impl->m_VariableToSqpRangeListMap.end()) {
It's now possible to create the variable and ask data to be retreived...
r319 impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart);
Correction MR
r300 }
It's now possible to create the variable and ask data to be retreived...
r319 else {
notInCache << dateTime;
Correction MR
r300 }
Implementation of the cach interval algoritm
r229
return notInCache;
}
Change SqpRange for SqpDateTime
r512 QVector<SqpRange>
Implementation of the addDateTime method of the cache
r230 VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept
{
Change info to debug on thread display log
r367 qCDebug(LOG_VariableCacheController()) << "VariableCacheController::dateCacheList"
<< QThread::currentThread()->objectName();
Correction MR
r300 try {
Change SqpRange for SqpDateTime
r512 return impl->m_VariableToSqpRangeListMap.at(variable);
Correction MR
r300 }
catch (const std::out_of_range &e) {
Modify cache log lvl from info to warn
r303 qCWarning(LOG_VariableCacheController()) << e.what();
Change SqpRange for SqpDateTime
r512 return QVector<SqpRange>{};
Correction MR
r300 }
Implementation of the addDateTime method of the cache
r230 }
void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse(
Change SqpRange for SqpDateTime
r512 const SqpRange &dateTime, QVector<SqpRange> &dateTimeList, int cacheIndex)
Implementation of the addDateTime method of the cache
r230 {
const auto dateTimeListSize = dateTimeList.count();
if (cacheIndex >= dateTimeListSize) {
dateTimeList.push_back(dateTime);
// there is no anymore interval to compore, we can just push_back it
return;
}
auto currentDateTime = dateTimeList[cacheIndex];
if (dateTime.m_TEnd < currentDateTime.m_TStart) {
// The compared one is < to current one compared, we can insert it
dateTimeList.insert(cacheIndex, dateTime);
}
else if (dateTime.m_TStart > currentDateTime.m_TEnd) {
// The compared one is > to current one compared we can comparet if to the next one
addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex);
}
else {
// Merge cases: we need to merge the two interval, remove the old one from the list then
// rerun the algo from this index with the merged interval
auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart);
auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd);
Change SqpRange for SqpDateTime
r512 auto mergeDateTime = SqpRange{mTStart, mTEnd};
Implementation of the addDateTime method of the cache
r230
dateTimeList.remove(cacheIndex);
addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex);
}
}
Implementation of the cach interval algoritm
r229
void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd(
Change SqpRange for SqpDateTime
r512 const SqpRange &dateTime, QVector<SqpRange> &dateTimeList, QVector<SqpRange> &notInCache,
int cacheIndex, double currentTStart)
Implementation of the cach interval algoritm
r229 {
const auto dateTimeListSize = dateTimeList.count();
if (cacheIndex >= dateTimeListSize) {
if (currentTStart < dateTime.m_TEnd) {
// te localised after all other interval: The last interval is [currentTsart, te]
Change SqpRange for SqpDateTime
r512 notInCache.push_back(SqpRange{currentTStart, dateTime.m_TEnd});
Implementation of the cach interval algoritm
r229 }
return;
}
auto currentDateTimeJ = dateTimeList[cacheIndex];
if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) {
// te localised between to interval: The last interval is [currentTsart, te]
Change SqpRange for SqpDateTime
r512 notInCache.push_back(SqpRange{currentTStart, dateTime.m_TEnd});
Implementation of the cach interval algoritm
r229 }
else {
Change SqpRange for SqpDateTime
r512 notInCache.push_back(SqpRange{currentTStart, currentDateTimeJ.m_TStart});
Implementation of the cach interval algoritm
r229 if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) {
// te not localised before the current interval: we need to look at the next interval
addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex,
currentDateTimeJ.m_TEnd);
}
}
}
void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart(
Change SqpRange for SqpDateTime
r512 const SqpRange &dateTime, QVector<SqpRange> &dateTimeList, QVector<SqpRange> &notInCache,
int cacheIndex, double currentTStart)
Implementation of the cach interval algoritm
r229 {
const auto dateTimeListSize = dateTimeList.count();
if (cacheIndex >= dateTimeListSize) {
// ts localised after all other interval: The last interval is [ts, te]
Change SqpRange for SqpDateTime
r512 notInCache.push_back(SqpRange{currentTStart, dateTime.m_TEnd});
Implementation of the cach interval algoritm
r229 return;
}
auto currentDateTimeI = dateTimeList[cacheIndex];
if (currentTStart < currentDateTimeI.m_TStart) {
// ts localised between to interval: let's localized te
Correction for pull request
r243 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndex, currentTStart);
Implementation of the cach interval algoritm
r229 }
Add method to display cache....
r293 else if (currentTStart < currentDateTimeI.m_TEnd) {
if (dateTime.m_TEnd > currentDateTimeI.m_TEnd) {
// ts not localised before the current interval: we need to look at the next interval
// We can assume now current tstart is the last interval tend, because data between them
// are
// in the cache
addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
currentDateTimeI.m_TEnd);
}
Implementation of the cach interval algoritm
r229 }
else {
// ts not localised before the current interval: we need to look at the next interval
addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
}
}
Add method to display cache....
r293
Correction MR
r300 void VariableCacheController::displayCache(std::shared_ptr<Variable> variable) const
Add method to display cache....
r293 {
Change SqpRange for SqpDateTime
r512 auto variableDateTimeList = impl->m_VariableToSqpRangeListMap.find(variable);
if (variableDateTimeList != impl->m_VariableToSqpRangeListMap.end()) {
Correction clang format
r365 qCInfo(LOG_VariableCacheController()) << tr("VariableCacheController::displayCache")
<< variableDateTimeList->second;
Correction MR
r300 }
else {
qCWarning(LOG_VariableCacheController())
<< tr("Cannot display a variable that is not in the cache");
}
Add method to display cache....
r293 }