From 74729a372b163a592d49a3d2e49cdef2a08c8c22 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Jun 2013 20:05:03 -0400 Subject: [PATCH] some refactoring --- Extractor/ExtractionContainers.cpp | 6 ++-- Extractor/ExtractionContainers.h | 2 +- createHierarchy.cpp | 8 ++--- extractor.cpp | 53 ++++++++++++++++-------------- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 2cb2baf22..14e8352b5 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -20,7 +20,7 @@ #include "ExtractionContainers.h" -void ExtractionContainers::PrepareData(const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM) { +void ExtractionContainers::PrepareData(const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM) { try { unsigned usedNodeCounter = 0; unsigned usedEdgeCounter = 0; @@ -130,7 +130,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const restrictionsOutstream.close(); std::ofstream fout; - fout.open(outputFileName.c_str(), std::ios::binary); + fout.open(output_file_name.c_str(), std::ios::binary); fout.write((char*)&usedNodeCounter, sizeof(unsigned)); time = get_timestamp(); std::cout << "[extractor] Confirming/Writing used nodes ... " << std::flush; @@ -271,7 +271,7 @@ void ExtractionContainers::PrepareData(const std::string & outputFileName, const std::cout << "ok" << std::endl; time = get_timestamp(); std::cout << "[extractor] writing street name index ... " << std::flush; - std::string nameOutFileName = (outputFileName + ".names"); + std::string nameOutFileName = (output_file_name + ".names"); std::ofstream nameOutFile(nameOutFileName.c_str(), std::ios::binary); unsigned sizeOfNameIndex = nameVector.size(); nameOutFile.write((char *)&(sizeOfNameIndex), sizeof(unsigned)); diff --git a/Extractor/ExtractionContainers.h b/Extractor/ExtractionContainers.h index f5dfa789d..f3815c12f 100644 --- a/Extractor/ExtractionContainers.h +++ b/Extractor/ExtractionContainers.h @@ -55,7 +55,7 @@ public: wayStartEndVector.clear(); } - void PrepareData( const std::string & outputFileName, const std::string restrictionsFileName, const unsigned amountOfRAM); + void PrepareData( const std::string & output_file_name, const std::string restrictionsFileName, const unsigned amountOfRAM); STXXLNodeIDVector usedNodeIDs; STXXLNodeVector allNodes; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 5e6343d1d..3f76fcd19 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -63,14 +63,14 @@ int main (int argc, char *argv[]) { } double startupTime = get_timestamp(); - unsigned numberOfThreads = omp_get_num_procs(); + unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("contractor.ini")) { ContractorConfiguration contractorConfig("contractor.ini"); unsigned rawNumber = stringToInt(contractorConfig.GetParameter("Threads")); - if(rawNumber != 0 && rawNumber <= numberOfThreads) - numberOfThreads = rawNumber; + if(rawNumber != 0 && rawNumber <= number_of_threads) + number_of_threads = rawNumber; } - omp_set_num_threads(numberOfThreads); + omp_set_num_threads(number_of_threads); INFO("Using restrictions from file: " << argv[2]); std::ifstream restrictionsInstream(argv[2], std::ios::binary); diff --git a/extractor.cpp b/extractor.cpp index 3beeef510..800fd8be5 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -31,17 +31,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "typedefs.h" #include + #include #include - #include -typedef BaseConfiguration ExtractorConfiguration; - ExtractorCallbacks * extractCallBacks; int main (int argc, char *argv[]) { - double earliestTime = get_timestamp(); + double startup_time = get_timestamp(); if(argc < 2) { ERR("usage: \n" << argv[0] << " []"); @@ -50,36 +48,37 @@ int main (int argc, char *argv[]) { /*** Setup Scripting Environment ***/ ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); - unsigned numberOfThreads = omp_get_num_procs(); + unsigned number_of_threads = omp_get_num_procs(); if(testDataFile("extractor.ini")) { - ExtractorConfiguration extractorConfig("extractor.ini"); + BaseConfiguration extractorConfig("extractor.ini"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads")); - if( rawNumber != 0 && rawNumber <= numberOfThreads) - numberOfThreads = rawNumber; + if( rawNumber != 0 && rawNumber <= number_of_threads) { + number_of_threads = rawNumber; + } } - omp_set_num_threads(numberOfThreads); + omp_set_num_threads(number_of_threads); INFO("extracting data from input file " << argv[1]); - bool isPBF(false); - std::string outputFileName(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 = outputFileName.find(".osm.bz2"); + std::string::size_type pos = output_file_name.find(".osm.bz2"); if(pos==std::string::npos) { - pos = outputFileName.find(".osm.pbf"); + pos = output_file_name.find(".osm.pbf"); if(pos!=std::string::npos) { - isPBF = true; + file_has_pbf_format = true; } } if(pos!=std::string::npos) { - outputFileName.replace(pos, 8, ".osrm"); + output_file_name.replace(pos, 8, ".osrm"); restrictionsFileName.replace(pos, 8, ".osrm.restrictions"); } else { - pos=outputFileName.find(".osm"); + pos=output_file_name.find(".osm"); if(pos!=std::string::npos) { - outputFileName.replace(pos, 5, ".osrm"); + output_file_name.replace(pos, 5, ".osrm"); restrictionsFileName.replace(pos, 5, ".osrm.restrictions"); } else { - outputFileName.append(".osrm"); + output_file_name.append(".osrm"); restrictionsFileName.append(".osrm.restrictions"); } } @@ -96,7 +95,7 @@ int main (int argc, char *argv[]) { stringMap[""] = 0; extractCallBacks = new ExtractorCallbacks(&externalMemory, &stringMap); BaseParser* parser; - if(isPBF) { + if(file_has_pbf_format) { parser = new PBFParser(argv[1], extractCallBacks, scriptingEnvironment); } else { parser = new XMLParser(argv[1], extractCallBacks, scriptingEnvironment); @@ -106,18 +105,22 @@ int main (int argc, char *argv[]) { ERR("Parser not initialized!"); } INFO("Parsing in progress.."); - double time = get_timestamp(); + double parsing_start_time = get_timestamp(); parser->Parse(); - INFO("Parsing finished after " << get_timestamp() - time << " seconds"); + INFO("Parsing finished after " << + (get_timestamp() - parsing_start_time) << + " seconds" + ); - externalMemory.PrepareData(outputFileName, restrictionsFileName, amountOfRAM); + externalMemory.PrepareData(output_file_name, restrictionsFileName, amountOfRAM); - stringMap.clear(); delete parser; delete extractCallBacks; - INFO("finished after " << get_timestamp() - earliestTime << "s"); + + INFO("extraction finished after " << get_timestamp() - startup_time << "s"); std::cout << "\nRun:\n" - "./osrm-prepare " << outputFileName << " " << restrictionsFileName << std::endl; + << "./osrm-prepare " << output_file_name << " " << restrictionsFileName + << std::endl; return 0; }