2010-07-15 10:45:43 -04:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-11-24 13:37:49 -05:00
|
|
|
|
2012-08-29 12:33:18 -04:00
|
|
|
#include "Extractor/ExtractorCallbacks.h"
|
2012-08-30 10:59:41 -04:00
|
|
|
#include "Extractor/ExtractionContainers.h"
|
2012-11-19 13:04:59 -05:00
|
|
|
#include "Extractor/ScriptingEnvironment.h"
|
2012-08-27 11:40:59 -04:00
|
|
|
#include "Extractor/PBFParser.h"
|
|
|
|
#include "Extractor/XMLParser.h"
|
2013-08-10 07:29:24 -04:00
|
|
|
#include "Util/GitDescription.h"
|
2011-05-07 03:36:17 -04:00
|
|
|
#include "Util/MachineInfo.h"
|
2013-01-01 18:33:14 -05:00
|
|
|
#include "Util/OpenMPWrapper.h"
|
2013-08-05 11:28:57 -04:00
|
|
|
#include "Util/OSRMException.h"
|
2013-08-10 07:29:24 -04:00
|
|
|
#include "Util/ProgramOptions.h"
|
2013-08-08 08:17:01 -04:00
|
|
|
#include "Util/SimpleLogger.h"
|
2012-11-22 11:23:31 -05:00
|
|
|
#include "Util/StringUtil.h"
|
2013-07-22 10:34:06 -04:00
|
|
|
#include "Util/UUID.h"
|
2013-06-24 16:47:35 -04:00
|
|
|
#include "typedefs.h"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2013-06-26 20:05:03 -04:00
|
|
|
|
2013-06-24 16:47:35 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
2011-10-04 09:42:24 -04:00
|
|
|
|
2011-01-14 11:54:42 -05:00
|
|
|
ExtractorCallbacks * extractCallBacks;
|
2013-07-22 10:34:06 -04:00
|
|
|
UUID uuid;
|
2011-01-09 16:42:27 -05:00
|
|
|
|
|
|
|
int main (int argc, char *argv[]) {
|
2013-06-27 11:44:32 -04:00
|
|
|
try {
|
2013-08-08 08:17:01 -04:00
|
|
|
LogPolicy::GetInstance().Unmute();
|
2013-06-27 11:44:32 -04:00
|
|
|
double startup_time = get_timestamp();
|
2013-08-10 07:29:24 -04:00
|
|
|
|
|
|
|
boost::filesystem::path config_file_path, input_path, profile_path;
|
|
|
|
int requested_num_threads;
|
|
|
|
|
|
|
|
// declare a group of options that will be allowed only on command line
|
|
|
|
boost::program_options::options_description generic_options("Options");
|
|
|
|
generic_options.add_options()
|
|
|
|
("version,v", "Show version")
|
|
|
|
("help,h", "Show this help message")
|
|
|
|
("config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)->default_value("extractor.ini"),
|
|
|
|
"Path to a configuration 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");
|
|
|
|
config_options.add_options()
|
|
|
|
("profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)->default_value("profile.lua"),
|
|
|
|
"Path to LUA routing profile")
|
2013-10-12 09:21:36 -04:00
|
|
|
("threads,t", boost::program_options::value<int>(&requested_num_threads)->default_value(8),
|
2013-08-10 07:29:24 -04:00
|
|
|
"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
|
|
|
|
boost::program_options::options_description hidden_options("Hidden options");
|
|
|
|
hidden_options.add_options()
|
|
|
|
("input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
|
|
|
|
"Input file in .osm, .osm.bz2 or .osm.pbf format");
|
|
|
|
|
|
|
|
// positional option
|
|
|
|
boost::program_options::positional_options_description positional_options;
|
|
|
|
positional_options.add("input", 1);
|
|
|
|
|
|
|
|
// combine above options for parsing
|
|
|
|
boost::program_options::options_description cmdline_options;
|
|
|
|
cmdline_options.add(generic_options).add(config_options).add(hidden_options);
|
|
|
|
|
|
|
|
boost::program_options::options_description config_file_options;
|
|
|
|
config_file_options.add(config_options).add(hidden_options);
|
|
|
|
|
2013-12-04 05:08:21 -05:00
|
|
|
boost::program_options::options_description visible_options(boost::filesystem::basename(argv[0]) + " <input.osm/.osm.bz2/.osm.pbf> [options]");
|
2013-08-10 07:29:24 -04:00
|
|
|
visible_options.add(generic_options).add(config_options);
|
|
|
|
|
|
|
|
// parse command line options
|
|
|
|
boost::program_options::variables_map option_variables;
|
|
|
|
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
|
|
|
|
options(cmdline_options).positional(positional_options).run(), option_variables);
|
|
|
|
|
|
|
|
if(option_variables.count("version")) {
|
|
|
|
SimpleLogger().Write() << g_GIT_DESCRIPTION;
|
|
|
|
return 0;
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2011-12-01 09:12:30 -05:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
if(option_variables.count("help")) {
|
|
|
|
SimpleLogger().Write() << visible_options;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-22 13:24:34 -05:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
boost::program_options::notify(option_variables);
|
2013-08-14 05:59:46 -04:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
// parse config file
|
|
|
|
if(boost::filesystem::is_regular_file(config_file_path)) {
|
2013-09-24 15:50:20 -04:00
|
|
|
SimpleLogger().Write() << "Reading options from: " << config_file_path.c_str();
|
|
|
|
std::string config_str;
|
|
|
|
PrepareConfigFile( config_file_path.c_str(), config_str );
|
|
|
|
std::stringstream config_stream( config_str );
|
|
|
|
boost::program_options::store(parse_config_file(config_stream, config_file_options), option_variables);
|
2013-08-10 07:29:24 -04:00
|
|
|
boost::program_options::notify(option_variables);
|
2013-06-26 20:05:03 -04:00
|
|
|
}
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
if(!option_variables.count("input")) {
|
|
|
|
SimpleLogger().Write(logWARNING) << "No input file specified";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1 > requested_num_threads) {
|
|
|
|
SimpleLogger().Write(logWARNING) << "Number of threads must be 1 or larger";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleLogger().Write() << "Input file: " << input_path.filename().string();
|
|
|
|
SimpleLogger().Write() << "Profile: " << profile_path.filename().string();
|
|
|
|
SimpleLogger().Write() << "Threads: " << requested_num_threads;
|
|
|
|
|
|
|
|
/*** Setup Scripting Environment ***/
|
|
|
|
ScriptingEnvironment scriptingEnvironment(profile_path.c_str());
|
|
|
|
|
|
|
|
omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) );
|
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
bool file_has_pbf_format(false);
|
2013-08-10 07:29:24 -04:00
|
|
|
std::string output_file_name(input_path.c_str());
|
|
|
|
std::string restrictionsFileName(input_path.c_str());
|
2013-06-27 11:44:32 -04:00
|
|
|
std::string::size_type pos = output_file_name.find(".osm.bz2");
|
|
|
|
if(pos==std::string::npos) {
|
|
|
|
pos = output_file_name.find(".osm.pbf");
|
|
|
|
if(pos!=std::string::npos) {
|
|
|
|
file_has_pbf_format = true;
|
2013-07-17 07:20:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(pos==std::string::npos) {
|
|
|
|
pos = output_file_name.find(".pbf");
|
|
|
|
if(pos!=std::string::npos) {
|
|
|
|
file_has_pbf_format = true;
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2011-01-12 13:08:10 -05:00
|
|
|
}
|
2012-12-29 15:02:26 -05:00
|
|
|
if(pos!=std::string::npos) {
|
2013-06-27 11:44:32 -04:00
|
|
|
output_file_name.replace(pos, 8, ".osrm");
|
|
|
|
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
|
2011-01-12 13:08:10 -05:00
|
|
|
} else {
|
2013-06-27 11:44:32 -04:00
|
|
|
pos=output_file_name.find(".osm");
|
|
|
|
if(pos!=std::string::npos) {
|
|
|
|
output_file_name.replace(pos, 5, ".osrm");
|
|
|
|
restrictionsFileName.replace(pos, 5, ".osrm.restrictions");
|
|
|
|
} else {
|
|
|
|
output_file_name.append(".osrm");
|
|
|
|
restrictionsFileName.append(".osrm.restrictions");
|
|
|
|
}
|
2011-01-12 13:08:10 -05:00
|
|
|
}
|
2011-03-24 11:06:49 -04:00
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
StringMap stringMap;
|
|
|
|
ExtractionContainers externalMemory;
|
2011-01-12 13:08:10 -05:00
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
stringMap[""] = 0;
|
|
|
|
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
|
|
|
|
BaseParser* parser;
|
|
|
|
if(file_has_pbf_format) {
|
2013-08-10 07:29:24 -04:00
|
|
|
parser = new PBFParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
|
2013-06-27 11:44:32 -04:00
|
|
|
} else {
|
2013-08-10 07:29:24 -04:00
|
|
|
parser = new XMLParser(input_path.c_str(), extractCallBacks, scriptingEnvironment);
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2013-06-24 16:47:35 -04:00
|
|
|
|
2013-06-27 11:44:32 -04:00
|
|
|
if(!parser->ReadHeader()) {
|
2013-08-05 11:28:57 -04:00
|
|
|
throw OSRMException("Parser not initialized!");
|
2013-06-27 11:44:32 -04:00
|
|
|
}
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Parsing in progress..";
|
2013-06-27 11:44:32 -04:00
|
|
|
double parsing_start_time = get_timestamp();
|
|
|
|
parser->Parse();
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() << "Parsing finished after " <<
|
2013-06-27 11:44:32 -04:00
|
|
|
(get_timestamp() - parsing_start_time) <<
|
2013-08-08 08:17:01 -04:00
|
|
|
" seconds";
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2013-11-13 11:09:20 -05:00
|
|
|
externalMemory.PrepareData(output_file_name, restrictionsFileName);
|
2013-06-27 11:44:32 -04:00
|
|
|
|
|
|
|
delete parser;
|
|
|
|
delete extractCallBacks;
|
|
|
|
|
2013-08-08 08:17:01 -04:00
|
|
|
SimpleLogger().Write() <<
|
|
|
|
"extraction finished after " << get_timestamp() - startup_time <<
|
|
|
|
"s";
|
2013-06-27 11:44:32 -04:00
|
|
|
|
2013-08-19 16:41:46 -04:00
|
|
|
SimpleLogger().Write() << "To prepare the data for routing, run: "
|
2013-10-12 09:21:36 -04:00
|
|
|
<< "./osrm-prepare " << output_file_name << std::endl;
|
2013-08-19 16:41:46 -04:00
|
|
|
|
2013-08-10 07:29:24 -04:00
|
|
|
} catch(boost::program_options::too_many_positional_options_error& e) {
|
|
|
|
SimpleLogger().Write(logWARNING) << "Only one input file can be specified";
|
|
|
|
return -1;
|
|
|
|
} catch(boost::program_options::error& e) {
|
|
|
|
SimpleLogger().Write(logWARNING) << e.what();
|
|
|
|
return -1;
|
2013-06-27 11:44:32 -04:00
|
|
|
} catch(std::exception & e) {
|
2013-08-10 07:29:24 -04:00
|
|
|
SimpleLogger().Write(logWARNING) << "Unhandled exception: " << e.what();
|
2013-08-05 11:28:57 -04:00
|
|
|
return -1;
|
2013-02-10 12:28:04 -05:00
|
|
|
}
|
2013-08-05 11:28:57 -04:00
|
|
|
return 0;
|
2010-07-15 10:45:43 -04:00
|
|
|
}
|