diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index b140eca01..65639c83d 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -312,6 +312,65 @@ int Storage::Run() shared_layout_ptr->SetBlockSize(SharedDataLayout::DATASOURCE_NAME_LENGTHS, m_datasource_name_lengths.size()); + boost::filesystem::ifstream intersection_stream(config.intersection_class_path, + std::ios::binary); + if (!static_cast(intersection_stream)) + throw util::exception("Could not open " + config.intersection_class_path.string() + + " for reading."); + + if (!util::readAndCheckFingerprint(intersection_stream)) + throw util::exception("Fingerprint of " + config.intersection_class_path.string() + + " does not match or could not read from file"); + + std::vector 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(SharedDataLayout::BEARING_CLASSID, + bearing_class_id_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(SharedDataLayout::BEARING_OFFSETS, bearing_blocks); + shared_layout_ptr->SetBlockSize::BlockT>( + SharedDataLayout::BEARING_BLOCKS, bearing_blocks); + + std::vector bearing_offsets_data(bearing_blocks); + std::vector bearing_blocks_data(bearing_blocks); + + if (bearing_blocks) + { + intersection_stream.read( + reinterpret_cast(&bearing_offsets_data[0]), + shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS)); + } + + if (bearing_blocks) + { + intersection_stream.read(reinterpret_cast(&bearing_blocks_data[0]), + shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS)); + } + + std::uint64_t num_bearings; + intersection_stream >> num_bearings; + + std::vector bearing_class_table(num_bearings); + intersection_stream.read(reinterpret_cast(&bearing_class_table[0]), + sizeof(bearing_class_table[0]) * num_bearings); + shared_layout_ptr->SetBlockSize(SharedDataLayout::BEARING_VALUES, + num_bearings); + if (!static_cast(intersection_stream)) + throw util::exception("Failed to read from " + config.names_data_path.string()); + + std::vector entry_class_table; + if (!util::deserializeVector(intersection_stream, entry_class_table)) + throw util::exception("Failed to read from " + config.names_data_path.string()); + + shared_layout_ptr->SetBlockSize(SharedDataLayout::ENTRY_CLASS, + entry_class_table.size()); + // allocate shared memory block util::SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; @@ -572,88 +631,40 @@ int Storage::Run() } // load intersection classes + if (!bearing_class_id_table.empty()) { - boost::filesystem::ifstream intersection_stream(config.intersection_class_path, - std::ios::binary); - if (!static_cast(intersection_stream)) - throw util::exception("Could not open " + config.intersection_class_path.string() + - " for reading."); + auto bearing_id_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::BEARING_CLASSID); + std::copy(bearing_class_id_table.begin(), bearing_class_id_table.end(), bearing_id_ptr); + } - if (!util::readAndCheckFingerprint(intersection_stream)) - throw util::exception("Fingerprint of " + config.intersection_class_path.string() + - " does not match or could not read from file"); + if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS) > 0) + { + unsigned *bearing_offsets_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::BEARING_OFFSETS); + std::copy(bearing_offsets_data.begin(), bearing_offsets_data.end(), + bearing_offsets_ptr); + } - std::vector 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()); + if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS) > 0) + { + unsigned *bearing_blocks_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::BEARING_BLOCKS); + std::copy(bearing_blocks_data.begin(), bearing_blocks_data.end(),bearing_blocks_ptr); + } - shared_layout_ptr->SetBlockSize(SharedDataLayout::BEARING_CLASSID, - bearing_class_id_table.size()); - if (!bearing_class_id_table.empty()) - { - auto bearing_id_ptr = shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::BEARING_CLASSID); - std::copy(bearing_class_id_table.begin(), bearing_class_id_table.end(), bearing_id_ptr); - } + if (!bearing_class_table.empty()) + { + auto bearing_class_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::BEARING_VALUES); + std::copy(bearing_class_table.begin(), bearing_class_table.end(), bearing_class_ptr); + } - 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(SharedDataLayout::BEARING_OFFSETS, - bearing_blocks); - shared_layout_ptr->SetBlockSize::BlockT>( - SharedDataLayout::BEARING_BLOCKS, bearing_blocks); - - if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS) > 0) - { - unsigned *bearing_offsets_ptr = shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::BEARING_OFFSETS); - intersection_stream.read( - reinterpret_cast(bearing_offsets_ptr), - shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_OFFSETS)); - } - - if (shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS) > 0) - { - unsigned *bearing_blocks_ptr = shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::BEARING_BLOCKS); - intersection_stream.read( - reinterpret_cast(bearing_blocks_ptr), - shared_layout_ptr->GetBlockSize(SharedDataLayout::BEARING_BLOCKS)); - } - - std::uint64_t num_bearings; - intersection_stream >> num_bearings; - - std::vector bearing_class_table(num_bearings); - intersection_stream.read(reinterpret_cast(&bearing_class_table[0]), - sizeof(bearing_class_table[0]) * num_bearings); - shared_layout_ptr->SetBlockSize(SharedDataLayout::BEARING_VALUES, - num_bearings); - if (!bearing_class_table.empty()) - { - auto bearing_class_ptr = shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::BEARING_VALUES); - std::copy(bearing_class_table.begin(), bearing_class_table.end(), bearing_class_ptr); - } - - if (!static_cast(intersection_stream)) - throw util::exception("Failed to read from " + config.names_data_path.string()); - - std::vector entry_class_table; - if (!util::deserializeVector(intersection_stream, entry_class_table)) - throw util::exception("Failed to read from " + config.names_data_path.string()); - - shared_layout_ptr->SetBlockSize(SharedDataLayout::ENTRY_CLASS, - entry_class_table.size()); - if (!entry_class_table.empty()) - { - auto entry_class_ptr = shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::ENTRY_CLASS); - std::copy(entry_class_table.begin(), entry_class_table.end(), entry_class_ptr); - } + if (!entry_class_table.empty()) + { + auto entry_class_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::ENTRY_CLASS); + std::copy(entry_class_table.begin(), entry_class_table.end(), entry_class_ptr); } data_timestamp_ptr->layout = layout_region;