use program options in data store tool

This commit is contained in:
Dennis Luxen 2013-10-15 18:24:49 +02:00
parent 1197b96c49
commit 852c648235

View File

@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "Server/DataStructures/BaseDataFacade.h" #include "Server/DataStructures/BaseDataFacade.h"
#include "Server/DataStructures/SharedDataType.h" #include "Server/DataStructures/SharedDataType.h"
#include "Util/BoostFileSystemFix.h" #include "Util/BoostFileSystemFix.h"
#include "Util/IniFile.h" #include "Util/ProgramOptions.h"
#include "Util/SimpleLogger.h" #include "Util/SimpleLogger.h"
#include "Util/UUID.h" #include "Util/UUID.h"
#include "typedefs.h" #include "typedefs.h"
@ -37,80 +37,69 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <string> #include <string>
#include <vector> #include <vector>
int main(int argc, char * argv[]) { int main( const int argc, const char * argv[] ) {
try { try {
LogPolicy::GetInstance().Unmute(); LogPolicy::GetInstance().Unmute();
SimpleLogger().Write() << "Checking input parameters"; SimpleLogger().Write() << "Checking input parameters";
boost::filesystem::path base_path = boost::filesystem::absolute( bool use_shared_memory = false;
(argc > 1 ? argv[1] : "server.ini") std::string ip_address;
).parent_path(); int ip_port, requested_num_threads;
IniFile server_config((argc > 1 ? argv[1] : "server.ini"));
//check contents of config file ServerPaths server_paths;
if ( !server_config.Holds("hsgrData")) { if( !GenerateServerProgramOptions(
throw OSRMException("no ram index file name in server ini"); argc,
argv,
server_paths,
ip_address,
ip_port,
requested_num_threads,
use_shared_memory
)
) {
return 0;
} }
if ( !server_config.Holds("ramIndex") ) { if( server_paths.find("hsgrdata") == server_paths.end() ) {
throw OSRMException("no mem index file name in server ini"); throw OSRMException("no hsgr file given in ini file");
} }
if ( !server_config.Holds("nodesData") ) { if( server_paths.find("ramindex") == server_paths.end() ) {
throw OSRMException("no nodes file name in server ini"); throw OSRMException("no ram index file given in ini file");
} }
if ( !server_config.Holds("edgesData") ) { if( server_paths.find("fileindex") == server_paths.end() ) {
throw OSRMException("no edges file name in server ini"); throw OSRMException("no leaf index file given in ini file");
}
if( server_paths.find("nodesdata") == server_paths.end() ) {
throw OSRMException("no nodes file given in ini file");
}
if( server_paths.find("edgesdata") == server_paths.end() ) {
throw OSRMException("no edges file given in ini file");
}
if( server_paths.find("namesdata") == server_paths.end() ) {
throw OSRMException("no names file given in ini file");
} }
//generate paths of data files ServerPaths::const_iterator paths_iterator = server_paths.find("hsgrdata");
boost::filesystem::path hsgr_path = boost::filesystem::absolute( BOOST_ASSERT(server_paths.end() != paths_iterator);
server_config.GetParameter("hsgrData"), const boost::filesystem::path & hsgr_path = paths_iterator->second;
base_path paths_iterator = server_paths.find("timestamp");
); BOOST_ASSERT(server_paths.end() != paths_iterator);
boost::filesystem::path ram_index_path = boost::filesystem::absolute( const boost::filesystem::path & timestamp_path = paths_iterator->second;
server_config.GetParameter("ramIndex"), paths_iterator = server_paths.find("ramindex");
base_path BOOST_ASSERT(server_paths.end() != paths_iterator);
); const boost::filesystem::path & ram_index_path = paths_iterator->second;
boost::filesystem::path node_data_path = boost::filesystem::absolute( // paths_iterator = server_paths.find("fileindex");
server_config.GetParameter("nodesData"), // BOOST_ASSERT(server_paths.end() != paths_iterator);
base_path // const boost::filesystem::path & file_index_path = paths_iterator->second;
); paths_iterator = server_paths.find("nodesdata");
boost::filesystem::path edge_data_path = boost::filesystem::absolute( BOOST_ASSERT(server_paths.end() != paths_iterator);
server_config.GetParameter("edgesData"), const boost::filesystem::path & nodes_data_path = paths_iterator->second;
base_path paths_iterator = server_paths.find("edgesdata");
); BOOST_ASSERT(server_paths.end() != paths_iterator);
boost::filesystem::path name_data_path = boost::filesystem::absolute( const boost::filesystem::path & edges_data_path = paths_iterator->second;
server_config.GetParameter("namesData"), paths_iterator = server_paths.find("namesdata");
base_path BOOST_ASSERT(server_paths.end() != paths_iterator);
); const boost::filesystem::path & names_data_path = paths_iterator->second;
boost::filesystem::path timestamp_path = boost::filesystem::absolute(
server_config.GetParameter("timestamp"),
base_path
);
//check if data files actually exist
if ( !boost::filesystem::exists(hsgr_path) ) {
throw(".hsgr not found");
}
if ( !boost::filesystem::exists(ram_index_path) ) {
throw(".ramIndex not found");
}
if ( !boost::filesystem::exists(node_data_path) ) {
throw(".nodes not found");
}
if ( !boost::filesystem::exists(edge_data_path) ) {
throw(".edges not found");
}
if ( !boost::filesystem::exists(name_data_path) ) {
throw(".names not found");
}
// check if data files empty
if ( 0 == boost::filesystem::file_size( node_data_path ) ) {
throw OSRMException("nodes file is empty");
}
if ( 0 == boost::filesystem::file_size( edge_data_path ) ) {
throw OSRMException("edges file is empty");
}
// Allocate a memory layout in shared memory // // Allocate a memory layout in shared memory //
SharedMemory * layout_memory = SharedMemoryFactory::Get( SharedMemory * layout_memory = SharedMemoryFactory::Get(
@ -128,7 +117,7 @@ int main(int argc, char * argv[]) {
SimpleLogger().Write() << "Collecting files sizes"; SimpleLogger().Write() << "Collecting files sizes";
// number of entries in name index // number of entries in name index
boost::filesystem::ifstream name_stream( boost::filesystem::ifstream name_stream(
name_data_path, std::ios::binary names_data_path, std::ios::binary
); );
unsigned name_index_size = 0; unsigned name_index_size = 0;
name_stream.read((char *)&name_index_size, sizeof(unsigned)); name_stream.read((char *)&name_index_size, sizeof(unsigned));
@ -143,7 +132,7 @@ int main(int argc, char * argv[]) {
//Loading information for original edges //Loading information for original edges
boost::filesystem::ifstream edges_input_stream( boost::filesystem::ifstream edges_input_stream(
edge_data_path, edges_data_path,
std::ios::binary std::ios::binary
); );
unsigned number_of_original_edges = 0; unsigned number_of_original_edges = 0;
@ -232,9 +221,9 @@ int main(int argc, char * argv[]) {
//load coordinate size //load coordinate size
SimpleLogger().Write() << SimpleLogger().Write() <<
"Loading coordinates list from " << node_data_path.string(); "Loading coordinates list from " << nodes_data_path.string();
boost::filesystem::ifstream nodes_input_stream( boost::filesystem::ifstream nodes_input_stream(
node_data_path, nodes_data_path,
std::ios::binary std::ios::binary
); );
unsigned coordinate_list_size = 0; unsigned coordinate_list_size = 0;
@ -252,7 +241,7 @@ int main(int argc, char * argv[]) {
// read actual data into shared memory object // // read actual data into shared memory object //
// Loading street names // Loading street names
SimpleLogger().Write() << "Loading names index and chars from: " << name_data_path.string(); SimpleLogger().Write() << "Loading names index and chars from: " << names_data_path.string();
unsigned * name_index_ptr = (unsigned*)( unsigned * name_index_ptr = (unsigned*)(
shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset() shared_memory_ptr + shared_layout_ptr->GetNameIndexOffset()
); );
@ -275,7 +264,7 @@ int main(int argc, char * argv[]) {
//load original edge information //load original edge information
SimpleLogger().Write() << SimpleLogger().Write() <<
"Loading via node, coordinates and turn instruction lists from: " << "Loading via node, coordinates and turn instruction lists from: " <<
edge_data_path.string(); edges_data_path.string();
NodeID * via_node_ptr = (NodeID *)( NodeID * via_node_ptr = (NodeID *)(
shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset() shared_memory_ptr + shared_layout_ptr->GetViaNodeListOffset()