use exceptions instead of hard abort

This commit is contained in:
Dennis Luxen 2013-08-05 17:28:57 +02:00
parent ec7d3a9885
commit 54302a53e1
23 changed files with 248 additions and 193 deletions

View File

@ -434,8 +434,9 @@ public:
p.printStatus(numberOfContractedNodes); p.printStatus(numberOfContractedNodes);
} }
BOOST_FOREACH(_ThreadData * data, threadData) BOOST_FOREACH(_ThreadData * data, threadData) {
delete data; delete data;
}
threadData.clear(); threadData.clear();
} }

View File

@ -21,11 +21,7 @@
#include "TemporaryStorage.h" #include "TemporaryStorage.h"
TemporaryStorage::TemporaryStorage() { TemporaryStorage::TemporaryStorage() {
try {
tempDirectory = boost::filesystem::temp_directory_path(); tempDirectory = boost::filesystem::temp_directory_path();
} catch(boost::filesystem::filesystem_error & e) {
ERR("could not retrieve location of temporary path: " << e.what());
}
} }
TemporaryStorage & TemporaryStorage::GetInstance(){ TemporaryStorage & TemporaryStorage::GetInstance(){
@ -39,12 +35,8 @@ TemporaryStorage::~TemporaryStorage() {
void TemporaryStorage::removeAll() { void TemporaryStorage::removeAll() {
boost::mutex::scoped_lock lock(mutex); boost::mutex::scoped_lock lock(mutex);
try { for(unsigned slot_id = 0; slot_id < vectorOfStreamDatas.size(); ++slot_id) {
for(unsigned slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID) deallocateSlot(slot_id);
deallocateSlot(slotID);
} catch(boost::filesystem::filesystem_error & e) {
ERR("could not retrieve location of temporary path: " << e.what());
} }
vectorOfStreamDatas.clear(); vectorOfStreamDatas.clear();
} }
@ -67,10 +59,10 @@ void TemporaryStorage::deallocateSlot(int slotID) {
if(!boost::filesystem::exists(data.pathToTemporaryFile)) { if(!boost::filesystem::exists(data.pathToTemporaryFile)) {
return; return;
} }
if(data.streamToTemporaryFile->is_open()) if(data.streamToTemporaryFile->is_open()) {
data.streamToTemporaryFile->close(); data.streamToTemporaryFile->close();
}
//INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile);
boost::filesystem::remove(data.pathToTemporaryFile); boost::filesystem::remove(data.pathToTemporaryFile);
} catch(boost::filesystem::filesystem_error & e) { } catch(boost::filesystem::filesystem_error & e) {
abort(e); abort(e);
@ -81,8 +73,10 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s
try { try {
StreamData & data = vectorOfStreamDatas[slotID]; StreamData & data = vectorOfStreamDatas[slotID];
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
if(!data.writeMode) BOOST_ASSERT_MSG(
ERR("Writing after first read is not allowed"); data.writeMode,
"Writing after first read is not allowed"
);
data.streamToTemporaryFile->write(pointer, size); data.streamToTemporaryFile->write(pointer, size);
} catch(boost::filesystem::filesystem_error & e) { } catch(boost::filesystem::filesystem_error & e) {
abort(e); abort(e);
@ -121,13 +115,11 @@ boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) {
} catch(boost::filesystem::filesystem_error & e) { } catch(boost::filesystem::filesystem_error & e) {
abort(e); abort(e);
} }
// INFO("telling position: " << position);
return position; return position;
} }
void TemporaryStorage::abort(boost::filesystem::filesystem_error& ) { void TemporaryStorage::abort(boost::filesystem::filesystem_error& ) {
removeAll(); removeAll();
// ERR("I/O Error occured: " << e.what());
} }
void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) { 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]; StreamData & data = vectorOfStreamDatas[slotID];
boost::mutex::scoped_lock lock(*data.readWriteMutex); boost::mutex::scoped_lock lock(*data.readWriteMutex);
data.streamToTemporaryFile->seekg(position); data.streamToTemporaryFile->seekg(position);
// INFO("seeking to position: " << position);
} catch(boost::filesystem::filesystem_error & e) { } catch(boost::filesystem::filesystem_error & e) {
abort(e); abort(e);
} }

