From 58e88d43a9a56c1ea15d8e6c1642ce27b8371aa8 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Sat, 14 Apr 2012 20:07:30 +0200 Subject: [PATCH] Moving object that holds all query data into seperate object. --- Plugins/LocatePlugin.h | 4 +- Plugins/NearestPlugin.h | 4 +- Plugins/ObjectForPluginStruct.h | 87 ------------------- Plugins/ViaRoutePlugin.h | 6 +- Server/DataStructures/QueryObjectsStorage.cpp | 68 +++++++++++++++ Server/DataStructures/QueryObjectsStorage.h | 44 ++++++++++ routed.cpp | 5 +- 7 files changed, 122 insertions(+), 96 deletions(-) delete mode 100644 Plugins/ObjectForPluginStruct.h create mode 100644 Server/DataStructures/QueryObjectsStorage.cpp create mode 100644 Server/DataStructures/QueryObjectsStorage.h diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 47dc29d54..dbf2dbf0e 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "ObjectForPluginStruct.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" #include "BasePlugin.h" #include "RouteParameters.h" #include "../Util/StringUtil.h" @@ -34,7 +34,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ class LocatePlugin : public BasePlugin { public: - LocatePlugin(ObjectsForQueryStruct * objects) { + LocatePlugin(QueryObjectsStorage * objects) { nodeHelpDesk = objects->nodeHelpDesk; } std::string GetDescriptor() const { return std::string("locate"); } diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 21fb935b9..8f50dbed2 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "RouteParameters.h" -#include "ObjectForPluginStruct.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../DataStructures/NodeInformationHelpDesk.h" #include "../DataStructures/HashTable.h" @@ -37,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ class NearestPlugin : public BasePlugin { public: - NearestPlugin(ObjectsForQueryStruct * objects) { + NearestPlugin(QueryObjectsStorage * objects) { nodeHelpDesk = objects->nodeHelpDesk; descriptorTable.Set("", 0); //default descriptor descriptorTable.Set("kml", 0); diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h deleted file mode 100644 index 631257d75..000000000 --- a/Plugins/ObjectForPluginStruct.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - open source routing machine - Copyright (C) Dennis Luxen, others 2010 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. - */ - - -#ifndef OBJECTSFORQUERYSTRUCT_H_ -#define OBJECTSFORQUERYSTRUCT_H_ - -#include -#include - -#include "../DataStructures/StaticGraph.h" -#include "../Util/GraphLoader.h" - - -struct ObjectsForQueryStruct { - typedef StaticGraph QueryGraph; - typedef QueryGraph::InputEdge InputEdge; - - 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"); - std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); - //Deserialize road network graph - std::vector< QueryGraph::_StrNode> nodeList; - std::vector< QueryGraph::_StrEdge> 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, checkSum); - nodeHelpDesk->initNNGrid(nodesInStream); - - //deserialize street name list - INFO("Loading names index"); - std::ifstream namesInStream(namesPath.c_str(), ios::binary); - unsigned size(0); - namesInStream.read((char *)&size, sizeof(unsigned)); -// names = new std::vector(); - - char buf[1024]; - for(unsigned i = 0; i < size; ++i) { - unsigned sizeOfString = 0; - namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); - buf[sizeOfString] = '\0'; // instead of memset - namesInStream.read(buf, sizeOfString); - names.push_back(buf); - } - std::vector(names).swap(names); - hsgrInStream.close(); - namesInStream.close(); - INFO("All query data structures loaded"); - } - - ~ObjectsForQueryStruct() { -// delete names; - delete graph; - delete nodeHelpDesk; - } -}; - -#endif /* OBJECTSFORQUERYSTRUCT_H_ */ diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 032b9ec95..d9b8d93e7 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -27,8 +27,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include "ObjectForPluginStruct.h" - #include "BasePlugin.h" #include "RouteParameters.h" @@ -44,6 +42,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/StringUtil.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" + class ViaRoutePlugin : public BasePlugin { private: NodeInformationHelpDesk * nodeHelpDesk; @@ -54,7 +54,7 @@ private: SearchEngine > * searchEngine; public: - ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) { + ViaRoutePlugin(QueryObjectsStorage * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) { nodeHelpDesk = objects->nodeHelpDesk; graph = objects->graph; diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp new file mode 100644 index 000000000..7938c697f --- /dev/null +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -0,0 +1,68 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + + +#include "QueryObjectsStorage.h" +#include "../../Util/GraphLoader.h" + +QueryObjectsStorage::QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd) { + INFO("loading graph data"); + std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); + //Deserialize road network graph + std::vector< QueryGraph::_StrNode> nodeList; + std::vector< QueryGraph::_StrEdge> 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, checkSum); + nodeHelpDesk->initNNGrid(nodesInStream); + + //deserialize street name list + INFO("Loading names index"); + std::ifstream namesInStream(namesPath.c_str(), ios::binary); + unsigned size(0); + namesInStream.read((char *)&size, sizeof(unsigned)); + // names = new std::vector(); + + char buf[1024]; + for(unsigned i = 0; i < size; ++i) { + unsigned sizeOfString = 0; + namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); + buf[sizeOfString] = '\0'; // instead of memset + namesInStream.read(buf, sizeOfString); + names.push_back(buf); + } + std::vector(names).swap(names); + hsgrInStream.close(); + namesInStream.close(); + INFO("All query data structures loaded"); +} + +QueryObjectsStorage::~QueryObjectsStorage() { + // delete names; + delete graph; + delete nodeHelpDesk; +} diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h new file mode 100644 index 000000000..72695bd86 --- /dev/null +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -0,0 +1,44 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + + +#ifndef QUERYOBJECTSSTORAGE_H_ +#define QUERYOBJECTSSTORAGE_H_ + +#include +#include + +#include "../../DataStructures/StaticGraph.h" + +struct QueryObjectsStorage { + typedef StaticGraph QueryGraph; + typedef QueryGraph::InputEdge InputEdge; + + NodeInformationHelpDesk * nodeHelpDesk; + std::vector names; + QueryGraph * graph; + unsigned checkSum; + + QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route"); + + ~QueryObjectsStorage(); +}; + +#endif /* QUERYOBJECTSSTORAGE_H_ */ diff --git a/routed.cpp b/routed.cpp index 2f2a62d0b..b970905e2 100644 --- a/routed.cpp +++ b/routed.cpp @@ -24,14 +24,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include "Server/DataStructures/QueryObjectsStorage.h" #include "Server/ServerConfiguration.h" #include "Server/ServerFactory.h" #include "Plugins/HelloWorldPlugin.h" #include "Plugins/LocatePlugin.h" #include "Plugins/NearestPlugin.h" -#include "Plugins/ObjectForPluginStruct.h" #include "Plugins/ViaRoutePlugin.h" + #include "Util/InputFileUtil.h" #include "Util/OpenMPReplacement.h" @@ -87,7 +88,7 @@ int main (int argc, char *argv[]) { Server * s = ServerFactory::CreateServer(serverConfig); RequestHandler & h = s->GetRequestHandlerPtr(); - ObjectsForQueryStruct * objects = new ObjectsForQueryStruct(serverConfig.GetParameter("hsgrData"), + QueryObjectsStorage * objects = new QueryObjectsStorage(serverConfig.GetParameter("hsgrData"), serverConfig.GetParameter("ramIndex"), serverConfig.GetParameter("fileIndex"), serverConfig.GetParameter("nodesData"),