From e034733ac66ffbad00111bfd82b4a465867181d3 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 17 Feb 2012 08:15:33 +0100 Subject: [PATCH] CRC32 of data is written to file and loaded into NodeInfoHelpDesk. --- DataStructures/NodeInformationHelpDesk.h | 7 ++++++- Plugins/ObjectForPluginStruct.h | 6 ++++-- Util/GraphLoader.h | 3 ++- createHierarchy.cpp | 17 ++++++++++++----- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 91106f824b..01de6fb0d2 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class NodeInformationHelpDesk{ public: - NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes) : numberOfNodes(_numberOfNodes) { + NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) { readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); coordinateVector.reserve(numberOfNodes); assert(0 == coordinateVector.size()); @@ -72,10 +72,15 @@ class NodeInformationHelpDesk{ readOnlyGrid->FindNearestPointOnEdge(input, output); } + inline unsigned GetCheckSum() const { + return checkSum; + } + private: std::vector<_Coordinate> coordinateVector; ReadOnlyGrid * readOnlyGrid; unsigned numberOfNodes; + unsigned checkSum; }; #endif /*NODEINFORMATIONHELPDESK_H_*/ diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h index 89dc75d071..c8610cce2f 100644 --- a/Plugins/ObjectForPluginStruct.h +++ b/Plugins/ObjectForPluginStruct.h @@ -36,6 +36,7 @@ struct ObjectsForQueryStruct { NodeInformationHelpDesk * nodeHelpDesk; std::vector * names; QueryGraph * graph; + unsigned checkSum; ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") { INFO("loading graph data"); @@ -43,14 +44,15 @@ struct ObjectsForQueryStruct { //Deserialize road network graph std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrEdge> edgeList; - const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList); + const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList, &checkSum); + INFO("Data checksum is " << checkSum); graph = new QueryGraph(nodeList, edgeList); assert(0 == nodeList.size()); assert(0 == edgeList.size()); INFO("Loading nearest neighbor indices"); //Init nearest neighbor data structure std::ifstream nodesInStream(nodesPath.c_str(), ios::binary); - nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n); + nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum); nodeHelpDesk->initNNGrid(nodesInStream); //deserialize street name list diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index e2804c5f16..1e9c1fa699 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -361,8 +361,9 @@ NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector -unsigned readHSGRFromStream(istream &in, vector& nodeList, vector & edgeList) { +unsigned readHSGRFromStream(istream &in, vector& nodeList, vector & edgeList, unsigned * checkSum) { unsigned numberOfNodes = 0; + in.read((char*) checkSum, sizeof(unsigned)); in.read((char*) & numberOfNodes, sizeof(unsigned)); nodeList.resize(numberOfNodes + 1); NodeT currentNode; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 3a0ff8680a..33eb762df4 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -37,6 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include "Algorithms/CRC32.h" #include "Util/OpenMPReplacement.h" #include "typedefs.h" #include "Contractor/Contractor.h" @@ -129,27 +130,32 @@ int main (int argc, char *argv[]) { std::vector nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); DELETE(edgeBasedGraphFactory); - double expansionHasFinishedTime = get_timestamp() - startupTime; WritableGrid * writeableGrid = new WritableGrid(); INFO("building grid ..."); writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut); DELETE( writeableGrid ); + CRC32 crc32; + unsigned crc32OfNodeBasedEdgeList = crc32((char *)&(nodeBasedEdgeList[0]), nodeBasedEdgeList.size()*sizeof(EdgeBasedGraphFactory::EdgeBasedNode)); +// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); + nodeBasedEdgeList.clear(); std::vector().swap(nodeBasedEdgeList); INFO("writing node map ..."); std::ofstream mapOutFile(nodeOut, ios::binary); - BOOST_FOREACH(NodeInfo & info, internalToExternaleNodeMapping) { - mapOutFile.write((char *)&(info), sizeof(NodeInfo)); - } + mapOutFile.write((char *)&(internalToExternaleNodeMapping[0]), internalToExternaleNodeMapping.size()*sizeof(NodeInfo)); mapOutFile.close(); - internalToExternaleNodeMapping.clear(); + + std::vector().swap(internalToExternaleNodeMapping); inputRestrictions.clear(); std::vector<_Restriction>().swap(inputRestrictions); +// unsigned crc32OfNodeBasedEdgeList = crc32((char*)&edgeBasedEdgeList[0], edgeBasedEdgeList.size()); +// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); + INFO("initializing contractor"); Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); @@ -199,6 +205,7 @@ int main (int argc, char *argv[]) { position += edge - lastEdge; //remove } //Serialize numberOfNodes, nodes + edgeOutFile.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned)); edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes+1));