View File

@ -24,12 +24,14 @@
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <boost/assert.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include "../Util/OSRMException.h"
#include "../typedefs.h" #include "../typedefs.h"
//This is one big workaround for latest boost renaming woes. //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)), streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
readWriteMutex(new boost::mutex) readWriteMutex(new boost::mutex)
{ {
if(streamToTemporaryFile->fail()) if(streamToTemporaryFile->fail()) {
ERR("Aborting, because temporary file at " << pathToTemporaryFile << " could not be created"); throw OSRMException("temporary file could not be created");
}
} }
}; };
//vector of file streams that is used to store temporary data //vector of file streams that is used to store temporary data

View File

@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef EDGE_H #ifndef EDGE_H
#define EDGE_H #define EDGE_H
#include "../Util/OSRMException.h"
#include <cassert> #include <cassert>
class NodeBasedEdge { class NodeBasedEdge {
@ -40,8 +42,34 @@ public:
return (source() < e.source()); 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) : explicit NodeBasedEdge(
_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);}; } 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 target() const {return _target; }
NodeID source() const {return _source; } NodeID source() const {return _source; }

View File

@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "PhantomNodes.h" #include "PhantomNodes.h"
#include "StaticRTree.h" #include "StaticRTree.h"
#include "../Contractor/EdgeBasedGraphFactory.h" #include "../Contractor/EdgeBasedGraphFactory.h"
#include "../Util/OSRMException.h"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -127,9 +128,13 @@ private:
const std::string & edges_file const std::string & edges_file
) { ) {
std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary); std::ifstream nodes_input_stream(nodes_file.c_str(), std::ios::binary);
if(!nodes_input_stream) { ERR(nodes_file << " not found"); } if(!nodes_input_stream) {
throw OSRMException("nodes file not found");
}
std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary); std::ifstream edges_input_stream(edges_file.c_str(), std::ios::binary);
if(!edges_input_stream) { ERR(edges_file << " not found"); } if(!edges_input_stream) {
throw OSRMException("edges file not found");
}
DEBUG("Loading node data"); DEBUG("Loading node data");
NodeInfo b; NodeInfo b;

View File

