Skip to content

Commit

Permalink
correctly merge the loading progress code for reading the cache from …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
patrickbr committed Jun 26, 2024
1 parent 4e6e58c commit 6f2b412
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/qlever-petrimaps/GeomCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include <iostream>
#include <sstream>

#include "GeomCache.h"
#include "qlever-petrimaps/Misc.h"
#include "qlever-petrimaps/server/Requestor.h"
#include "util/Misc.h"
#include "util/geo/Geo.h"
#include "util/geo/PolyLine.h"
#include "GeomCache.h"

using petrimaps::GeomCache;

Expand Down Expand Up @@ -51,6 +51,10 @@ double GeomCache::getLoadStatusPercent(bool total) {
totalPercent +=
_curRow / static_cast<double>(_totalSize) * parseIdsPercent;
break;

case _LoadStatusStages::FromFile:
totalPercent = _curRow / static_cast<double>(_totalSize) * 100.0;
break;
}

return std::min(100.0, totalPercent);
Expand Down Expand Up @@ -118,5 +122,3 @@ util::geo::DBox GeomCache::getLineBBox(size_t lid) const {

return ret;
}


6 changes: 4 additions & 2 deletions src/qlever-petrimaps/GeomCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <atomic>

#include "qlever-petrimaps/Misc.h"
#include "util/geo/Geo.h"
Expand Down Expand Up @@ -62,10 +63,11 @@ class GeomCache {

protected:
CURL* _curl;
enum _LoadStatusStages { Parse = 1, ParseIds };
enum _LoadStatusStages { Parse = 1, ParseIds, FromFile};
_LoadStatusStages _loadStatusStage = Parse;

size_t _curRow = 0, _curUniqueGeom = 0, _geometryDuplicates = 0;
std::atomic<size_t> _curRow;
size_t _curUniqueGeom = 0, _geometryDuplicates = 0;
size_t _totalSize = 0;
mutable std::mutex _m;
bool _ready = false;
Expand Down
72 changes: 60 additions & 12 deletions src/qlever-petrimaps/SPARQLCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ std::string SPARQLCache::indexHashFromDisk(const std::string& fname) {

// _____________________________________________________________________________
void SPARQLCache::fromDisk(const std::string& fname) {
_loadStatusStage = _LoadStatusStages::FromFile;

_points.clear();
_linePoints.clear();
_lines.clear();
Expand All @@ -936,23 +938,69 @@ void SPARQLCache::fromDisk(const std::string& fname) {
_indexHash = util::trim(tmp);

size_t numPoints;
size_t numLinePoints;
size_t numLines;
size_t numQidToId;
std::streampos posPoints;
std::streampos posLinePoints;
std::streampos posLines;
std::streampos posQidToId;
// get total num points
// points
f.read(reinterpret_cast<char*>(&numPoints), sizeof(size_t));
_points.resize(numPoints);
f.read(reinterpret_cast<char*>(&_points[0]),
sizeof(util::geo::FPoint) * numPoints);
posPoints = f.tellg();
f.seekg(sizeof(util::geo::FPoint) * numPoints, f.cur);

// linePoints
f.read(reinterpret_cast<char*>(&numLinePoints), sizeof(size_t));
_linePoints.resize(numLinePoints);
posLinePoints = f.tellg();
f.seekg(sizeof(util::geo::Point<int16_t>) * numLinePoints, f.cur);

// lines
f.read(reinterpret_cast<char*>(&numLines), sizeof(size_t));
_lines.resize(numLines);
posLines = f.tellg();
f.seekg(sizeof(size_t) * numLines, f.cur);

// qidToId
f.read(reinterpret_cast<char*>(&numQidToId), sizeof(size_t));
_qidToId.resize(numQidToId);
posQidToId = f.tellg();
f.seekg(sizeof(IdMapping) * numQidToId, f.cur);

_totalSize = numPoints + numLinePoints + numLines + numQidToId;
_curRow = 0;

f.read(reinterpret_cast<char*>(&numPoints), sizeof(size_t));
_linePoints.resize(numPoints);
f.read(reinterpret_cast<char*>(&_linePoints[0]),
sizeof(util::geo::Point<int16_t>) * numPoints);
// read data from file
// points
f.seekg(posPoints);
for (size_t i = 0; i < numPoints; i++) {
f.read(reinterpret_cast<char*>(&_points[i]), sizeof(util::geo::FPoint));
_curRow += 1;
}

f.read(reinterpret_cast<char*>(&numPoints), sizeof(size_t));
_lines.resize(numPoints);
f.read(reinterpret_cast<char*>(&_lines[0]), sizeof(size_t) * numPoints);
// linePoints
f.seekg(posLinePoints);
for (size_t i = 0; i < numLinePoints; i++) {
f.read(reinterpret_cast<char*>(&_linePoints[i]), sizeof(util::geo::Point<int16_t>));
_curRow += 1;
}

f.read(reinterpret_cast<char*>(&numPoints), sizeof(size_t));
_qidToId.resize(numPoints);
f.read(reinterpret_cast<char*>(&_qidToId[0]), sizeof(IdMapping) * numPoints);
// lines
f.seekg(posLines);
for (size_t i = 0; i < numLines; i++) {
f.read(reinterpret_cast<char*>(&_lines[i]), sizeof(size_t));
_curRow += 1;
}

// qidToId
f.seekg(posQidToId);
for (size_t i = 0; i < numQidToId; i++) {
f.read(reinterpret_cast<char*>(&_qidToId[i]), sizeof(IdMapping));
_curRow += 1;
}

f.close();
}
Expand Down

0 comments on commit 6f2b412

Please sign in to comment.