forked from knoepfle/matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extractor.cpp
149 lines (129 loc) · 5.1 KB
/
extractor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
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 "Extractor/ExtractorCallbacks.h"
#include "Extractor/ExtractionContainers.h"
#include "Extractor/ScriptingEnvironment.h"
#include "Extractor/PBFParser.h"
#include "Extractor/XMLParser.h"
#include "Util/IniFile.h"
#include "Util/InputFileUtil.h"
#include "Util/MachineInfo.h"
#include "Util/OpenMPWrapper.h"
#include "Util/OSRMException.h"
#include "Util/SimpleLogger.h"
#include "Util/StringUtil.h"
#include "Util/UUID.h"
#include "typedefs.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
ExtractorCallbacks * extractCallBacks;
UUID uuid;
int main (int argc, char *argv[]) {
try {
LogPolicy::GetInstance().Unmute();
double startup_time = get_timestamp();
if(argc < 2) {
SimpleLogger().Write(logWARNING) <<
"usage: \n" <<
argv[0] <<
" <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]";
return -1;
}
/*** Setup Scripting Environment ***/
ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua"));
unsigned number_of_threads = omp_get_num_procs();
if(testDataFile("extractor.ini")) {
IniFile extractorConfig("extractor.ini");
unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));
if( rawNumber != 0 && rawNumber <= number_of_threads) {
number_of_threads = rawNumber;
}
}
omp_set_num_threads(number_of_threads);
SimpleLogger().Write() << "extracting data from input file " << argv[1];
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;
}
}
if(pos==std::string::npos) {
pos = output_file_name.find(".pbf");
if(pos!=std::string::npos) {
file_has_pbf_format = true;
}
}
if(pos!=std::string::npos) {
output_file_name.replace(pos, 8, ".osrm");
restrictionsFileName.replace(pos, 8, ".osrm.restrictions");
} else {
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");
}
}
unsigned amountOfRAM = 1;
unsigned installedRAM = GetPhysicalmemory();
if(installedRAM < 2048264) {
SimpleLogger().Write(logWARNING) << "Machine has less than 2GB RAM.";
}
StringMap stringMap;
ExtractionContainers externalMemory;
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);
}
if(!parser->ReadHeader()) {
throw OSRMException("Parser not initialized!");
}
SimpleLogger().Write() << "Parsing in progress..";
double parsing_start_time = get_timestamp();
parser->Parse();
SimpleLogger().Write() << "Parsing finished after " <<
(get_timestamp() - parsing_start_time) <<
" seconds";
externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM);
delete parser;
delete extractCallBacks;
SimpleLogger().Write() <<
"extraction finished after " << get_timestamp() - startup_time <<
"s";
SimpleLogger().Write() << "\nRun:\n./osrm-prepare " <<
output_file_name <<
" " <<
restrictionsFileName <<
std::endl;
} catch(std::exception & e) {
SimpleLogger().Write(logWARNING) << "unhandled exception: " << e.what();
return -1;
}
return 0;
}