use exceptions instead of hard abort
This commit is contained in:
parent
ec7d3a9885
commit
54302a53e1
@ -434,8 +434,9 @@ public:
|
||||
|
||||
p.printStatus(numberOfContractedNodes);
|
||||
}
|
||||
BOOST_FOREACH(_ThreadData * data, threadData)
|
||||
BOOST_FOREACH(_ThreadData * data, threadData) {
|
||||
delete data;
|
||||
}
|
||||
threadData.clear();
|
||||
}
|
||||
|
||||
|
@ -21,11 +21,7 @@
|
||||
#include "TemporaryStorage.h"
|
||||
|
||||
TemporaryStorage::TemporaryStorage() {
|
||||
try {
|
||||
tempDirectory = boost::filesystem::temp_directory_path();
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
ERR("could not retrieve location of temporary path: " << e.what());
|
||||
}
|
||||
tempDirectory = boost::filesystem::temp_directory_path();
|
||||
}
|
||||
|
||||
TemporaryStorage & TemporaryStorage::GetInstance(){
|
||||
@ -39,12 +35,8 @@ TemporaryStorage::~TemporaryStorage() {
|
||||
|
||||
void TemporaryStorage::removeAll() {
|
||||
boost::mutex::scoped_lock lock(mutex);
|
||||
try {
|
||||
for(unsigned slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID)
|
||||
deallocateSlot(slotID);
|
||||
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
ERR("could not retrieve location of temporary path: " << e.what());
|
||||
for(unsigned slot_id = 0; slot_id < vectorOfStreamDatas.size(); ++slot_id) {
|
||||
deallocateSlot(slot_id);
|
||||
}
|
||||
vectorOfStreamDatas.clear();
|
||||
}
|
||||
@ -64,13 +56,13 @@ void TemporaryStorage::deallocateSlot(int slotID) {
|
||||
try {
|
||||
StreamData & data = vectorOfStreamDatas[slotID];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
if(!boost::filesystem::exists(data.pathToTemporaryFile)) {
|
||||
if(!boost::filesystem::exists(data.pathToTemporaryFile)) {
|
||||
return;
|
||||
}
|
||||
if(data.streamToTemporaryFile->is_open())
|
||||
if(data.streamToTemporaryFile->is_open()) {
|
||||
data.streamToTemporaryFile->close();
|
||||
}
|
||||
|
||||
//INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile);
|
||||
boost::filesystem::remove(data.pathToTemporaryFile);
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
abort(e);
|
||||
@ -81,8 +73,10 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s
|
||||
try {
|
||||
StreamData & data = vectorOfStreamDatas[slotID];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
if(!data.writeMode)
|
||||
ERR("Writing after first read is not allowed");
|
||||
BOOST_ASSERT_MSG(
|
||||
data.writeMode,
|
||||
"Writing after first read is not allowed"
|
||||
);
|
||||
data.streamToTemporaryFile->write(pointer, size);
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
abort(e);
|
||||
@ -121,13 +115,11 @@ boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) {
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
abort(e);
|
||||
}
|
||||
// INFO("telling position: " << position);
|
||||
return position;
|
||||
}
|
||||
|
||||
void TemporaryStorage::abort(boost::filesystem::filesystem_error& ) {
|
||||
removeAll();
|
||||
// ERR("I/O Error occured: " << e.what());
|
||||
}
|
||||
|
||||
void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) {
|
||||
@ -135,7 +127,6 @@ void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type pos
|
||||
StreamData & data = vectorOfStreamDatas[slotID];
|
||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||
data.streamToTemporaryFile->seekg(position);
|
||||
// INFO("seeking to position: " << position);
|
||||
} catch(boost::filesystem::filesystem_error & e) {
|
||||
abort(e);
|
||||
}
|
||||
|
@ -24,12 +24,14 @@
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
//This is one big workaround for latest boost renaming woes.
|
||||
@ -102,8 +104,9 @@ private:
|
||||
streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
|
||||
readWriteMutex(new boost::mutex)
|
||||
{
|
||||
if(streamToTemporaryFile->fail())
|
||||
ERR("Aborting, because temporary file at " << pathToTemporaryFile << " could not be created");
|
||||
if(streamToTemporaryFile->fail()) {
|
||||
throw OSRMException("temporary file could not be created");
|
||||
}
|
||||
}
|
||||
};
|
||||
//vector of file streams that is used to store temporary data
|
||||
|
@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef EDGE_H
|
||||
#define EDGE_H
|
||||
|
||||
|
||||
#include "../Util/OSRMException.h"
|
||||
#include <cassert>
|
||||
|
||||
class NodeBasedEdge {
|
||||
@ -40,8 +42,34 @@ public:
|
||||
return (source() < e.source());
|
||||
}
|
||||
|
||||
explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig, bool ar, bool cf) :
|
||||
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), _contraFlow(cf) { if(ty < 0) {ERR("Type: " << ty);}; }
|
||||
explicit NodeBasedEdge(
|
||||
NodeID s,
|
||||
NodeID t,
|
||||
NodeID n,
|
||||
EdgeWeight w,
|
||||
bool f,
|
||||
bool b,
|
||||
short ty,
|
||||
bool ra,
|
||||
bool ig,
|
||||
bool ar,
|
||||
bool cf
|
||||
) : _source(s),
|
||||
_target(t),
|
||||
_name(n),
|
||||
_weight(w),
|
||||
forward(f),
|
||||
backward(b),
|
||||
_type(ty),
|
||||
_roundabout(ra),
|
||||
_ignoreInGrid(ig),
|
||||
_accessRestricted(ar),
|
||||
_contraFlow(cf)
|
||||
{
|
||||
if(ty < 0) {
|
||||
throw OSRMException("negative edge type");
|
||||
}
|
||||
}
|
||||
|
||||
NodeID target() const {return _target; }
|
||||
NodeID source() const {return _source; }
|
||||
|
@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "PhantomNodes.h"
|
||||
#include "StaticRTree.h"
|
||||
#include "../Contractor/EdgeBasedGraphFactory.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
@ -126,10 +127,14 @@ private:
|
||||
const std::string & nodes_file,
|
||||
const std::string & edges_file
|
||||
) {
|
||||
std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary);
|
||||
if(!nodes_input_stream) { ERR(nodes_file << " not found"); }
|
||||
std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary);
|
||||
if(!edges_input_stream) { ERR(edges_file << " not found"); }
|
||||
std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary);
|
||||
if(!nodes_input_stream) {
|
||||
throw OSRMException("nodes file not found");
|
||||
}
|
||||
std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary);
|
||||
if(!edges_input_stream) {
|
||||
throw OSRMException("edges file not found");
|
||||
}
|
||||
|
||||
DEBUG("Loading node data");
|
||||
NodeInfo b;
|
||||
|
@ -29,7 +29,9 @@ extractor_callbacks(ec), scriptingEnvironment(se), luaState(NULL), use_turn_rest
|
||||
|
||||
void BaseParser::ReadUseRestrictionsSetting() {
|
||||
if( 0 != luaL_dostring( luaState, "return use_turn_restrictions\n") ) {
|
||||
ERR(lua_tostring( luaState,-1)<< " occured in scripting block");
|
||||
throw OSRMException(
|
||||
/*lua_tostring( luaState, -1 ) + */"ERROR occured in scripting block"
|
||||
);
|
||||
}
|
||||
if( lua_isboolean( luaState, -1) ) {
|
||||
use_turn_restrictions = lua_toboolean(luaState, -1);
|
||||
@ -44,20 +46,14 @@ void BaseParser::ReadUseRestrictionsSetting() {
|
||||
void BaseParser::ReadRestrictionExceptions() {
|
||||
if(lua_function_exists(luaState, "get_exceptions" )) {
|
||||
//get list of turn restriction exceptions
|
||||
try {
|
||||
luabind::call_function<void>(
|
||||
luaState,
|
||||
"get_exceptions",
|
||||
boost::ref(restriction_exceptions)
|
||||
);
|
||||
INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction");
|
||||
BOOST_FOREACH(std::string & str, restriction_exceptions) {
|
||||
INFO(" " << str);
|
||||
}
|
||||
} catch (const luabind::error &er) {
|
||||
lua_State* Ler=er.state();
|
||||
report_errors(Ler, -1);
|
||||
ERR(er.what());
|
||||
luabind::call_function<void>(
|
||||
luaState,
|
||||
"get_exceptions",
|
||||
boost::ref(restriction_exceptions)
|
||||
);
|
||||
INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction");
|
||||
BOOST_FOREACH(const std::string & str, restriction_exceptions) {
|
||||
INFO(" " << str);
|
||||
}
|
||||
} else {
|
||||
INFO("Found no exceptions to turn restrictions");
|
||||
@ -72,37 +68,25 @@ void BaseParser::report_errors(lua_State *L, const int status) const {
|
||||
}
|
||||
|
||||
void BaseParser::ParseNodeInLua(ImportNode& n, lua_State* localLuaState) {
|
||||
try {
|
||||
luabind::call_function<void>( localLuaState, "node_function", boost::ref(n) );
|
||||
} catch (const luabind::error &er) {
|
||||
lua_State* Ler=er.state();
|
||||
report_errors(Ler, -1);
|
||||
ERR(er.what());
|
||||
}
|
||||
luabind::call_function<void>( localLuaState, "node_function", boost::ref(n) );
|
||||
}
|
||||
|
||||
void BaseParser::ParseWayInLua(ExtractionWay& w, lua_State* localLuaState) {
|
||||
if(2 > w.path.size()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
luabind::call_function<void>( localLuaState, "way_function", boost::ref(w) );
|
||||
} catch (const luabind::error &er) {
|
||||
lua_State* Ler=er.state();
|
||||
report_errors(Ler, -1);
|
||||
ERR(er.what());
|
||||
}
|
||||
luabind::call_function<void>( localLuaState, "way_function", boost::ref(w) );
|
||||
}
|
||||
|
||||
bool BaseParser::ShouldIgnoreRestriction(const std::string& except_tag_string) const {
|
||||
//should this restriction be ignored? yes if there's an overlap between:
|
||||
//a) the list of modes in the except tag of the restriction (except_tag_string), ex: except=bus;bicycle
|
||||
//b) the lua profile defines a hierachy of modes, ex: [access, vehicle, bicycle]
|
||||
|
||||
|
||||
if( "" == except_tag_string ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Be warned, this is quadratic work here, but we assume that
|
||||
//only a few exceptions are actually defined.
|
||||
std::vector<std::string> exceptions;
|
||||
|
@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
#include "ExtractorCallbacks.h"
|
||||
#include "ScriptingEnvironment.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
|
||||
extern "C" {
|
||||
#include <lua.h>
|
||||
|
@ -39,14 +39,10 @@ public:
|
||||
|
||||
ExtractionContainers() {
|
||||
//Check if another instance of stxxl is already running or if there is a general problem
|
||||
try {
|
||||
stxxl::vector<unsigned> testForRunningInstance;
|
||||
} catch(std::exception & e) {
|
||||
ERR("Could not instantiate STXXL layer." << std::endl << e.what());
|
||||
}
|
||||
|
||||
stxxl::vector<unsigned> testForRunningInstance;
|
||||
nameVector.push_back("");
|
||||
}
|
||||
|
||||
virtual ~ExtractionContainers() {
|
||||
usedNodeIDs.clear();
|
||||
allNodes.clear();
|
||||
|
@ -28,7 +28,7 @@ PBFParser::PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnv
|
||||
input.open(fileName, std::ios::in | std::ios::binary);
|
||||
|
||||
if (!input) {
|
||||
std::cerr << fileName << ": File not found." << std::endl;
|
||||
throw OSRMException("pbf file not found.");
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
@ -194,7 +194,9 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) {
|
||||
}
|
||||
|
||||
inline void PBFParser::parseNode(_ThreadData * ) {
|
||||
ERR("Parsing of simple nodes not supported. PBF should use dense nodes");
|
||||
throw OSRMException(
|
||||
"Parsing of simple nodes not supported. PBF should use dense nodes"
|
||||
);
|
||||
}
|
||||
|
||||
inline void PBFParser::parseRelation(_ThreadData * threadData) {
|
||||
@ -475,7 +477,7 @@ bool PBFParser::readNextBlock(std::fstream& stream, _ThreadData * threadData) {
|
||||
}
|
||||
|
||||
if ( !threadData->PBFprimitiveBlock.ParseFromArray( &(threadData->charBuffer[0]), threadData-> charBuffer.size() ) ) {
|
||||
ERR("failed to parse PrimitiveBlock");
|
||||
std::cerr << "failed to parse PrimitiveBlock" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "../DataStructures/ConcurrentQueue.h"
|
||||
#include "../Util/MachineInfo.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -40,59 +40,58 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
|
||||
|
||||
// Add our function to the state's global scope
|
||||
luabind::module(myLuaState) [
|
||||
luabind::def("print", LUA_print<std::string>),
|
||||
luabind::def("parseMaxspeed", parseMaxspeed),
|
||||
luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration)
|
||||
luabind::def("print", LUA_print<std::string>),
|
||||
luabind::def("parseMaxspeed", parseMaxspeed),
|
||||
luabind::def("durationIsValid", durationIsValid),
|
||||
luabind::def("parseDuration", parseDuration)
|
||||
];
|
||||
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<HashTable<std::string, std::string> >("keyVals")
|
||||
.def("Add", &HashTable<std::string, std::string>::Add)
|
||||
.def("Find", &HashTable<std::string, std::string>::Find)
|
||||
.def("Holds", &HashTable<std::string, std::string>::Holds)
|
||||
];
|
||||
luabind::class_<HashTable<std::string, std::string> >("keyVals")
|
||||
.def("Add", &HashTable<std::string, std::string>::Add)
|
||||
.def("Find", &HashTable<std::string, std::string>::Find)
|
||||
.def("Holds", &HashTable<std::string, std::string>::Holds)
|
||||
];
|
||||
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<ImportNode>("Node")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("lat", &ImportNode::lat)
|
||||
.def_readwrite("lon", &ImportNode::lon)
|
||||
.def_readwrite("id", &ImportNode::id)
|
||||
.def_readwrite("bollard", &ImportNode::bollard)
|
||||
.def_readwrite("traffic_light", &ImportNode::trafficLight)
|
||||
.def_readwrite("tags", &ImportNode::keyVals)
|
||||
];
|
||||
luabind::class_<ImportNode>("Node")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("lat", &ImportNode::lat)
|
||||
.def_readwrite("lon", &ImportNode::lon)
|
||||
.def_readwrite("id", &ImportNode::id)
|
||||
.def_readwrite("bollard", &ImportNode::bollard)
|
||||
.def_readwrite("traffic_light", &ImportNode::trafficLight)
|
||||
.def_readwrite("tags", &ImportNode::keyVals)
|
||||
];
|
||||
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<ExtractionWay>("Way")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("speed", &ExtractionWay::speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.def_readwrite("type", &ExtractionWay::type)
|
||||
.def_readwrite("access", &ExtractionWay::access)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted)
|
||||
.def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid)
|
||||
.def_readwrite("tags", &ExtractionWay::keyVals)
|
||||
.def_readwrite("direction", &ExtractionWay::direction)
|
||||
.enum_("constants")
|
||||
[
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
]
|
||||
];
|
||||
luabind::class_<ExtractionWay>("Way")
|
||||
.def(luabind::constructor<>())
|
||||
.def_readwrite("name", &ExtractionWay::name)
|
||||
.def_readwrite("speed", &ExtractionWay::speed)
|
||||
.def_readwrite("backward_speed", &ExtractionWay::backward_speed)
|
||||
.def_readwrite("duration", &ExtractionWay::duration)
|
||||
.def_readwrite("type", &ExtractionWay::type)
|
||||
.def_readwrite("access", &ExtractionWay::access)
|
||||
.def_readwrite("roundabout", &ExtractionWay::roundabout)
|
||||
.def_readwrite("is_access_restricted", &ExtractionWay::isAccessRestricted)
|
||||
.def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid)
|
||||
.def_readwrite("tags", &ExtractionWay::keyVals)
|
||||
.def_readwrite("direction", &ExtractionWay::direction)
|
||||
.enum_("constants") [
|
||||
luabind::value("notSure", 0),
|
||||
luabind::value("oneway", 1),
|
||||
luabind::value("bidirectional", 2),
|
||||
luabind::value("opposite", 3)
|
||||
]
|
||||
];
|
||||
luabind::module(myLuaState) [
|
||||
luabind::class_<std::vector<std::string> >("vector")
|
||||
.def("Add", &std::vector<std::string>::push_back)
|
||||
];
|
||||
luabind::class_<std::vector<std::string> >("vector")
|
||||
.def("Add", &std::vector<std::string>::push_back)
|
||||
];
|
||||
|
||||
if(0 != luaL_dofile(myLuaState, fileName) ) {
|
||||
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
||||
throw OSRMException("ERROR occured in scripting block");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../Util/LuaUtil.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "../Plugins/ViaRoutePlugin.h"
|
||||
#include "../Plugins/RouteParameters.h"
|
||||
#include "../Util/BaseConfiguration.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/InputFileUtil.h"
|
||||
#include "../Server/BasicDatastructures.h"
|
||||
|
||||
@ -39,19 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
|
||||
class OSRMException: public std::exception {
|
||||
public:
|
||||
OSRMException(const char * message) : message(message) {}
|
||||
private:
|
||||
virtual const char* what() const throw() {
|
||||
return message;
|
||||
}
|
||||
const char * message;
|
||||
};
|
||||
|
||||
class OSRM : boost::noncopyable {
|
||||
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
|
||||
QueryObjectsStorage * objects;
|
||||
|
@ -33,7 +33,9 @@ QueryObjectsStorage::QueryObjectsStorage(
|
||||
) {
|
||||
INFO("loading graph data");
|
||||
std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary);
|
||||
if(!hsgrInStream) { ERR(hsgrPath << " not found"); }
|
||||
if(!hsgrInStream) {
|
||||
throw OSRMException("hsgr not found");
|
||||
}
|
||||
//Deserialize road network graph
|
||||
std::vector< QueryGraph::_StrNode> nodeList;
|
||||
std::vector< QueryGraph::_StrEdge> edgeList;
|
||||
@ -79,7 +81,9 @@ QueryObjectsStorage::QueryObjectsStorage(
|
||||
//deserialize street name list
|
||||
INFO("Loading names index");
|
||||
std::ifstream namesInStream(namesPath.c_str(), std::ios::binary);
|
||||
if(!namesInStream) { ERR(namesPath << " not found"); }
|
||||
if(!namesInStream) {
|
||||
throw OSRMException("names file not found");
|
||||
}
|
||||
unsigned size(0);
|
||||
namesInStream.read((char *)&size, sizeof(unsigned));
|
||||
|
||||
|
@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include<vector>
|
||||
#include<string>
|
||||
|
||||
#include "../../Util/OSRMException.h"
|
||||
#include "../../DataStructures/NodeInformationHelpDesk.h"
|
||||
#include "../../DataStructures/QueryEdge.h"
|
||||
#include "../../DataStructures/StaticGraph.h"
|
||||
|
@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "../Util/BaseConfiguration.h"
|
||||
#include "../Util/InputFileUtil.h"
|
||||
#include "../Util/OpenMPWrapper.h"
|
||||
#include "../Util/OSRMException.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
#include "../typedefs.h"
|
||||
@ -40,31 +41,32 @@ struct ServerFactory {
|
||||
static Server * CreateServer(BaseConfiguration& serverConfig) {
|
||||
|
||||
if(!testDataFile(serverConfig.GetParameter("nodesData"))) {
|
||||
ERR("nodes file not found");
|
||||
throw OSRMException("nodes file not found");
|
||||
}
|
||||
|
||||
if(!testDataFile(serverConfig.GetParameter("hsgrData"))) {
|
||||
ERR("hsgr file not found");
|
||||
throw OSRMException("hsgr file not found");
|
||||
}
|
||||
|
||||
if(!testDataFile(serverConfig.GetParameter("namesData"))) {
|
||||
ERR("names file not found");
|
||||
throw OSRMException("names file not found");
|
||||
}
|
||||
|
||||
if(!testDataFile(serverConfig.GetParameter("ramIndex"))) {
|
||||
ERR("ram index file not found");
|
||||
throw OSRMException("ram index file not found");
|
||||
}
|
||||
|
||||
if(!testDataFile(serverConfig.GetParameter("fileIndex"))) {
|
||||
ERR("file index file not found");
|
||||
throw OSRMException("file index file not found");
|
||||
}
|
||||
|
||||
int threads = omp_get_num_procs();
|
||||
if(serverConfig.GetParameter("IP") == "")
|
||||
if(serverConfig.GetParameter("IP") == "") {
|
||||
serverConfig.SetParameter("IP", "0.0.0.0");
|
||||
if(serverConfig.GetParameter("Port") == "")
|
||||
}
|
||||
if(serverConfig.GetParameter("Port") == "") {
|
||||
serverConfig.SetParameter("Port", "5000");
|
||||
|
||||
}
|
||||
if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads)
|
||||
threads = stringToInt( serverConfig.GetParameter("Threads") );
|
||||
|
||||
|
@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef BASECONFIGURATION_H_
|
||||
#define BASECONFIGURATION_H_
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "../DataStructures/HashTable.h"
|
||||
|
||||
#include <exception>
|
||||
@ -33,26 +34,19 @@ public:
|
||||
BaseConfiguration(const char * configFile) {
|
||||
std::ifstream config( configFile );
|
||||
if(!config) {
|
||||
std::cerr << "[config] .ini not found" << std::endl;
|
||||
return;
|
||||
throw OSRMException("[config] .ini not found");
|
||||
}
|
||||
|
||||
std::string line;
|
||||
try {
|
||||
if (config.is_open()) {
|
||||
while ( config.good() ) {
|
||||
getline (config,line);
|
||||
std::vector<std::string> tokens;
|
||||
Tokenize(line, tokens);
|
||||
if(2 == tokens.size() )
|
||||
parameters.Add(tokens[0], tokens[1]);
|
||||
}
|
||||
config.close();
|
||||
if (config.is_open()) {
|
||||
while ( config.good() ) {
|
||||
getline (config,line);
|
||||
std::vector<std::string> tokens;
|
||||
Tokenize(line, tokens);
|
||||
if(2 == tokens.size() )
|
||||
parameters.Add(tokens[0], tokens[1]);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
ERR("[config] " << configFile << " not found -> Exception: " <<e.what());
|
||||
if(config.is_open())
|
||||
config.close();
|
||||
config.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,18 +87,20 @@ private:
|
||||
|
||||
void TrimStringRight(std::string& str) {
|
||||
std::string::size_type pos = str.find_last_not_of(" ");
|
||||
if (pos != std::string::npos)
|
||||
if (pos != std::string::npos) {
|
||||
str.erase(pos+1);
|
||||
else
|
||||
} else {
|
||||
str.erase( str.begin() , str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
void TrimStringLeft(std::string& str) {
|
||||
std::string::size_type pos = str.find_first_not_of(" ");
|
||||
if (pos != std::string::npos)
|
||||
if (pos != std::string::npos) {
|
||||
str.erase(0, pos);
|
||||
else
|
||||
} else {
|
||||
str.erase( str.begin() , str.end() );
|
||||
}
|
||||
}
|
||||
|
||||
HashTable<std::string, std::string> parameters;
|
||||
|
@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef GRAPHLOADER_H
|
||||
#define GRAPHLOADER_H
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "../DataStructures/ImportNode.h"
|
||||
#include "../DataStructures/ImportEdge.h"
|
||||
#include "../DataStructures/NodeCoords.h"
|
||||
@ -308,19 +309,25 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
|
||||
forward = false;
|
||||
}
|
||||
|
||||
if(length == 0) { ERR("loaded null length edge"); }
|
||||
if(length == 0) {
|
||||
throw OSRMException("loaded null length edge");
|
||||
}
|
||||
|
||||
// translate the external NodeIDs to internal IDs
|
||||
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
||||
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
|
||||
ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source);
|
||||
throw OSRMException("unresolvable source Node ID");
|
||||
}
|
||||
source = intNodeID->second;
|
||||
intNodeID = ext2IntNodeMap.find(target);
|
||||
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); }
|
||||
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) {
|
||||
throw OSRMException("unresolvable target Node ID");
|
||||
}
|
||||
target = intNodeID->second;
|
||||
|
||||
if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); }
|
||||
if(source == UINT_MAX || target == UINT_MAX) {
|
||||
throw OSRMException("nonexisting source or target" );
|
||||
}
|
||||
|
||||
EdgeT inputEdge(source, target, 0, weight, forward, backward, type );
|
||||
edgeList.push_back(inputEdge);
|
||||
@ -351,8 +358,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
|
||||
in >> source >> target >> weight >> dir;
|
||||
|
||||
assert(weight > 0);
|
||||
if(dir <0 || dir > 3)
|
||||
ERR( "[error] direction bogus: " << dir );
|
||||
if(dir <0 || dir > 3) {
|
||||
throw OSRMException( "[error] direction bogus");
|
||||
}
|
||||
assert(0<=dir && dir<=3);
|
||||
|
||||
bool forward = true;
|
||||
@ -361,7 +369,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
|
||||
if (dir == 2) forward = false;
|
||||
if (dir == 3) {backward = true; forward = true;}
|
||||
|
||||
if(weight == 0) { ERR("loaded null length edge"); }
|
||||
if(weight == 0) {
|
||||
throw OSRMException("loaded null length edge");
|
||||
}
|
||||
|
||||
if( nodeMap.find(source) == nodeMap.end()) {
|
||||
nodeMap.insert(std::make_pair(source, numberOfNodes ));
|
||||
@ -395,7 +405,7 @@ unsigned readHSGRFromStream(
|
||||
WARN(
|
||||
".hsgr was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
unsigned number_of_nodes = 0;
|
||||
|
@ -165,12 +165,12 @@ inline bool StringStartsWith(const std::string & input, const std::string & pref
|
||||
|
||||
// Function returns a 'random' filename in temporary directors.
|
||||
// May not be platform independent.
|
||||
inline void GetTemporaryFileName(std::string & filename) {
|
||||
char buffer[L_tmpnam];
|
||||
char * retPointer = tmpnam (buffer);
|
||||
if(0 == retPointer)
|
||||
ERR("Could not create temporary file name");
|
||||
filename = buffer;
|
||||
}
|
||||
// inline void GetTemporaryFileName(std::string & filename) {
|
||||
// char buffer[L_tmpnam];
|
||||
// char * retPointer = tmpnam (buffer);
|
||||
// if(0 == retPointer) {
|
||||
// ERR("Could not create temporary file name");
|
||||
// filename = buffer;
|
||||
// }
|
||||
|
||||
#endif /* STRINGUTIL_H_ */
|
||||
|
@ -61,35 +61,35 @@ const bool UUID::IsMagicNumberOK() const {
|
||||
|
||||
const bool UUID::TestGraphUtil(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("hsgr input file misses magic number. Check or reprocess the file");
|
||||
throw OSRMException("hsgr input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_graph, md5_graph+32, other.md5_graph);
|
||||
}
|
||||
|
||||
const bool UUID::TestPrepare(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("extracted input file misses magic number. Check or reprocess the file");
|
||||
throw OSRMException("extracted input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare);
|
||||
}
|
||||
|
||||
const bool UUID::TestRTree(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("r-tree input file misses magic number. Check or reprocess the file");
|
||||
throw OSRMException("r-tree input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_tree, md5_tree+32, other.md5_tree);
|
||||
}
|
||||
|
||||
const bool UUID::TestNodeInfo(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("nodes file misses magic number. Check or reprocess the file");
|
||||
throw OSRMException("nodes file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo);
|
||||
}
|
||||
|
||||
const bool UUID::TestQueryObjects(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("missing magic number. Check or reprocess the file");
|
||||
throw OSRMException("missing magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_objects, md5_objects+32, other.md5_objects);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef UUID_H
|
||||
#define UUID_H
|
||||
|
||||
#include "OSRMException.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "Util/InputFileUtil.h"
|
||||
#include "Util/LuaUtil.h"
|
||||
#include "Util/OpenMPWrapper.h"
|
||||
#include "Util/OSRMException.h"
|
||||
#include "Util/StringUtil.h"
|
||||
#include "typedefs.h"
|
||||
|
||||
@ -59,7 +60,10 @@ std::vector<ImportEdge> edgeList;
|
||||
int main (int argc, char *argv[]) {
|
||||
try {
|
||||
if(argc < 3) {
|
||||
ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions> [<profile>]");
|
||||
std::cerr <<
|
||||
"usage: \n" <<
|
||||
argv[0] << " <osrm-data> <osrm-restrictions> [<profile>]" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
double startupTime = get_timestamp();
|
||||
@ -75,7 +79,9 @@ int main (int argc, char *argv[]) {
|
||||
INFO("Using restrictions from file: " << argv[2]);
|
||||
std::ifstream restrictionsInstream(argv[2], std::ios::binary);
|
||||
if(!restrictionsInstream.good()) {
|
||||
ERR("Could not access <osrm-restrictions> files");
|
||||
std::cerr <<
|
||||
"Could not access <osrm-restrictions> files" << std::endl;
|
||||
|
||||
}
|
||||
_Restriction restriction;
|
||||
UUID uuid_loaded, uuid_orig;
|
||||
@ -85,7 +91,7 @@ int main (int argc, char *argv[]) {
|
||||
WARN(
|
||||
".restrictions was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
|
||||
@ -96,7 +102,7 @@ int main (int argc, char *argv[]) {
|
||||
std::ifstream in;
|
||||
in.open (argv[1], std::ifstream::in | std::ifstream::binary);
|
||||
if (!in.is_open()) {
|
||||
ERR("Cannot open " << argv[1]);
|
||||
throw OSRMException("Cannot open osrm input file");
|
||||
}
|
||||
|
||||
std::string nodeOut(argv[1]); nodeOut += ".nodes";
|
||||
@ -107,7 +113,7 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
/*** Setup Scripting Environment ***/
|
||||
if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) {
|
||||
ERR("Need profile.lua to apply traffic signal penalty");
|
||||
throw OSRMException("Cannot open profile.lua ");
|
||||
}
|
||||
|
||||
// Create a new lua state
|
||||
@ -125,18 +131,29 @@ int main (int argc, char *argv[]) {
|
||||
// Now call our function in a lua script
|
||||
INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") );
|
||||
if(0 != luaL_dofile(myLuaState, (argc > 3 ? argv[3] : "profile.lua") )) {
|
||||
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
||||
std::cerr <<
|
||||
lua_tostring(myLuaState,-1) <<
|
||||
" occured in scripting block" <<
|
||||
std::endl;
|
||||
}
|
||||
|
||||
EdgeBasedGraphFactory::SpeedProfileProperties speedProfile;
|
||||
|
||||
if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) {
|
||||
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
||||
std::cerr <<
|
||||
lua_tostring(myLuaState,-1) <<
|
||||
" occured in scripting block" <<
|
||||
std::endl;
|
||||
return -1;
|
||||
}
|
||||
speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1);
|
||||
|
||||
if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) {
|
||||
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block");
|
||||
std::cerr <<
|
||||
lua_tostring(myLuaState,-1) <<
|
||||
" occured in scripting block" <<
|
||||
std::endl;
|
||||
return -1;
|
||||
}
|
||||
speedProfile.uTurnPenalty = 10*lua_tointeger(myLuaState, -1);
|
||||
|
||||
@ -146,9 +163,13 @@ int main (int argc, char *argv[]) {
|
||||
NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
|
||||
in.close();
|
||||
INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights");
|
||||
if(0 == edgeList.size())
|
||||
ERR("The input data is broken. It is impossible to do any turns in this graph");
|
||||
|
||||
if(0 == edgeList.size()) {
|
||||
std::cerr <<
|
||||
"The input data is broken. "
|
||||
"It is impossible to do any turns in this graph" <<
|
||||
std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/***
|
||||
* Building an edge-expanded graph from node-based input an turn restrictions
|
||||
@ -262,7 +283,13 @@ int main (int argc, char *argv[]) {
|
||||
currentEdge.data = contractedEdgeList[edge].data;
|
||||
if(currentEdge.data.distance <= 0) {
|
||||
INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance);
|
||||
ERR("Failed at edges of node " << node << " of " << numberOfNodes);
|
||||
std::cerr <<
|
||||
"Failed at edges of node " <<
|
||||
node <<
|
||||
" of " <<
|
||||
numberOfNodes <<
|
||||
std::endl;
|
||||
return -1;
|
||||
}
|
||||
//Serialize edges
|
||||
hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph<EdgeData>::_StrEdge));
|
||||
@ -278,8 +305,9 @@ int main (int argc, char *argv[]) {
|
||||
//cleanedEdgeList.clear();
|
||||
_nodes.clear();
|
||||
INFO("finished preprocessing");
|
||||
} catch (std::exception &e) {
|
||||
ERR("Exception occured: " << e.what());
|
||||
} catch ( const std::exception &e ) {
|
||||
std::cerr << "Exception occured: " << e.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "Util/InputFileUtil.h"
|
||||
#include "Util/MachineInfo.h"
|
||||
#include "Util/OpenMPWrapper.h"
|
||||
#include "Util/OSRMException.h"
|
||||
#include "Util/StringUtil.h"
|
||||
#include "Util/UUID.h"
|
||||
#include "typedefs.h"
|
||||
@ -45,7 +46,12 @@ int main (int argc, char *argv[]) {
|
||||
double startup_time = get_timestamp();
|
||||
|
||||
if(argc < 2) {
|
||||
ERR("usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]");
|
||||
std::cerr <<
|
||||
"usage: \n" <<
|
||||
argv[0] <<
|
||||
" <file.osm/.osm.bz2/.osm.pbf> [<profile.lua>]" <<
|
||||
std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*** Setup Scripting Environment ***/
|
||||
@ -111,7 +117,7 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if(!parser->ReadHeader()) {
|
||||
ERR("Parser not initialized!");
|
||||
throw OSRMException("Parser not initialized!");
|
||||
}
|
||||
INFO("Parsing in progress..");
|
||||
double parsing_start_time = get_timestamp();
|
||||
@ -128,11 +134,16 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
INFO("extraction finished after " << get_timestamp() - startup_time << "s");
|
||||
|
||||
std::cout << "\nRun:\n"
|
||||
<< "./osrm-prepare " << output_file_name << " " << restrictionsFileName
|
||||
<< std::endl;
|
||||
return 0;
|
||||
std::cout <<
|
||||
"\nRun:\n" <<
|
||||
"./osrm-prepare " <<
|
||||
output_file_name <<
|
||||
" " <<
|
||||
restrictionsFileName <<
|
||||
std::endl;
|
||||
} catch(std::exception & e) {
|
||||
WARN("unhandled exception: " << e.what());
|
||||
INFO("unhandled exception: " << e.what());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user