@ -29,7 +29,9 @@ extractor_callbacks(ec), scriptingEnvironment(se), luaState(NULL), use_turn_rest
void BaseParser::ReadUseRestrictionsSetting() { void BaseParser::ReadUseRestrictionsSetting() {
if( 0 != luaL_dostring( luaState, "return use_turn_restrictions\n") ) { 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) ) { if( lua_isboolean( luaState, -1) ) {
use_turn_restrictions = lua_toboolean(luaState, -1); use_turn_restrictions = lua_toboolean(luaState, -1);
@ -44,21 +46,15 @@ void BaseParser::ReadUseRestrictionsSetting() {
void BaseParser::ReadRestrictionExceptions() { void BaseParser::ReadRestrictionExceptions() {
if(lua_function_exists(luaState, "get_exceptions" )) { if(lua_function_exists(luaState, "get_exceptions" )) {
//get list of turn restriction exceptions //get list of turn restriction exceptions
try {
luabind::call_function<void>( luabind::call_function<void>(
luaState, luaState,
"get_exceptions", "get_exceptions",
boost::ref(restriction_exceptions) boost::ref(restriction_exceptions)
); );
INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction"); INFO("Found " << restriction_exceptions.size() << " exceptions to turn restriction");
BOOST_FOREACH(std::string & str, restriction_exceptions) { BOOST_FOREACH(const std::string & str, restriction_exceptions) {
INFO(" " << str); INFO(" " << str);
} }
} catch (const luabind::error &er) {
lua_State* Ler=er.state();
report_errors(Ler, -1);
ERR(er.what());
}
} else { } else {
INFO("Found no exceptions to turn restrictions"); INFO("Found no exceptions to turn restrictions");
} }
@ -72,26 +68,14 @@ void BaseParser::report_errors(lua_State *L, const int status) const {
} }
void BaseParser::ParseNodeInLua(ImportNode& n, lua_State* localLuaState) { void BaseParser::ParseNodeInLua(ImportNode& n, lua_State* localLuaState) {
try {
luabind::call_function<void>( localLuaState, "node_function", boost::ref(n) ); 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());
}
} }
void BaseParser::ParseWayInLua(ExtractionWay& w, lua_State* localLuaState) { void BaseParser::ParseWayInLua(ExtractionWay& w, lua_State* localLuaState) {
if(2 > w.path.size()) { if(2 > w.path.size()) {
return; return;
} }
try {
luabind::call_function<void>( localLuaState, "way_function", boost::ref(w) ); 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());
}
} }
bool BaseParser::ShouldIgnoreRestriction(const std::string& except_tag_string) const { bool BaseParser::ShouldIgnoreRestriction(const std::string& except_tag_string) const {

View File

@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "ExtractorCallbacks.h" #include "ExtractorCallbacks.h"
#include "ScriptingEnvironment.h" #include "ScriptingEnvironment.h"
#include "../Util/OSRMException.h"
extern "C" { extern "C" {
#include <lua.h> #include <lua.h>

View File

@ -39,14 +39,10 @@ public:
ExtractionContainers() { ExtractionContainers() {
//Check if another instance of stxxl is already running or if there is a general problem //Check if another instance of stxxl is already running or if there is a general problem
try {
stxxl::vector<unsigned> testForRunningInstance; stxxl::vector<unsigned> testForRunningInstance;
} catch(std::exception & e) {
ERR("Could not instantiate STXXL layer." << std::endl << e.what());
}
nameVector.push_back(""); nameVector.push_back("");
} }
virtual ~ExtractionContainers() { virtual ~ExtractionContainers() {
usedNodeIDs.clear(); usedNodeIDs.clear();
allNodes.clear(); allNodes.clear();

View File

@ -28,7 +28,7 @@ PBFParser::PBFParser(const char * fileName, ExtractorCallbacks* ec, ScriptingEnv
input.open(fileName, std::ios::in | std::ios::binary); input.open(fileName, std::ios::in | std::ios::binary);
if (!input) { if (!input) {
std::cerr << fileName << ": File not found." << std::endl; throw OSRMException("pbf file not found.");
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -194,7 +194,9 @@ inline void PBFParser::parseDenseNode(_ThreadData * threadData) {
} }
inline void PBFParser::parseNode(_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) { 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() ) ) { 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 false;
} }
return true; return true;

View File

@ -27,6 +27,7 @@
#include "../DataStructures/ConcurrentQueue.h" #include "../DataStructures/ConcurrentQueue.h"
#include "../Util/MachineInfo.h" #include "../Util/MachineInfo.h"
#include "../Util/OpenMPWrapper.h" #include "../Util/OpenMPWrapper.h"
#include "../Util/OSRMException.h"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>

View File

@ -78,8 +78,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
.def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid) .def_readwrite("ignore_in_grid", &ExtractionWay::ignoreInGrid)
.def_readwrite("tags", &ExtractionWay::keyVals) .def_readwrite("tags", &ExtractionWay::keyVals)
.def_readwrite("direction", &ExtractionWay::direction) .def_readwrite("direction", &ExtractionWay::direction)
.enum_("constants") .enum_("constants") [
[
luabind::value("notSure", 0), luabind::value("notSure", 0),
luabind::value("oneway", 1), luabind::value("oneway", 1),
luabind::value("bidirectional", 2), luabind::value("bidirectional", 2),
@ -92,7 +91,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
]; ];
if(0 != luaL_dofile(myLuaState, fileName) ) { if(0 != luaL_dofile(myLuaState, fileName) ) {
ERR(lua_tostring(myLuaState,-1)<< " occured in scripting block"); throw OSRMException("ERROR occured in scripting block");
} }
} }
} }

View File

@ -26,6 +26,7 @@
#include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportNode.h"
#include "../Util/LuaUtil.h" #include "../Util/LuaUtil.h"
#include "../Util/OpenMPWrapper.h" #include "../Util/OpenMPWrapper.h"
#include "../Util/OSRMException.h"
#include "../typedefs.h" #include "../typedefs.h"
#include <vector> #include <vector>

View File

@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Plugins/ViaRoutePlugin.h" #include "../Plugins/ViaRoutePlugin.h"
#include "../Plugins/RouteParameters.h" #include "../Plugins/RouteParameters.h"
#include "../Util/BaseConfiguration.h" #include "../Util/BaseConfiguration.h"
#include "../Util/OSRMException.h"
#include "../Util/InputFileUtil.h" #include "../Util/InputFileUtil.h"
#include "../Server/BasicDatastructures.h" #include "../Server/BasicDatastructures.h"
@ -39,19 +40,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <exception>
#include <vector> #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 { class OSRM : boost::noncopyable {
typedef boost::unordered_map<std::string, BasePlugin *> PluginMap; typedef boost::unordered_map<std::string, BasePlugin *> PluginMap;
QueryObjectsStorage * objects; QueryObjectsStorage * objects;

View File

@ -33,7 +33,9 @@ QueryObjectsStorage::QueryObjectsStorage(
) { ) {
INFO("loading graph data"); INFO("loading graph data");
std::ifstream hsgrInStream(hsgrPath.c_str(), std::ios::binary); 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 //Deserialize road network graph
std::vector< QueryGraph::_StrNode> nodeList; std::vector< QueryGraph::_StrNode> nodeList;
std::vector< QueryGraph::_StrEdge> edgeList; std::vector< QueryGraph::_StrEdge> edgeList;
@ -79,7 +81,9 @@ QueryObjectsStorage::QueryObjectsStorage(
//deserialize street name list //deserialize street name list
INFO("Loading names index"); INFO("Loading names index");
std::ifstream namesInStream(namesPath.c_str(), std::ios::binary); 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); unsigned size(0);
namesInStream.read((char *)&size, sizeof(unsigned)); namesInStream.read((char *)&size, sizeof(unsigned));

View File

@ -25,6 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include<vector> #include<vector>
#include<string> #include<string>
#include "../../Util/OSRMException.h"
#include "../../DataStructures/NodeInformationHelpDesk.h" #include "../../DataStructures/NodeInformationHelpDesk.h"
#include "../../DataStructures/QueryEdge.h" #include "../../DataStructures/QueryEdge.h"
#include "../../DataStructures/StaticGraph.h" #include "../../DataStructures/StaticGraph.h"

View File

@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Util/BaseConfiguration.h" #include "../Util/BaseConfiguration.h"
#include "../Util/InputFileUtil.h" #include "../Util/InputFileUtil.h"
#include "../Util/OpenMPWrapper.h" #include "../Util/OpenMPWrapper.h"
#include "../Util/OSRMException.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
#include "../typedefs.h" #include "../typedefs.h"
@ -40,31 +41,32 @@ struct ServerFactory {
static Server * CreateServer(BaseConfiguration& serverConfig) { static Server * CreateServer(BaseConfiguration& serverConfig) {
if(!testDataFile(serverConfig.GetParameter("nodesData"))) { if(!testDataFile(serverConfig.GetParameter("nodesData"))) {
ERR("nodes file not found"); throw OSRMException("nodes file not found");
} }
if(!testDataFile(serverConfig.GetParameter("hsgrData"))) { if(!testDataFile(serverConfig.GetParameter("hsgrData"))) {
ERR("hsgr file not found"); throw OSRMException("hsgr file not found");
} }
if(!testDataFile(serverConfig.GetParameter("namesData"))) { if(!testDataFile(serverConfig.GetParameter("namesData"))) {
ERR("names file not found"); throw OSRMException("names file not found");
} }
if(!testDataFile(serverConfig.GetParameter("ramIndex"))) { if(!testDataFile(serverConfig.GetParameter("ramIndex"))) {
ERR("ram index file not found"); throw OSRMException("ram index file not found");
} }
if(!testDataFile(serverConfig.GetParameter("fileIndex"))) { if(!testDataFile(serverConfig.GetParameter("fileIndex"))) {
ERR("file index file not found"); throw OSRMException("file index file not found");
} }
int threads = omp_get_num_procs(); int threads = omp_get_num_procs();
if(serverConfig.GetParameter("IP") == "") if(serverConfig.GetParameter("IP") == "") {
serverConfig.SetParameter("IP", "0.0.0.0"); serverConfig.SetParameter("IP", "0.0.0.0");
if(serverConfig.GetParameter("Port") == "") }
if(serverConfig.GetParameter("Port") == "") {
serverConfig.SetParameter("Port", "5000"); serverConfig.SetParameter("Port", "5000");
}
if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads) if(stringToInt(serverConfig.GetParameter("Threads")) != 0 && stringToInt(serverConfig.GetParameter("Threads")) <= threads)
threads = stringToInt( serverConfig.GetParameter("Threads") ); threads = stringToInt( serverConfig.GetParameter("Threads") );

View File

@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef BASECONFIGURATION_H_ #ifndef BASECONFIGURATION_H_
#define BASECONFIGURATION_H_ #define BASECONFIGURATION_H_
#include "OSRMException.h"
#include "../DataStructures/HashTable.h" #include "../DataStructures/HashTable.h"
#include <exception> #include <exception>
@ -33,12 +34,10 @@ public:
BaseConfiguration(const char * configFile) { BaseConfiguration(const char * configFile) {
std::ifstream config( configFile ); std::ifstream config( configFile );
if(!config) { if(!config) {
std::cerr << "[config] .ini not found" << std::endl; throw OSRMException("[config] .ini not found");
return;
} }
std::string line; std::string line;
try {
if (config.is_open()) { if (config.is_open()) {
while ( config.good() ) { while ( config.good() ) {
getline (config,line); getline (config,line);
@ -49,11 +48,6 @@ public:
} }
config.close(); config.close();
} }
} catch(std::exception& e) {
ERR("[config] " << configFile << " not found -> Exception: " <<e.what());
if(config.is_open())
config.close();
}
} }
std::string GetParameter(const char * key){ std::string GetParameter(const char * key){
@ -93,19 +87,21 @@ private:
void TrimStringRight(std::string& str) { void TrimStringRight(std::string& str) {
std::string::size_type pos = str.find_last_not_of(" "); std::string::size_type pos = str.find_last_not_of(" ");
if (pos != std::string::npos) if (pos != std::string::npos) {
str.erase(pos+1); str.erase(pos+1);
else } else {
str.erase( str.begin() , str.end() ); str.erase( str.begin() , str.end() );
} }
}
void TrimStringLeft(std::string& str) { void TrimStringLeft(std::string& str) {
std::string::size_type pos = str.find_first_not_of(" "); std::string::size_type pos = str.find_first_not_of(" ");
if (pos != std::string::npos) if (pos != std::string::npos) {
str.erase(0, pos); str.erase(0, pos);
else } else {
str.erase( str.begin() , str.end() ); str.erase( str.begin() , str.end() );
} }
}
HashTable<std::string, std::string> parameters; HashTable<std::string, std::string> parameters;
}; };

View File

@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef GRAPHLOADER_H #ifndef GRAPHLOADER_H
#define GRAPHLOADER_H #define GRAPHLOADER_H
#include "OSRMException.h"
#include "../DataStructures/ImportNode.h" #include "../DataStructures/ImportNode.h"
#include "../DataStructures/ImportEdge.h" #include "../DataStructures/ImportEdge.h"
#include "../DataStructures/NodeCoords.h" #include "../DataStructures/NodeCoords.h"
@ -308,19 +309,25 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
forward = false; 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 // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { 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; source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target); 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; 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 ); EdgeT inputEdge(source, target, 0, weight, forward, backward, type );
edgeList.push_back(inputEdge); edgeList.push_back(inputEdge);
@ -351,8 +358,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
in >> source >> target >> weight >> dir; in >> source >> target >> weight >> dir;
assert(weight > 0); assert(weight > 0);
if(dir <0 || dir > 3) if(dir <0 || dir > 3) {
ERR( "[error] direction bogus: " << dir ); throw OSRMException( "[error] direction bogus");
}
assert(0<=dir && dir<=3); assert(0<=dir && dir<=3);
bool forward = true; bool forward = true;
@ -361,7 +369,9 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
if (dir == 2) forward = false; if (dir == 2) forward = false;
if (dir == 3) {backward = true; forward = true;} 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()) { if( nodeMap.find(source) == nodeMap.end()) {
nodeMap.insert(std::make_pair(source, numberOfNodes )); nodeMap.insert(std::make_pair(source, numberOfNodes ));
@ -395,7 +405,7 @@ unsigned readHSGRFromStream(
WARN( WARN(
".hsgr was prepared with different build.\n" ".hsgr was prepared with different build.\n"
"Reprocess to get rid of this warning." "Reprocess to get rid of this warning."
) );
} }
unsigned number_of_nodes = 0; unsigned number_of_nodes = 0;

View File

@ -165,12 +165,12 @@ inline bool StringStartsWith(const std::string & input, const std::string & pref
// Function returns a 'random' filename in temporary directors. // Function returns a 'random' filename in temporary directors.
// May not be platform independent. // May not be platform independent.
inline void GetTemporaryFileName(std::string & filename) { // inline void GetTemporaryFileName(std::string & filename) {
char buffer[L_tmpnam]; // char buffer[L_tmpnam];
char * retPointer = tmpnam (buffer); // char * retPointer = tmpnam (buffer);
if(0 == retPointer) // if(0 == retPointer) {
ERR("Could not create temporary file name"); // ERR("Could not create temporary file name");
filename = buffer; // filename = buffer;
} // }
#endif /* STRINGUTIL_H_ */ #endif /* STRINGUTIL_H_ */

View File

@ -61,35 +61,35 @@ const bool UUID::IsMagicNumberOK() const {
const bool UUID::TestGraphUtil(const UUID & other) const { const bool UUID::TestGraphUtil(const UUID & other) const {
if(!other.IsMagicNumberOK()) { 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); return std::equal(md5_graph, md5_graph+32, other.md5_graph);
} }
const bool UUID::TestPrepare(const UUID & other) const { const bool UUID::TestPrepare(const UUID & other) const {
if(!other.IsMagicNumberOK()) { 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); return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare);
} }
const bool UUID::TestRTree(const UUID & other) const { const bool UUID::TestRTree(const UUID & other) const {
if(!other.IsMagicNumberOK()) { 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); return std::equal(md5_tree, md5_tree+32, other.md5_tree);
} }
const bool UUID::TestNodeInfo(const UUID & other) const { const bool UUID::TestNodeInfo(const UUID & other) const {
if(!other.IsMagicNumberOK()) { 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); return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo);
} }
const bool UUID::TestQueryObjects(const UUID & other) const { const bool UUID::TestQueryObjects(const UUID & other) const {
if(!other.IsMagicNumberOK()) { 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); return std::equal(md5_objects, md5_objects+32, other.md5_objects);
} }

View File

@ -21,6 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef UUID_H #ifndef UUID_H
#define UUID_H #define UUID_H
#include "OSRMException.h"
#include "../typedefs.h" #include "../typedefs.h"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>

View File

@ -31,6 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Util/InputFileUtil.h" #include "Util/InputFileUtil.h"
#include "Util/LuaUtil.h" #include "Util/LuaUtil.h"
#include "Util/OpenMPWrapper.h" #include "Util/OpenMPWrapper.h"
#include "Util/OSRMException.h"
#include "Util/StringUtil.h" #include "Util/StringUtil.h"
#include "typedefs.h" #include "typedefs.h"
@ -59,7 +60,10 @@ std::vector<ImportEdge> edgeList;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
try { try {
if(argc < 3) { 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(); double startupTime = get_timestamp();
@ -75,7 +79,9 @@ int main (int argc, char *argv[]) {
INFO("Using restrictions from file: " << argv[2]); INFO("Using restrictions from file: " << argv[2]);
std::ifstream restrictionsInstream(argv[2], std::ios::binary); std::ifstream restrictionsInstream(argv[2], std::ios::binary);
if(!restrictionsInstream.good()) { if(!restrictionsInstream.good()) {
ERR("Could not access <osrm-restrictions> files"); std::cerr <<
"Could not access <osrm-restrictions> files" << std::endl;
} }
_Restriction restriction; _Restriction restriction;
UUID uuid_loaded, uuid_orig; UUID uuid_loaded, uuid_orig;
@ -85,7 +91,7 @@ int main (int argc, char *argv[]) {
WARN( WARN(
".restrictions was prepared with different build.\n" ".restrictions was prepared with different build.\n"
"Reprocess to get rid of this warning." "Reprocess to get rid of this warning."
) );
} }
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
@ -96,7 +102,7 @@ int main (int argc, char *argv[]) {
std::ifstream in; std::ifstream in;
in.open (argv[1], std::ifstream::in | std::ifstream::binary); in.open (argv[1], std::ifstream::in | std::ifstream::binary);
if (!in.is_open()) { if (!in.is_open()) {
ERR("Cannot open " << argv[1]); throw OSRMException("Cannot open osrm input file");
} }
std::string nodeOut(argv[1]); nodeOut += ".nodes"; std::string nodeOut(argv[1]); nodeOut += ".nodes";
@ -107,7 +113,7 @@ int main (int argc, char *argv[]) {
/*** Setup Scripting Environment ***/ /*** Setup Scripting Environment ***/
if(!testDataFile( (argc > 3 ? argv[3] : "profile.lua") )) { 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 // Create a new lua state
@ -125,18 +131,29 @@ int main (int argc, char *argv[]) {
// Now call our function in a lua script // Now call our function in a lua script
INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") ); INFO("Parsing speedprofile from " << (argc > 3 ? argv[3] : "profile.lua") );
if(0 != luaL_dofile(myLuaState, (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; EdgeBasedGraphFactory::SpeedProfileProperties speedProfile;
if(0 != luaL_dostring( myLuaState, "return traffic_signal_penalty\n")) { 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); speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1);
if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { 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); 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); NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions);
in.close(); in.close();
INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); INFO(inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights");
if(0 == edgeList.size()) if(0 == edgeList.size()) {
ERR("The input data is broken. It is impossible to do any turns in this graph"); 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 * 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; currentEdge.data = contractedEdgeList[edge].data;
if(currentEdge.data.distance <= 0) { if(currentEdge.data.distance <= 0) {
INFO("Edge: " << i << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance); 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 //Serialize edges
hsgr_output_stream.write((char*) &currentEdge, sizeof(StaticGraph<EdgeData>::_StrEdge)); hsgr_output_stream.write((char*) &currentEdge, sizeof(StaticGraph<EdgeData>::_StrEdge));
@ -278,8 +305,9 @@ int main (int argc, char *argv[]) {
//cleanedEdgeList.clear(); //cleanedEdgeList.clear();
_nodes.clear(); _nodes.clear();
INFO("finished preprocessing"); INFO("finished preprocessing");
} catch (std::exception &e) { } catch ( const std::exception &e ) {
ERR("Exception occured: " << e.what()); std::cerr << "Exception occured: " << e.what() << std::endl;
return -1;
} }
return 0; return 0;
} }

View File

@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Util/InputFileUtil.h" #include "Util/InputFileUtil.h"
#include "Util/MachineInfo.h" #include "Util/MachineInfo.h"
#include "Util/OpenMPWrapper.h" #include "Util/OpenMPWrapper.h"
#include "Util/OSRMException.h"
#include "Util/StringUtil.h" #include "Util/StringUtil.h"
#include "Util/UUID.h" #include "Util/UUID.h"
#include "typedefs.h" #include "typedefs.h"
@ -45,7 +46,12 @@ int main (int argc, char *argv[]) {
double startup_time = get_timestamp(); double startup_time = get_timestamp();
if(argc < 2) { 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 ***/ /*** Setup Scripting Environment ***/
@ -111,7 +117,7 @@ int main (int argc, char *argv[]) {
} }
if(!parser->ReadHeader()) { if(!parser->ReadHeader()) {
ERR("Parser not initialized!"); throw OSRMException("Parser not initialized!");
} }
INFO("Parsing in progress.."); INFO("Parsing in progress..");
double parsing_start_time = get_timestamp(); 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"); INFO("extraction finished after " << get_timestamp() - startup_time << "s");
std::cout << "\nRun:\n" std::cout <<
<< "./osrm-prepare " << output_file_name << " " << restrictionsFileName "\nRun:\n" <<
<< std::endl; "./osrm-prepare " <<
return 0; output_file_name <<
" " <<
restrictionsFileName <<
std::endl;
} catch(std::exception & e) { } catch(std::exception & e) {
WARN("unhandled exception: " << e.what()); INFO("unhandled exception: " << e.what());
return -1;
} }
return 0;
} }