2012-04-14 14:07:30 -04:00
|
|
|
/*
|
|
|
|
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"
|
|
|
|
|
2013-10-13 08:13:08 -04:00
|
|
|
QueryObjectsStorage::QueryObjectsStorage( const ServerPaths & paths ) {
|
|
|
|
if( paths.find("hsgrdata") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no hsgr file given in ini file");
|
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if( paths.find("ramindex") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no ram index file given in ini file");
|
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if( paths.find("fileindex") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no mem index file given in ini file");
|
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if( paths.find("nodesdata") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no nodes file given in ini file");
|
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if( paths.find("edgesdata") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no edges file given in ini file");
|
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if( paths.find("namesdata") == paths.end() ) {
|
2013-08-09 08:47:09 -04:00
|
|
|
throw OSRMException("no names file given in ini file");
|
|
|
|
}
|
|
|
|
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "loading graph data";
|
2012-04-14 14:07:30 -04:00
|
|
|
//Deserialize road network graph
|
2013-10-13 08:13:08 -04:00
|
|
|
|
|
|
|
ServerPaths::const_iterator paths_iterator = paths.find("hsgrdata");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & hsgr_data_string = paths_iterator->second.string();
|
|
|
|
|
2013-08-20 11:05:36 -04:00
|
|
|
std::vector< QueryGraph::_StrNode> node_list;
|
|
|
|
std::vector< QueryGraph::_StrEdge> edge_list;
|
|
|
|
const int number_of_nodes = readHSGRFromStream(
|
2013-10-13 08:13:08 -04:00
|
|
|
hsgr_data_string,
|
2013-08-20 11:05:36 -04:00
|
|
|
node_list,
|
|
|
|
edge_list,
|
|
|
|
&check_sum
|
2013-06-25 13:27:39 -04:00
|
|
|
);
|
2012-04-14 14:07:30 -04:00
|
|
|
|
2013-08-20 11:05:36 -04:00
|
|
|
SimpleLogger().Write() << "Data checksum is " << check_sum;
|
|
|
|
graph = new QueryGraph(node_list, edge_list);
|
2013-10-13 08:13:08 -04:00
|
|
|
BOOST_ASSERT(0 == node_list.size());
|
|
|
|
BOOST_ASSERT(0 == edge_list.size());
|
|
|
|
|
2013-10-13 08:26:42 -04:00
|
|
|
paths_iterator = paths.find("timestamp");
|
2012-04-25 04:51:16 -04:00
|
|
|
|
2013-10-13 08:13:08 -04:00
|
|
|
if(paths.end() != paths_iterator) {
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Loading Timestamp";
|
2013-10-13 08:13:08 -04:00
|
|
|
const std::string & timestamp_string = paths_iterator->second.string();
|
|
|
|
|
|
|
|
boost::filesystem::ifstream time_stamp_instream(timestamp_string);
|
|
|
|
if( !time_stamp_instream.good() ) {
|
|
|
|
SimpleLogger().Write(logWARNING) << timestamp_string << " not found";
|
2013-08-08 08:17:01 -04:00
|
|
|
}
|
2012-09-19 11:06:35 -04:00
|
|
|
|
2013-10-13 08:13:08 -04:00
|
|
|
getline(time_stamp_instream, timestamp);
|
|
|
|
time_stamp_instream.close();
|
2012-05-15 08:28:13 -04:00
|
|
|
}
|
2013-07-22 10:34:06 -04:00
|
|
|
if(!timestamp.length()) {
|
2012-05-15 08:28:13 -04:00
|
|
|
timestamp = "n/a";
|
2013-07-22 10:34:06 -04:00
|
|
|
}
|
|
|
|
if(25 < timestamp.length()) {
|
2012-12-10 10:36:54 -05:00
|
|
|
timestamp.resize(25);
|
2013-07-22 10:34:06 -04:00
|
|
|
}
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Loading auxiliary information";
|
2013-10-13 08:13:08 -04:00
|
|
|
|
|
|
|
paths_iterator = paths.find("ramindex");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & ram_index_string = paths_iterator->second.string();
|
|
|
|
paths_iterator = paths.find("fileindex");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & file_index_string = paths_iterator->second.string();
|
|
|
|
paths_iterator = paths.find("nodesdata");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & nodes_data_string = paths_iterator->second.string();
|
|
|
|
paths_iterator = paths.find("edgesdata");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & edges_data_string = paths_iterator->second.string();
|
|
|
|
|
2012-04-25 04:51:16 -04:00
|
|
|
//Init nearest neighbor data structure
|
2013-06-27 16:09:21 -04:00
|
|
|
nodeHelpDesk = new NodeInformationHelpDesk(
|
2013-10-13 08:13:08 -04:00
|
|
|
ram_index_string,
|
|
|
|
file_index_string,
|
|
|
|
nodes_data_string,
|
|
|
|
edges_data_string,
|
2013-08-20 11:05:36 -04:00
|
|
|
number_of_nodes,
|
|
|
|
check_sum
|
2013-06-27 16:09:21 -04:00
|
|
|
);
|
2012-04-14 14:07:30 -04:00
|
|
|
|
|
|
|
//deserialize street name list
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Loading names index";
|
2013-08-09 11:47:11 -04:00
|
|
|
|
2013-10-13 08:13:08 -04:00
|
|
|
paths_iterator = paths.find("namesdata");
|
|
|
|
BOOST_ASSERT(paths.end() != paths_iterator);
|
|
|
|
const std::string & names_data_string = paths_iterator->second.string();
|
|
|
|
if ( !boost::filesystem::exists( paths_iterator->second ) ) {
|
2013-08-09 11:47:11 -04:00
|
|
|
throw OSRMException("names file does not exist");
|
2013-08-05 11:28:57 -04:00
|
|
|
}
|
2013-10-13 08:13:08 -04:00
|
|
|
if ( 0 == boost::filesystem::file_size( paths_iterator->second ) ) {
|
2013-08-09 11:47:11 -04:00
|
|
|
throw OSRMException("names file is empty");
|
|
|
|
}
|
|
|
|
|
2013-10-13 08:13:08 -04:00
|
|
|
boost::filesystem::ifstream name_stream(names_data_string, std::ios::binary);
|
2013-08-09 11:47:11 -04:00
|
|
|
unsigned size = 0;
|
|
|
|
name_stream.read((char *)&size, sizeof(unsigned));
|
2013-08-20 11:05:36 -04:00
|
|
|
BOOST_ASSERT_MSG(0 != size, "name file broken");
|
|
|
|
|
|
|
|
m_name_begin_indices.resize(size);
|
|
|
|
name_stream.read((char*)&m_name_begin_indices[0], size*sizeof(unsigned));
|
|
|
|
name_stream.read((char *)&size, sizeof(unsigned));
|
|
|
|
BOOST_ASSERT_MSG(0 != size, "name file broken");
|
|
|
|
|
|
|
|
m_names_char_list.resize(size+1); //+1 is sentinel/dummy element
|
|
|
|
name_stream.read((char *)&m_names_char_list[0], size*sizeof(char));
|
|
|
|
BOOST_ASSERT_MSG(0 != m_names_char_list.size(), "could not load any names");
|
|
|
|
|
2013-08-09 11:47:11 -04:00
|
|
|
name_stream.close();
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "All query data structures loaded";
|
2012-04-14 14:07:30 -04:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:05:36 -04:00
|
|
|
void QueryObjectsStorage::GetName(
|
|
|
|
const unsigned name_id,
|
|
|
|
std::string & result
|
|
|
|
) const {
|
|
|
|
if(UINT_MAX == name_id) {
|
|
|
|
result = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BOOST_ASSERT_MSG(
|
|
|
|
name_id < m_name_begin_indices.size(),
|
|
|
|
"name id too high"
|
|
|
|
);
|
|
|
|
unsigned begin_index = m_name_begin_indices[name_id];
|
|
|
|
unsigned end_index = m_name_begin_indices[name_id+1];
|
|
|
|
BOOST_ASSERT_MSG(
|
|
|
|
begin_index < m_names_char_list.size(),
|
|
|
|
"begin index of name too high"
|
|
|
|
);
|
|
|
|
BOOST_ASSERT_MSG(
|
|
|
|
end_index < m_names_char_list.size(),
|
|
|
|
"end index of name too high"
|
|
|
|
);
|
|
|
|
|
|
|
|
BOOST_ASSERT_MSG(begin_index <= end_index, "string ends before begin");
|
|
|
|
result.clear();
|
|
|
|
result.resize(end_index - begin_index);
|
|
|
|
std::copy(
|
|
|
|
m_names_char_list.begin() + begin_index,
|
|
|
|
m_names_char_list.begin() + end_index,
|
|
|
|
result.begin()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-04-14 14:07:30 -04:00
|
|
|
QueryObjectsStorage::~QueryObjectsStorage() {
|
|
|
|
delete graph;
|
|
|
|
delete nodeHelpDesk;
|
|
|
|
}
|