osrm-backend/extractor.cpp

150 lines
5.1 KiB
C++
Raw Normal View History

/*
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.
*/
2011-11-24 13:37:49 -05:00
#include "Extractor/ExtractorCallbacks.h"
#include "Extractor/ExtractionContainers.h"
#include "Extractor/ScriptingEnvironment.h"
2012-08-27 11:40:59 -04:00
#include "Extractor/PBFParser.h"
#include "Extractor/XMLParser.h"
#include "Util/IniFile.h"
#include "Util/InputFileUtil.h"
2011-05-07 03:36:17 -04:00
#include "Util/MachineInfo.h"
#include "Util/OpenMPWrapper.h"
2013-08-05 11:28:57 -04:00
#include "Util/OSRMException.h"
#include "Util/SimpleLogger.h"
#include "Util/StringUtil.h"
#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>
ExtractorCallbacks * extractCallBacks;
UUID uuid;
int main (int argc, char *argv[]) {
2013-06-27 11:44:32 -04:00
try {
LogPolicy::GetInstance().Unmute();
2013-06-27 11:44:32 -04:00
double startup_time = get_timestamp();
2013-06-27 11:44:32 -04:00
if(argc < 2) {
SimpleLogger().Write(logWARNING) <<
2013-08-05 11:28:57 -04:00
"usage: \n" <<
argv[0] <<
" <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]";
2013-08-05 11:28:57 -04:00
return -1;
2013-06-27 11:44:32 -04:00
}
2011-12-01 09:12:30 -05:00
2013-06-27 11:44:32 -04:00
/*** Setup Scripting Environment ***/
ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"));
2012-11-22 13:24:34 -05:00
2013-06-27 11:44:32 -04:00
unsigned number_of_threads = omp_get_num_procs();
if(testDataFile("extractor.ini")) {
IniFile extractorConfig("extractor.ini");
2013-06-27 11:44:32 -04:00
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
if( rawNumber != 0 && rawNumber <= number_of_threads) {
number_of_threads = rawNumber;
}
2013-06-26 20:05:03 -04:00
}
2013-06-27 11:44:32 -04:00
omp_set_num_threads(number_of_threads);
SimpleLogger().Write() << "extracting data from input file " << argv[1];
2013-06-27 11:44:32 -04:00
bool file_has_pbf_format(false);
std::string output_file_name(argv[1]);
std::string restrictionsFileName(argv[1]);
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
}
}
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");
} 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");
}
}
2013-06-27 11:44:32 -04:00
unsigned amountOfRAM = 1;
unsigned installedRAM = GetPhysicalmemory();
if(installedRAM < 2048264) {
SimpleLogger().Write(logWARNING) << "Machine has less than 2GB RAM.";
2013-06-27 11:44:32 -04:00
}
2013-06-24 16:47:35 -04:00
2013-06-27 11:44:32 -04:00
StringMap stringMap;
ExtractionContainers externalMemory;
2013-06-27 11:44:32 -04:00
stringMap[""] = 0;
extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap);
BaseParser* parser;
if(file_has_pbf_format) {
parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment);
} else {
parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment);
}
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
}
SimpleLogger().Write() << "Parsing in progress..";
2013-06-27 11:44:32 -04:00
double parsing_start_time = get_timestamp();
parser->Parse();
SimpleLogger().Write() << "Parsing finished after " <<
2013-06-27 11:44:32 -04:00
(get_timestamp() - parsing_start_time) <<
" seconds";
2013-06-27 11:44:32 -04:00
externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM);
delete parser;
delete extractCallBacks;
SimpleLogger().Write() <<
"extraction finished after " << get_timestamp() - startup_time <<
"s";
2013-06-27 11:44:32 -04:00
SimpleLogger().Write() << "\nRun:\n./osrm-prepare " <<
2013-08-05 11:28:57 -04:00
output_file_name <<
" " <<
restrictionsFileName <<
std::endl;
2013-06-27 11:44:32 -04:00
} catch(std::exception & e) {
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;
}