intersection classes with variable degree of discretization

This commit is contained in:
Moritz Kobitzsch
2016-05-10 08:37:45 +02:00
committed by Patrick Niklaus
parent 0f3942558f
commit 4d9aa65e78
23 changed files with 724 additions and 702 deletions
+58 -18
View File
@@ -31,6 +31,7 @@
#include <cstdint>
#include <fstream>
#include <iostream>
#include <iterator>
#include <new>
#include <string>
@@ -574,36 +575,75 @@ int Storage::Run()
{
boost::filesystem::ifstream intersection_stream(config.intersection_class_path,
std::ios::binary);
if (!static_cast<bool>(intersection_stream))
throw util::exception("Could not open " + config.intersection_class_path.string() +
" for reading.");
if (!util::readAndCheckFingerprint(intersection_stream))
{
util::SimpleLogger().Write(logWARNING)
<< "Fingerprint does not match or reading failed";
}
throw util::exception("Fingerprint of " + config.intersection_class_path.string() +
" does not match or could not read from file");
std::vector<BearingClassID> bearing_class_id_table;
util::deserializeVector(intersection_stream, bearing_class_id_table);
if (!util::deserializeVector(intersection_stream, bearing_class_id_table))
throw util::exception("Failed to read from " + config.names_data_path.string());
shared_layout_ptr->SetBlockSize<BearingClassID>(SharedDataLayout::BEARING_CLASSID,
bearing_class_id_table.size());
auto bearing_id_ptr = shared_layout_ptr->GetBlockPtr<BearingClassID, true>(
shared_memory_ptr, SharedDataLayout::BEARING_CLASSID);
std::copy(bearing_class_id_table.begin(), bearing_class_id_table.end(), bearing_id_ptr);
auto bearing_class_ptr =
shared_layout_ptr->GetBlockPtr<util::guidance::BearingClass, true>(
shared_memory_ptr, SharedDataLayout::BEARING_CLASS);
std::vector<util::guidance::BearingClass> bearing_class_table;
util::deserializeVector(intersection_stream, bearing_class_table);
shared_layout_ptr->SetBlockSize<util::guidance::BearingClass>(
SharedDataLayout::BEARING_CLASS, bearing_class_table.size());
unsigned bearing_blocks = 0;
intersection_stream.read((char *)&bearing_blocks, sizeof(unsigned));
unsigned sum_lengths = 0;
intersection_stream.read((char *)&sum_lengths, sizeof(unsigned));
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::BEARING_OFFSETS,
bearing_blocks);
shared_layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(
SharedDataLayout::BEARING_BLOCKS, bearing_blocks);
unsigned *bearing_offsets_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
shared_memory_ptr, SharedDataLayout::BEARING_OFFSETS);
if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS) > 0)
{
intersection_stream.read(
reinterpret_cast<char *>(bearing_offsets_ptr),
shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS));
}
unsigned *bearing_blocks_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
shared_memory_ptr, SharedDataLayout::BEARING_BLOCKS);
if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS) > 0)
{
intersection_stream.read(
reinterpret_cast<char *>(bearing_blocks_ptr),
shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS));
}
std::uint64_t num_bearings;
intersection_stream >> num_bearings;
std::vector<DiscreteBearing> bearing_class_table(num_bearings);
intersection_stream.read(reinterpret_cast<char *>(&bearing_class_table[0]),
sizeof(bearing_class_table[0]) * num_bearings);
shared_layout_ptr->SetBlockSize<DiscreteBearing>(SharedDataLayout::BEARING_VALUES,
num_bearings);
auto bearing_class_ptr = shared_layout_ptr->GetBlockPtr<DiscreteBearing, true>(
shared_memory_ptr, SharedDataLayout::BEARING_VALUES);
std::copy(bearing_class_table.begin(), bearing_class_table.end(), bearing_class_ptr);
auto entry_class_ptr =
shared_layout_ptr->GetBlockPtr<util::guidance::EntryClass, true>(
shared_memory_ptr, SharedDataLayout::ENTRY_CLASS);
if (!static_cast<bool>(intersection_stream))
throw util::exception("Failed to read from " + config.names_data_path.string());
std::vector<util::guidance::EntryClass> entry_class_table;
util::deserializeVector(intersection_stream, entry_class_table);
shared_layout_ptr->SetBlockSize<util::guidance::EntryClass>(
SharedDataLayout::ENTRY_CLASS, entry_class_table.size());
if(!util::deserializeVector(intersection_stream, entry_class_table))
throw util::exception("Failed to read from " + config.names_data_path.string());
shared_layout_ptr->SetBlockSize<util::guidance::EntryClass>(SharedDataLayout::ENTRY_CLASS,
entry_class_table.size());
auto entry_class_ptr = shared_layout_ptr->GetBlockPtr<util::guidance::EntryClass, true>(
shared_memory_ptr, SharedDataLayout::ENTRY_CLASS);
std::copy(entry_class_table.begin(), entry_class_table.end(), entry_class_ptr);
}