diff --git a/include/customizer/io.hpp b/include/customizer/io.hpp deleted file mode 100644 index d0704a65f..000000000 --- a/include/customizer/io.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OSRM_CUSTOMIZER_IO_HPP -#define OSRM_CUSTOMIZER_IO_HPP - -#include "customizer/edge_based_graph.hpp" - -#include "storage/io.hpp" - -namespace osrm -{ -namespace customizer -{ -namespace io -{ -} -} -} - -#endif diff --git a/include/partition/cell_storage.hpp b/include/partition/cell_storage.hpp index 414603378..c5c1b94dd 100644 --- a/include/partition/cell_storage.hpp +++ b/include/partition/cell_storage.hpp @@ -23,6 +23,15 @@ namespace osrm { +namespace storage +{ +namespace io +{ +class FileReader; +class FileWriter; +} +} + namespace partition { namespace detail @@ -32,12 +41,12 @@ template class CellStorageImpl; using CellStorage = detail::CellStorageImpl; using CellStorageView = detail::CellStorageImpl; -namespace io +namespace serialization { template -inline void read(const boost::filesystem::path &path, detail::CellStorageImpl &storage); +inline void read(storage::io::FileReader &reader, detail::CellStorageImpl &storage); template -inline void write(const boost::filesystem::path &path, +inline void write(storage::io::FileWriter &writer, const detail::CellStorageImpl &storage); } @@ -88,10 +97,9 @@ template class CellStorageImpl WeightValueT, boost::random_access_traversal_tag> { - typedef boost::iterator_facade - base_t; + typedef boost:: + iterator_facade + base_t; public: typedef typename base_t::value_type value_type; @@ -352,10 +360,10 @@ template class CellStorageImpl cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()}; } - friend void io::read(const boost::filesystem::path &path, - detail::CellStorageImpl &storage); - friend void io::write(const boost::filesystem::path &path, - const detail::CellStorageImpl &storage); + friend void serialization::read(storage::io::FileReader &reader, + detail::CellStorageImpl &storage); + friend void serialization::write(storage::io::FileWriter &writer, + const detail::CellStorageImpl &storage); private: Vector weights; diff --git a/include/partition/files.hpp b/include/partition/files.hpp new file mode 100644 index 000000000..b53ad2cee --- /dev/null +++ b/include/partition/files.hpp @@ -0,0 +1,76 @@ +#ifndef OSRM_PARTITION_SERILIZATION_HPP +#define OSRM_PARTITION_SERILIZATION_HPP + +#include "partition/serialization.hpp" + +#include "storage/io.hpp" + +namespace osrm +{ +namespace partition +{ +namespace files +{ + +// reads .osrm.mldgr file +template +inline void readGraph(const boost::filesystem::path &path, + MultiLevelGraph &graph) +{ + const auto fingerprint = storage::io::FileReader::VerifyFingerprint; + storage::io::FileReader reader{path, fingerprint}; + + serialization::read(reader, graph); +} + +// writes .osrm.mldgr file +template +inline void writeGraph(const boost::filesystem::path &path, + const MultiLevelGraph &graph) +{ + const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; + storage::io::FileWriter writer{path, fingerprint}; + + serialization::write(writer, graph); +} + +// read .osrm.partition file +inline void readPartition(const boost::filesystem::path &path, MultiLevelPartition &mlp) +{ + const auto fingerprint = storage::io::FileReader::VerifyFingerprint; + storage::io::FileReader reader{path, fingerprint}; + + serialization::read(reader, mlp); +} + +// writes .osrm.partition file +inline void writePartition(const boost::filesystem::path &path, const MultiLevelPartition &mlp) +{ + const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; + storage::io::FileWriter writer{path, fingerprint}; + + serialization::write(writer, mlp); +} + +// reads .osrm.cells file +inline void readCells(const boost::filesystem::path &path, CellStorage &storage) +{ + const auto fingerprint = storage::io::FileReader::VerifyFingerprint; + storage::io::FileReader reader{path, fingerprint}; + + serialization::read(reader, storage); +} + +// writes .osrm.cells file +inline void writeCells(const boost::filesystem::path &path, const CellStorage &storage) +{ + const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; + storage::io::FileWriter writer{path, fingerprint}; + + serialization::write(writer, storage); +} +} +} +} + +#endif diff --git a/include/partition/multi_level_graph.hpp b/include/partition/multi_level_graph.hpp index f61be06cf..622a83fad 100644 --- a/include/partition/multi_level_graph.hpp +++ b/include/partition/multi_level_graph.hpp @@ -14,17 +14,26 @@ namespace osrm { +namespace storage +{ +namespace io +{ +class FileReader; +class FileWriter; +} +} + namespace partition { template class MultiLevelGraph; -namespace io +namespace serialization { template -void read(const boost::filesystem::path &path, MultiLevelGraph &graph); +void read(storage::io::FileReader &reader, MultiLevelGraph &graph); template -void write(const boost::filesystem::path &path, const MultiLevelGraph &graph); +void write(storage::io::FileWriter &writer, const MultiLevelGraph &graph); } template @@ -190,10 +199,12 @@ class MultiLevelGraph : public util::StaticGraph node_to_edge_offset.push_back(mlp.GetNumberOfLevels()); } - friend void io::read(const boost::filesystem::path &path, - MultiLevelGraph &graph); - friend void io::write(const boost::filesystem::path &path, - const MultiLevelGraph &graph); + friend void + serialization::read(storage::io::FileReader &reader, + MultiLevelGraph &graph); + friend void + serialization::write(storage::io::FileWriter &writer, + const MultiLevelGraph &graph); Vector node_to_edge_offset; }; diff --git a/include/partition/multi_level_partition.hpp b/include/partition/multi_level_partition.hpp index c9914e9ec..9d91d824c 100644 --- a/include/partition/multi_level_partition.hpp +++ b/include/partition/multi_level_partition.hpp @@ -22,6 +22,14 @@ namespace osrm { +namespace storage +{ +namespace io +{ +class FileReader; +class FileWriter; +} +} namespace partition { namespace detail @@ -31,13 +39,12 @@ template class MultiLevelPartitionImpl; using MultiLevelPartition = detail::MultiLevelPartitionImpl; using MultiLevelPartitionView = detail::MultiLevelPartitionImpl; -namespace io +namespace serialization { template -void read(const boost::filesystem::path &file, detail::MultiLevelPartitionImpl &mlp); +void read(storage::io::FileReader &reader, detail::MultiLevelPartitionImpl &mlp); template -void write(const boost::filesystem::path &file, - const detail::MultiLevelPartitionImpl &mlp); +void write(storage::io::FileWriter &writer, const detail::MultiLevelPartitionImpl &mlp); } namespace detail @@ -134,10 +141,10 @@ template class MultiLevelPartitionImpl final return cell_to_children[offset + cell + 1]; } - friend void io::read(const boost::filesystem::path &file, - MultiLevelPartitionImpl &mlp); - friend void io::write(const boost::filesystem::path &file, - const MultiLevelPartitionImpl &mlp); + friend void serialization::read(storage::io::FileReader &reader, + MultiLevelPartitionImpl &mlp); + friend void serialization::write(storage::io::FileWriter &writer, + const MultiLevelPartitionImpl &mlp); private: auto MakeLevelData(const std::vector &lidx_to_num_cells) diff --git a/include/partition/io.hpp b/include/partition/serialization.hpp similarity index 54% rename from include/partition/io.hpp rename to include/partition/serialization.hpp index 8ca76ffd1..c2c2446d2 100644 --- a/include/partition/io.hpp +++ b/include/partition/serialization.hpp @@ -1,5 +1,5 @@ -#ifndef OSRM_PARTITION_IO_HPP -#define OSRM_PARTITION_IO_HPP +#ifndef OSRM_PARTITION_SERIALIZATION_HPP +#define OSRM_PARTITION_SERIALIZATION_HPP #include "partition/cell_storage.hpp" #include "partition/edge_based_graph.hpp" @@ -13,57 +13,43 @@ namespace osrm { namespace partition { -namespace io +namespace serialization { template -inline void read(const boost::filesystem::path &path, MultiLevelGraph &graph) +inline void read(storage::io::FileReader &reader, + MultiLevelGraph &graph) { - const auto fingerprint = storage::io::FileReader::VerifyFingerprint; - storage::io::FileReader reader{path, fingerprint}; - reader.DeserializeVector(graph.node_array); reader.DeserializeVector(graph.edge_array); reader.DeserializeVector(graph.edge_to_level); } template -inline void write(const boost::filesystem::path &path, +inline void write(storage::io::FileWriter &writer, const MultiLevelGraph &graph) { - const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; - storage::io::FileWriter writer{path, fingerprint}; - writer.SerializeVector(graph.node_array); writer.SerializeVector(graph.edge_array); writer.SerializeVector(graph.node_to_edge_offset); } -template <> inline void read(const boost::filesystem::path &path, MultiLevelPartition &mlp) +template <> inline void read(storage::io::FileReader &reader, MultiLevelPartition &mlp) { - const auto fingerprint = storage::io::FileReader::VerifyFingerprint; - storage::io::FileReader reader{path, fingerprint}; - reader.ReadInto(mlp.level_data); reader.DeserializeVector(mlp.partition); reader.DeserializeVector(mlp.cell_to_children); } -template <> inline void write(const boost::filesystem::path &path, const MultiLevelPartition &mlp) +template <> inline void write(storage::io::FileWriter &writer, const MultiLevelPartition &mlp) { - const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; - storage::io::FileWriter writer{path, fingerprint}; - writer.WriteOne(mlp.level_data); writer.SerializeVector(mlp.partition); writer.SerializeVector(mlp.cell_to_children); } -template <> inline void read(const boost::filesystem::path &path, CellStorage &storage) +template <> inline void read(storage::io::FileReader &reader, CellStorage &storage) { - const auto fingerprint = storage::io::FileReader::VerifyFingerprint; - storage::io::FileReader reader{path, fingerprint}; - reader.DeserializeVector(storage.weights); reader.DeserializeVector(storage.source_boundary); reader.DeserializeVector(storage.destination_boundary); @@ -71,11 +57,8 @@ template <> inline void read(const boost::filesystem::path &path, CellStorage &s reader.DeserializeVector(storage.level_to_cell_offset); } -template <> inline void write(const boost::filesystem::path &path, const CellStorage &storage) +template <> inline void write(storage::io::FileWriter &writer, const CellStorage &storage) { - const auto fingerprint = storage::io::FileWriter::GenerateFingerprint; - storage::io::FileWriter writer{path, fingerprint}; - writer.SerializeVector(storage.weights); writer.SerializeVector(storage.source_boundary); writer.SerializeVector(storage.destination_boundary); diff --git a/src/customize/customizer.cpp b/src/customize/customizer.cpp index c9c7c3b63..19a356b1b 100644 --- a/src/customize/customizer.cpp +++ b/src/customize/customizer.cpp @@ -1,11 +1,10 @@ #include "customizer/customizer.hpp" #include "customizer/cell_customizer.hpp" #include "customizer/edge_based_graph.hpp" -#include "customizer/io.hpp" #include "partition/cell_storage.hpp" #include "partition/edge_based_graph_reader.hpp" -#include "partition/io.hpp" +#include "partition/files.hpp" #include "partition/multi_level_partition.hpp" #include "storage/shared_memory_ownership.hpp" @@ -100,12 +99,12 @@ int Customizer::Run(const CustomizationConfig &config) TIMER_START(loading_data); partition::MultiLevelPartition mlp; - partition::io::read(config.mld_partition_path, mlp); + partition::files::readPartition(config.mld_partition_path, mlp); auto edge_based_graph = LoadAndUpdateEdgeExpandedGraph(config, mlp); partition::CellStorage storage; - partition::io::read(config.mld_storage_path, storage); + partition::files::readCells(config.mld_storage_path, storage); TIMER_STOP(loading_data); util::Log() << "Loading partition data took " << TIMER_SEC(loading_data) << " seconds"; @@ -116,12 +115,12 @@ int Customizer::Run(const CustomizationConfig &config) util::Log() << "Cells customization took " << TIMER_SEC(cell_customize) << " seconds"; TIMER_START(writing_mld_data); - partition::io::write(config.mld_storage_path, storage); + partition::files::writeCells(config.mld_storage_path, storage); TIMER_STOP(writing_mld_data); util::Log() << "MLD customization writing took " << TIMER_SEC(writing_mld_data) << " seconds"; TIMER_START(writing_graph); - partition::io::write(config.mld_graph_path, *edge_based_graph); + partition::files::writeGraph(config.mld_graph_path, *edge_based_graph); TIMER_STOP(writing_graph); util::Log() << "Graph writing took " << TIMER_SEC(writing_graph) << " seconds"; diff --git a/src/partition/partitioner.cpp b/src/partition/partitioner.cpp index f13281983..41b1621f6 100644 --- a/src/partition/partitioner.cpp +++ b/src/partition/partitioner.cpp @@ -4,7 +4,7 @@ #include "partition/cell_storage.hpp" #include "partition/compressed_node_based_graph_reader.hpp" #include "partition/edge_based_graph_reader.hpp" -#include "partition/io.hpp" +#include "partition/files.hpp" #include "partition/multi_level_partition.hpp" #include "partition/recursive_bisection.hpp" #include "partition/remove_unconnected.hpp" @@ -184,8 +184,8 @@ int Partitioner::Run(const PartitionConfig &config) util::Log() << "CellStorage constructed in " << TIMER_SEC(cell_storage) << " seconds"; TIMER_START(writing_mld_data); - io::write(config.mld_partition_path, mlp); - io::write(config.mld_storage_path, storage); + files::writePartition(config.mld_partition_path, mlp); + files::writeCells(config.mld_storage_path, storage); TIMER_STOP(writing_mld_data); util::Log() << "MLD data writing took " << TIMER_SEC(writing_mld_data) << " seconds";