allow old capitalized option names in routed, few other adjustments

This commit is contained in:
Emil Tin 2013-09-24 19:21:02 +02:00
parent c4904cc365
commit 644fad8355
2 changed files with 84 additions and 53 deletions

View File

@ -22,22 +22,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "QueryObjectsStorage.h" #include "QueryObjectsStorage.h"
QueryObjectsStorage::QueryObjectsStorage(boost::unordered_map<const std::string,boost::filesystem::path>& paths) { QueryObjectsStorage::QueryObjectsStorage(boost::unordered_map<const std::string,boost::filesystem::path>& paths) {
if( paths["hsgr"].empty() ) { if( paths["hsgrdata"].empty() ) {
throw OSRMException("no hsgr file given in ini file"); throw OSRMException("no hsgr file given in ini file");
} }
if( paths["ramIndex"].empty() ) { if( paths["ramindex"].empty() ) {
throw OSRMException("no ram index file given in ini file"); throw OSRMException("no ram index file given in ini file");
} }
if( paths["fileIndex"].empty() ) { if( paths["fileindex"].empty() ) {
throw OSRMException("no mem index file given in ini file"); throw OSRMException("no mem index file given in ini file");
} }
if( paths["nodes"].empty() ) { if( paths["nodesdata"].empty() ) {
throw OSRMException("no nodes file given in ini file"); throw OSRMException("no nodes file given in ini file");
} }
if( paths["edges"].empty() ) { if( paths["edgesdata"].empty() ) {
throw OSRMException("no edges file given in ini file"); throw OSRMException("no edges file given in ini file");
} }
if( paths["names"].empty() ) { if( paths["namesdata"].empty() ) {
throw OSRMException("no names file given in ini file"); throw OSRMException("no names file given in ini file");
} }
@ -46,7 +46,7 @@ QueryObjectsStorage::QueryObjectsStorage(boost::unordered_map<const std::string,
std::vector< QueryGraph::_StrNode> node_list; std::vector< QueryGraph::_StrNode> node_list;
std::vector< QueryGraph::_StrEdge> edge_list; std::vector< QueryGraph::_StrEdge> edge_list;
const int number_of_nodes = readHSGRFromStream( const int number_of_nodes = readHSGRFromStream(
paths["hsgr"].c_str(), paths["hsgrdata"].c_str(),
node_list, node_list,
edge_list, edge_list,
&check_sum &check_sum
@ -77,10 +77,10 @@ QueryObjectsStorage::QueryObjectsStorage(boost::unordered_map<const std::string,
SimpleLogger().Write() << "Loading auxiliary information"; SimpleLogger().Write() << "Loading auxiliary information";
//Init nearest neighbor data structure //Init nearest neighbor data structure
nodeHelpDesk = new NodeInformationHelpDesk( nodeHelpDesk = new NodeInformationHelpDesk(
paths["ramIndex"].c_str(), paths["ramindex"].c_str(),
paths["fileIndex"].c_str(), paths["fileindex"].c_str(),
paths["nodes"].c_str(), paths["nodesdata"].c_str(),
paths["edges"].c_str(), paths["edgesdata"].c_str(),
number_of_nodes, number_of_nodes,
check_sum check_sum
); );
@ -88,14 +88,14 @@ QueryObjectsStorage::QueryObjectsStorage(boost::unordered_map<const std::string,
//deserialize street name list //deserialize street name list
SimpleLogger().Write() << "Loading names index"; SimpleLogger().Write() << "Loading names index";
if ( !boost::filesystem::exists( paths["names"] ) ) { if ( !boost::filesystem::exists( paths["namesdata"] ) ) {
throw OSRMException("names file does not exist"); throw OSRMException("names file does not exist");
} }
if ( 0 == boost::filesystem::file_size( paths["names"] ) ) { if ( 0 == boost::filesystem::file_size( paths["namesdata"] ) ) {
throw OSRMException("names file is empty"); throw OSRMException("names file is empty");
} }
boost::filesystem::ifstream name_stream(paths["names"], std::ios::binary); boost::filesystem::ifstream name_stream(paths["namesdata"], std::ios::binary);
unsigned size = 0; unsigned size = 0;
name_stream.read((char *)&size, sizeof(unsigned)); name_stream.read((char *)&size, sizeof(unsigned));
BOOST_ASSERT_MSG(0 != size, "name file broken"); BOOST_ASSERT_MSG(0 != size, "name file broken");

View File

@ -40,6 +40,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/date_time.hpp> #include <boost/date_time.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/regex.hpp>
#include <iostream> #include <iostream>
@ -85,22 +86,22 @@ int main (int argc, char * argv[]) {
("version,v", "Show version") ("version,v", "Show version")
("help,h", "Show this help message") ("help,h", "Show this help message")
("config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])->default_value("server.ini"), ("config,c", boost::program_options::value<boost::filesystem::path>(&paths["config"])->default_value("server.ini"),
"Path to a configuration file."); "Path to a configuration file");
// declare a group of options that will be allowed both on command line and in config file // declare a group of options that will be allowed both on command line and in config file
boost::program_options::options_description config_options("Configuration"); boost::program_options::options_description config_options("Configuration");
config_options.add_options() config_options.add_options()
("hsgr", boost::program_options::value<boost::filesystem::path>(&paths["hsgr"]), ("hsgrdata", boost::program_options::value<boost::filesystem::path>(&paths["hsgrdata"]),
"HSGR file") "HSGR file")
("nodes", boost::program_options::value<boost::filesystem::path>(&paths["nodes"]), ("nodesdata", boost::program_options::value<boost::filesystem::path>(&paths["nodesdata"]),
"Nodes file") "Nodes file")
("edges", boost::program_options::value<boost::filesystem::path>(&paths["edges"]), ("edgesdata", boost::program_options::value<boost::filesystem::path>(&paths["edgesdata"]),
"Edges file") "Edges file")
("ram-index", boost::program_options::value<boost::filesystem::path>(&paths["ramIndex"]), ("ramindex", boost::program_options::value<boost::filesystem::path>(&paths["ramindex"]),
"RAM index file") "RAM index file")
("file-index", boost::program_options::value<boost::filesystem::path>(&paths["fileIndex"]), ("fileindex", boost::program_options::value<boost::filesystem::path>(&paths["fileindex"]),
"File index file") "File index file")
("names", boost::program_options::value<boost::filesystem::path>(&paths["names"]), ("namesdata", boost::program_options::value<boost::filesystem::path>(&paths["namesdata"]),
"Names file") "Names file")
("timestamp", boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]), ("timestamp", boost::program_options::value<boost::filesystem::path>(&paths["timestamp"]),
"Timestamp file") "Timestamp file")
@ -108,18 +109,18 @@ int main (int argc, char * argv[]) {
"IP address") "IP address")
("port,p", boost::program_options::value<int>(&ip_port)->default_value(5000), ("port,p", boost::program_options::value<int>(&ip_port)->default_value(5000),
"IP Port") "IP Port")
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(10), ("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
"Number of threads to use"); "Number of threads to use");
// hidden options, will be allowed both on command line and in config file, but will not be shown to the user // hidden options, will be allowed both on command line and in config file, but will not be shown to the user
boost::program_options::options_description hidden_options("Hidden options"); boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options() hidden_options.add_options()
("input,i", boost::program_options::value<boost::filesystem::path>(&paths["input"]), ("base,b", boost::program_options::value<boost::filesystem::path>(&paths["base"]),
"Input file in .osrm format"); "base path to .osrm file, other wil be located in the same folder");
// positional option // positional option
boost::program_options::positional_options_description positional_options; boost::program_options::positional_options_description positional_options;
positional_options.add("input", 1); positional_options.add("base", 1);
// combine above options for parsing // combine above options for parsing
boost::program_options::options_description cmdline_options; boost::program_options::options_description cmdline_options;
@ -128,7 +129,7 @@ int main (int argc, char * argv[]) {
boost::program_options::options_description config_file_options; boost::program_options::options_description config_file_options;
config_file_options.add(config_options).add(hidden_options); config_file_options.add(config_options).add(hidden_options);
boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osrm> [<options>]"); boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <base.osrm> [<options>]");
visible_options.add(generic_options).add(config_options); visible_options.add(generic_options).add(config_options);
// parse command line options // parse command line options
@ -150,44 +151,75 @@ int main (int argc, char * argv[]) {
// parse config file // parse config file
if(boost::filesystem::is_regular_file(paths["config"])) { if(boost::filesystem::is_regular_file(paths["config"])) {
std::ifstream ifs(paths["config"].c_str());
SimpleLogger().Write() << "Reading options from: " << paths["config"].c_str(); SimpleLogger().Write() << "Reading options from: " << paths["config"].c_str();
boost::program_options::store(parse_config_file(ifs, config_file_options), option_variables); std::ifstream config_stream(paths["config"].c_str());
std::string config_str( (std::istreambuf_iterator<char>(config_stream)), std::istreambuf_iterator<char>() );
//support old capitalized option names by downcasing them with a regex replace
boost::regex option_name_regex( "^([^=]*)" ); //match from start of line to '='
std::string option_name_format( "\\L$1\\E" ); //replace with downcased substring
std::string modified_config_str = boost::regex_replace( config_str, option_name_regex, option_name_format );
std::stringstream modified_stream(modified_config_str);
boost::program_options::store(parse_config_file(modified_stream, config_file_options), option_variables);
boost::program_options::notify(option_variables); boost::program_options::notify(option_variables);
} }
if(!option_variables.count("hsgr")) { if(!option_variables.count("hsgrdata")) {
paths["hsgr"] = std::string( paths["input"].c_str()) + ".hsgr"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "hsgrdata (or base) must be specified";
return -1;
}
paths["hsgrdata"] = std::string( paths["base"].c_str()) + ".hsgr";
} }
if(!option_variables.count("nodes")) { if(!option_variables.count("nodesdata")) {
paths["nodes"] = std::string( paths["input"].c_str()) + ".nodes"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "nodesdata (or base) must be specified";
return -1;
}
paths["nodesdata"] = std::string( paths["base"].c_str()) + ".nodes";
} }
if(!option_variables.count("edges")) { if(!option_variables.count("edgesdata")) {
paths["edges"] = std::string( paths["input"].c_str()) + ".edges"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "edgesdata (or base) must be specified";
return -1;
}
paths["edgesdata"] = std::string( paths["base"].c_str()) + ".edges";
} }
if(!option_variables.count("ram")) { if(!option_variables.count("ramindex")) {
paths["ramIndex"] = std::string( paths["input"].c_str()) + ".ramIndex"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "ramindex (or base) must be specified";
return -1;
}
paths["ramindex"] = std::string( paths["base"].c_str()) + ".ramIndex";
} }
if(!option_variables.count("index")) { if(!option_variables.count("fileindex")) {
paths["fileIndex"] = std::string( paths["input"].c_str()) + ".fileIndex"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "fileindex (or base) must be specified";
return -1;
}
paths["fileindex"] = std::string( paths["base"].c_str()) + ".fileIndex";
} }
if(!option_variables.count("names")) { if(!option_variables.count("namesdata")) {
paths["names"] = std::string( paths["input"].c_str()) + ".names"; if(!option_variables.count("base")) {
SimpleLogger().Write(logWARNING) << "namesdata (or base) must be specified";
return -1;
}
paths["namesdata"] = std::string( paths["base"].c_str()) + ".names";
} }
if(!option_variables.count("timestamp")) { if(!option_variables.count("timestamp")) {
paths["timestamp"] = std::string( paths["input"].c_str()) + ".timestamp"; if(!option_variables.count("base")) {
} SimpleLogger().Write(logWARNING) << "timestamp (or base) must be specified";
if(!option_variables.count("input")) {
SimpleLogger().Write(logWARNING) << "No input file specified";
return -1; return -1;
} }
paths["timestamp"] = std::string( paths["base"].c_str()) + ".timestamp";
}
if(1 > requested_num_threads) { if(1 > requested_num_threads) {
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger"; SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
@ -197,13 +229,12 @@ int main (int argc, char * argv[]) {
SimpleLogger().Write() << SimpleLogger().Write() <<
"starting up engines, " << g_GIT_DESCRIPTION << ", compiled at " << __DATE__ << ", " __TIME__; "starting up engines, " << g_GIT_DESCRIPTION << ", compiled at " << __DATE__ << ", " __TIME__;
SimpleLogger().Write() << "Input file:\t" << paths["input"].c_str(); SimpleLogger().Write() << "HSGR file:\t" << paths["hsgrdata"].c_str();
SimpleLogger().Write() << "HSGR file:\t" << paths["hsgr"].c_str(); SimpleLogger().Write() << "Nodes file:\t" << paths["nodesdata"].c_str();
SimpleLogger().Write() << "Nodes file:\t" << paths["nodes"].c_str(); SimpleLogger().Write() << "Edges file:\t" << paths["edgesdata"].c_str();
SimpleLogger().Write() << "Edges file:\t" << paths["edges"].c_str(); SimpleLogger().Write() << "RAM file:\t" << paths["ramindex"].c_str();
SimpleLogger().Write() << "RAM file:\t" << paths["ramIndex"].c_str(); SimpleLogger().Write() << "Index file:\t" << paths["fileindex"].c_str();
SimpleLogger().Write() << "Index file:\t" << paths["fileIndex"].c_str(); SimpleLogger().Write() << "Names file:\t" << paths["namesdata"].c_str();
SimpleLogger().Write() << "Names file:\t" << paths["names"].c_str();
SimpleLogger().Write() << "Timestamp file:\t" << paths["timestamp"].c_str(); SimpleLogger().Write() << "Timestamp file:\t" << paths["timestamp"].c_str();
SimpleLogger().Write() << "Threads:\t" << requested_num_threads; SimpleLogger().Write() << "Threads:\t" << requested_num_threads;
SimpleLogger().Write() << "IP address:\t" << ip_address; SimpleLogger().Write() << "IP address:\t" << ip_address;