const-ify things, use RAII for file closure, and start to use io:: to read some stuff.

This commit is contained in:
Daniel Patterson 2016-11-10 23:04:32 -08:00
parent b1125b7f1f
commit e226b52f21
3 changed files with 307 additions and 290 deletions

View File

@ -21,10 +21,17 @@ namespace io
{ {
// Reads the count of elements that is written in the file header and returns the number // Reads the count of elements that is written in the file header and returns the number
inline std::uint64_t readElementCount(boost::filesystem::ifstream &input_stream) inline std::uint64_t readElementCount64(boost::filesystem::ifstream &input_stream)
{ {
std::uint64_t number_of_elements = 0; std::uint64_t number_of_elements = 0;
input_stream.read((char *)&number_of_elements, sizeof(std::uint64_t)); input_stream.read(reinterpret_cast<char *>(&number_of_elements), sizeof(number_of_elements));
return number_of_elements;
}
inline std::uint64_t readElementCount32(boost::filesystem::ifstream &input_stream)
{
std::uint32_t number_of_elements = 0;
input_stream.read(reinterpret_cast<char *>(&number_of_elements), sizeof(number_of_elements));
return number_of_elements; return number_of_elements;
} }

View File

@ -357,7 +357,7 @@ class StaticRTree
} }
boost::filesystem::ifstream tree_node_file(node_file, std::ios::binary); boost::filesystem::ifstream tree_node_file(node_file, std::ios::binary);
const auto tree_size = storage::io::readElementCount(tree_node_file); const auto tree_size = storage::io::readElementCount64(tree_node_file);
m_search_tree.resize(tree_size); m_search_tree.resize(tree_size);
storage::io::readRamIndex(tree_node_file, &m_search_tree[0], tree_size); storage::io::readRamIndex(tree_node_file, &m_search_tree[0], tree_size);

View File

@ -252,248 +252,267 @@ Storage::ReturnCode Storage::Run(int max_wait)
*/ */
void Storage::LoadLayout(DataLayout *layout_ptr) void Storage::LoadLayout(DataLayout *layout_ptr)
{ {
auto absolute_file_index_path = boost::filesystem::absolute(config.file_index_path);
layout_ptr->SetBlockSize<char>(DataLayout::FILE_INDEX_PATH,
absolute_file_index_path.string().length() + 1);
// collect number of elements to store in shared memory object
util::SimpleLogger().Write() << "load names from: " << config.names_data_path;
// number of entries in name index
boost::filesystem::ifstream name_stream(config.names_data_path, std::ios::binary);
if (!name_stream)
{ {
throw util::exception("Could not open " + config.names_data_path.string() + auto absolute_file_index_path = boost::filesystem::absolute(config.file_index_path);
" for reading.");
layout_ptr->SetBlockSize<char>(DataLayout::FILE_INDEX_PATH,
absolute_file_index_path.string().length() + 1);
} }
unsigned name_blocks = 0;
name_stream.read((char *)&name_blocks, sizeof(unsigned));
layout_ptr->SetBlockSize<unsigned>(DataLayout::NAME_OFFSETS, name_blocks);
layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(DataLayout::NAME_BLOCKS,
name_blocks);
BOOST_ASSERT_MSG(0 != name_blocks, "name file broken");
unsigned number_of_chars = 0; {
name_stream.read((char *)&number_of_chars, sizeof(unsigned)); // collect number of elements to store in shared memory object
layout_ptr->SetBlockSize<char>(DataLayout::NAME_CHAR_LIST, number_of_chars); util::SimpleLogger().Write() << "load names from: " << config.names_data_path;
// number of entries in name index
boost::filesystem::ifstream name_stream(config.names_data_path, std::ios::binary);
if (!name_stream)
{
throw util::exception("Could not open " + config.names_data_path.string() +
" for reading.");
}
const auto name_blocks = io::readElementCount32(name_stream);
layout_ptr->SetBlockSize<unsigned>(DataLayout::NAME_OFFSETS, name_blocks);
layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(
DataLayout::NAME_BLOCKS, name_blocks);
BOOST_ASSERT_MSG(0 != name_blocks, "name file broken");
std::vector<std::uint32_t> lane_description_offsets; const auto number_of_chars = io::readElementCount32(name_stream);
std::vector<extractor::guidance::TurnLaneType::Mask> lane_description_masks; layout_ptr->SetBlockSize<char>(DataLayout::NAME_CHAR_LIST, number_of_chars);
if (!util::deserializeAdjacencyArray(config.turn_lane_description_path.string(), }
lane_description_offsets,
lane_description_masks)) {
throw util::exception("Failed to read lane descriptions from: " + std::vector<std::uint32_t> lane_description_offsets;
config.turn_lane_description_path.string()); std::vector<extractor::guidance::TurnLaneType::Mask> lane_description_masks;
layout_ptr->SetBlockSize<std::uint32_t>(DataLayout::LANE_DESCRIPTION_OFFSETS, if (!util::deserializeAdjacencyArray(config.turn_lane_description_path.string(),
lane_description_offsets.size()); lane_description_offsets,
layout_ptr->SetBlockSize<extractor::guidance::TurnLaneType::Mask>( lane_description_masks))
DataLayout::LANE_DESCRIPTION_MASKS, lane_description_masks.size()); throw util::exception("Failed to read lane descriptions from: " +
config.turn_lane_description_path.string());
layout_ptr->SetBlockSize<std::uint32_t>(DataLayout::LANE_DESCRIPTION_OFFSETS,
lane_description_offsets.size());
layout_ptr->SetBlockSize<extractor::guidance::TurnLaneType::Mask>(
DataLayout::LANE_DESCRIPTION_MASKS, lane_description_masks.size());
}
// Loading information for original edges // Loading information for original edges
boost::filesystem::ifstream edges_input_stream(config.edges_data_path, std::ios::binary);
if (!edges_input_stream)
{ {
throw util::exception("Could not open " + config.edges_data_path.string() + boost::filesystem::ifstream edges_input_stream(config.edges_data_path, std::ios::binary);
" for reading."); if (!edges_input_stream)
} {
const auto number_of_original_edges = io::readElementCount(edges_input_stream); throw util::exception("Could not open " + config.edges_data_path.string() +
" for reading.");
}
const auto number_of_original_edges = io::readElementCount64(edges_input_stream);
// note: settings this all to the same size is correct, we extract them from the same struct // note: settings this all to the same size is correct, we extract them from the same struct
layout_ptr->SetBlockSize<NodeID>(DataLayout::VIA_NODE_LIST, number_of_original_edges); layout_ptr->SetBlockSize<NodeID>(DataLayout::VIA_NODE_LIST, number_of_original_edges);
layout_ptr->SetBlockSize<unsigned>(DataLayout::NAME_ID_LIST, number_of_original_edges); layout_ptr->SetBlockSize<unsigned>(DataLayout::NAME_ID_LIST, number_of_original_edges);
layout_ptr->SetBlockSize<extractor::TravelMode>(DataLayout::TRAVEL_MODE, layout_ptr->SetBlockSize<extractor::TravelMode>(DataLayout::TRAVEL_MODE,
number_of_original_edges); number_of_original_edges);
layout_ptr->SetBlockSize<util::guidance::TurnBearing>(DataLayout::PRE_TURN_BEARING, layout_ptr->SetBlockSize<util::guidance::TurnBearing>(DataLayout::PRE_TURN_BEARING,
number_of_original_edges); number_of_original_edges);
layout_ptr->SetBlockSize<util::guidance::TurnBearing>(DataLayout::POST_TURN_BEARING, layout_ptr->SetBlockSize<util::guidance::TurnBearing>(DataLayout::POST_TURN_BEARING,
number_of_original_edges); number_of_original_edges);
layout_ptr->SetBlockSize<extractor::guidance::TurnInstruction>(DataLayout::TURN_INSTRUCTION, layout_ptr->SetBlockSize<extractor::guidance::TurnInstruction>(DataLayout::TURN_INSTRUCTION,
number_of_original_edges); number_of_original_edges);
layout_ptr->SetBlockSize<LaneDataID>(DataLayout::LANE_DATA_ID, number_of_original_edges); layout_ptr->SetBlockSize<LaneDataID>(DataLayout::LANE_DATA_ID, number_of_original_edges);
layout_ptr->SetBlockSize<EntryClassID>(DataLayout::ENTRY_CLASSID, number_of_original_edges); layout_ptr->SetBlockSize<EntryClassID>(DataLayout::ENTRY_CLASSID, number_of_original_edges);
boost::filesystem::ifstream hsgr_input_stream(config.hsgr_data_path, std::ios::binary);
if (!hsgr_input_stream)
{
throw util::exception("Could not open " + config.hsgr_data_path.string() + " for reading.");
} }
const auto hsgr_header = io::readHSGRHeader(hsgr_input_stream); {
layout_ptr->SetBlockSize<unsigned>(DataLayout::HSGR_CHECKSUM, 1); boost::filesystem::ifstream hsgr_input_stream(config.hsgr_data_path, std::ios::binary);
layout_ptr->SetBlockSize<QueryGraph::NodeArrayEntry>(DataLayout::GRAPH_NODE_LIST, if (!hsgr_input_stream)
hsgr_header.number_of_nodes); {
layout_ptr->SetBlockSize<QueryGraph::EdgeArrayEntry>(DataLayout::GRAPH_EDGE_LIST, throw util::exception("Could not open " + config.hsgr_data_path.string() +
hsgr_header.number_of_edges); " for reading.");
}
const auto hsgr_header = io::readHSGRHeader(hsgr_input_stream);
layout_ptr->SetBlockSize<unsigned>(DataLayout::HSGR_CHECKSUM, 1);
layout_ptr->SetBlockSize<QueryGraph::NodeArrayEntry>(DataLayout::GRAPH_NODE_LIST,
hsgr_header.number_of_nodes);
layout_ptr->SetBlockSize<QueryGraph::EdgeArrayEntry>(DataLayout::GRAPH_EDGE_LIST,
hsgr_header.number_of_edges);
}
// load rsearch tree size // load rsearch tree size
boost::filesystem::ifstream tree_node_file(config.ram_index_path, std::ios::binary); {
boost::filesystem::ifstream tree_node_file(config.ram_index_path, std::ios::binary);
const auto tree_size = io::readElementCount(tree_node_file); const auto tree_size = io::readElementCount64(tree_node_file);
layout_ptr->SetBlockSize<RTreeNode>(DataLayout::R_SEARCH_TREE, tree_size); layout_ptr->SetBlockSize<RTreeNode>(DataLayout::R_SEARCH_TREE, tree_size);
// allocate space in shared memory for profile properties // allocate space in shared memory for profile properties
const auto properties_size = io::readPropertiesCount(); const auto properties_size = io::readPropertiesCount();
layout_ptr->SetBlockSize<extractor::ProfileProperties>(DataLayout::PROPERTIES, properties_size); layout_ptr->SetBlockSize<extractor::ProfileProperties>(DataLayout::PROPERTIES,
properties_size);
}
// read timestampsize // read timestampsize
boost::filesystem::ifstream timestamp_stream(config.timestamp_path);
if (!timestamp_stream)
{ {
throw util::exception("Could not open " + config.timestamp_path.string() + " for reading."); boost::filesystem::ifstream timestamp_stream(config.timestamp_path);
if (!timestamp_stream)
{
throw util::exception("Could not open " + config.timestamp_path.string() +
" for reading.");
}
const auto timestamp_size = io::readNumberOfBytes(timestamp_stream);
layout_ptr->SetBlockSize<char>(DataLayout::TIMESTAMP, timestamp_size);
} }
const auto timestamp_size = io::readNumberOfBytes(timestamp_stream);
layout_ptr->SetBlockSize<char>(DataLayout::TIMESTAMP, timestamp_size);
// load core marker size // load core marker size
boost::filesystem::ifstream core_marker_file(config.core_data_path, std::ios::binary);
if (!core_marker_file)
{ {
throw util::exception("Could not open " + config.core_data_path.string() + " for reading."); boost::filesystem::ifstream core_marker_file(config.core_data_path, std::ios::binary);
} if (!core_marker_file)
{
throw util::exception("Could not open " + config.core_data_path.string() +
" for reading.");
}
uint32_t number_of_core_markers = 0; const auto number_of_core_markers = io::readElementCount32(core_marker_file);
core_marker_file.read((char *)&number_of_core_markers, sizeof(uint32_t)); layout_ptr->SetBlockSize<unsigned>(DataLayout::CORE_MARKER, number_of_core_markers);
layout_ptr->SetBlockSize<unsigned>(DataLayout::CORE_MARKER, number_of_core_markers); }
// load coordinate size // load coordinate size
boost::filesystem::ifstream nodes_input_stream(config.nodes_data_path, std::ios::binary);
if (!nodes_input_stream)
{ {
throw util::exception("Could not open " + config.core_data_path.string() + " for reading."); boost::filesystem::ifstream nodes_input_stream(config.nodes_data_path, std::ios::binary);
if (!nodes_input_stream)
{
throw util::exception("Could not open " + config.core_data_path.string() +
" for reading.");
}
const auto coordinate_list_size = io::readElementCount64(nodes_input_stream);
layout_ptr->SetBlockSize<util::Coordinate>(DataLayout::COORDINATE_LIST,
coordinate_list_size);
// we'll read a list of OSM node IDs from the same data, so set the block size for the same
// number of items:
layout_ptr->SetBlockSize<std::uint64_t>(
DataLayout::OSM_NODE_ID_LIST,
util::PackedVector<OSMNodeID>::elements_to_blocks(coordinate_list_size));
} }
const auto coordinate_list_size = io::readElementCount(nodes_input_stream);
layout_ptr->SetBlockSize<util::Coordinate>(DataLayout::COORDINATE_LIST, coordinate_list_size);
// we'll read a list of OSM node IDs from the same data, so set the block size for the same
// number of items:
layout_ptr->SetBlockSize<std::uint64_t>(
DataLayout::OSM_NODE_ID_LIST,
util::PackedVector<OSMNodeID>::elements_to_blocks(coordinate_list_size));
// load geometries sizes // load geometries sizes
boost::filesystem::ifstream geometry_input_stream(config.geometries_path, std::ios::binary);
if (!geometry_input_stream)
{ {
throw util::exception("Could not open " + config.geometries_path.string() + boost::filesystem::ifstream geometry_input_stream(config.geometries_path, std::ios::binary);
" for reading."); if (!geometry_input_stream)
} {
unsigned number_of_geometries_indices = 0; throw util::exception("Could not open " + config.geometries_path.string() +
unsigned number_of_compressed_geometries = 0; " for reading.");
}
geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned)); const auto number_of_geometries_indices = io::readElementCount32(geometry_input_stream);
layout_ptr->SetBlockSize<unsigned>(DataLayout::GEOMETRIES_INDEX, number_of_geometries_indices); layout_ptr->SetBlockSize<unsigned>(DataLayout::GEOMETRIES_INDEX,
boost::iostreams::seek( number_of_geometries_indices);
geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur); boost::iostreams::seek(
geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned)); geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur);
layout_ptr->SetBlockSize<NodeID>(DataLayout::GEOMETRIES_NODE_LIST,
number_of_compressed_geometries); const auto number_of_compressed_geometries = io::readElementCount32(geometry_input_stream);
layout_ptr->SetBlockSize<EdgeWeight>(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST, layout_ptr->SetBlockSize<NodeID>(DataLayout::GEOMETRIES_NODE_LIST,
number_of_compressed_geometries);
layout_ptr->SetBlockSize<EdgeWeight>(DataLayout::GEOMETRIES_REV_WEIGHT_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
layout_ptr->SetBlockSize<EdgeWeight>(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST,
number_of_compressed_geometries);
layout_ptr->SetBlockSize<EdgeWeight>(DataLayout::GEOMETRIES_REV_WEIGHT_LIST,
number_of_compressed_geometries);
}
// load datasource sizes. This file is optional, and it's non-fatal if it doesn't // load datasource sizes. This file is optional, and it's non-fatal if it doesn't
// exist. // exist.
boost::filesystem::ifstream geometry_datasource_input_stream(config.datasource_indexes_path,
std::ios::binary);
if (!geometry_datasource_input_stream)
{ {
throw util::exception("Could not open " + config.datasource_indexes_path.string() + boost::filesystem::ifstream geometry_datasource_input_stream(config.datasource_indexes_path,
" for reading."); std::ios::binary);
if (!geometry_datasource_input_stream)
{
throw util::exception("Could not open " + config.datasource_indexes_path.string() +
" for reading.");
}
const auto number_of_compressed_datasources =
io::readElementCount64(geometry_datasource_input_stream);
layout_ptr->SetBlockSize<uint8_t>(DataLayout::DATASOURCES_LIST,
number_of_compressed_datasources);
} }
const auto number_of_compressed_datasources =
io::readElementCount(geometry_datasource_input_stream);
layout_ptr->SetBlockSize<uint8_t>(DataLayout::DATASOURCES_LIST,
number_of_compressed_datasources);
// Load datasource name sizes. This file is optional, and it's non-fatal if it doesn't // Load datasource name sizes. This file is optional, and it's non-fatal if it doesn't
// exist // exist
boost::filesystem::ifstream datasource_names_input_stream(config.datasource_names_path,
std::ios::binary);
if (!datasource_names_input_stream)
{ {
throw util::exception("Could not open " + config.datasource_names_path.string() + boost::filesystem::ifstream datasource_names_input_stream(config.datasource_names_path,
" for reading."); std::ios::binary);
if (!datasource_names_input_stream)
{
throw util::exception("Could not open " + config.datasource_names_path.string() +
" for reading.");
}
const io::DatasourceNamesData datasource_names_data =
io::readDatasourceNames(datasource_names_input_stream);
layout_ptr->SetBlockSize<char>(DataLayout::DATASOURCE_NAME_DATA,
datasource_names_data.names.size());
layout_ptr->SetBlockSize<std::size_t>(DataLayout::DATASOURCE_NAME_OFFSETS,
datasource_names_data.offsets.size());
layout_ptr->SetBlockSize<std::size_t>(DataLayout::DATASOURCE_NAME_LENGTHS,
datasource_names_data.lengths.size());
} }
const io::DatasourceNamesData datasource_names_data =
io::readDatasourceNames(datasource_names_input_stream);
layout_ptr->SetBlockSize<char>(DataLayout::DATASOURCE_NAME_DATA,
datasource_names_data.names.size());
layout_ptr->SetBlockSize<std::size_t>(DataLayout::DATASOURCE_NAME_OFFSETS,
datasource_names_data.offsets.size());
layout_ptr->SetBlockSize<std::size_t>(DataLayout::DATASOURCE_NAME_LENGTHS,
datasource_names_data.lengths.size());
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))
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;
if (!util::deserializeVector(intersection_stream, bearing_class_id_table))
throw util::exception("Failed to bearing class ids read from " +
config.names_data_path.string());
layout_ptr->SetBlockSize<BearingClassID>(DataLayout::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));
layout_ptr->SetBlockSize<unsigned>(DataLayout::BEARING_OFFSETS, bearing_blocks);
layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(
DataLayout::BEARING_BLOCKS, bearing_blocks);
std::vector<unsigned> bearing_offsets_data(bearing_blocks);
std::vector<typename util::RangeTable<16, true>::BlockT> bearing_blocks_data(bearing_blocks);
if (bearing_blocks)
{ {
intersection_stream.read(reinterpret_cast<char *>(&bearing_offsets_data[0]), boost::filesystem::ifstream intersection_stream(config.intersection_class_path,
bearing_blocks * sizeof(bearing_offsets_data[0])); 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))
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;
if (!util::deserializeVector(intersection_stream, bearing_class_id_table))
throw util::exception("Failed to bearing class ids read from " +
config.names_data_path.string());
layout_ptr->SetBlockSize<BearingClassID>(DataLayout::BEARING_CLASSID,
bearing_class_id_table.size());
const auto bearing_blocks = io::readElementCount32(intersection_stream);
const auto sum_lengths = io::readElementCount32(intersection_stream);
layout_ptr->SetBlockSize<unsigned>(DataLayout::BEARING_OFFSETS, bearing_blocks);
layout_ptr->SetBlockSize<typename util::RangeTable<16, true>::BlockT>(
DataLayout::BEARING_BLOCKS, bearing_blocks);
// Skip the actual data
boost::iostreams::seek(intersection_stream,
bearing_blocks * sizeof(unsigned) +
bearing_blocks *
sizeof(typename util::RangeTable<16, true>::BlockT),
BOOST_IOS::cur);
const auto num_bearings = io::readElementCount64(intersection_stream);
// Skip over the actual data
boost::iostreams::seek(
intersection_stream, num_bearings * sizeof(DiscreteBearing), BOOST_IOS::cur);
layout_ptr->SetBlockSize<DiscreteBearing>(DataLayout::BEARING_VALUES, num_bearings);
if (!static_cast<bool>(intersection_stream))
throw util::exception("Failed to read bearing values from " +
config.intersection_class_path.string());
std::vector<util::guidance::EntryClass> entry_class_table;
if (!util::deserializeVector(intersection_stream, entry_class_table))
throw util::exception("Failed to read entry classes from " +
config.intersection_class_path.string());
layout_ptr->SetBlockSize<util::guidance::EntryClass>(DataLayout::ENTRY_CLASS,
entry_class_table.size());
} }
if (bearing_blocks)
{ {
intersection_stream.read(reinterpret_cast<char *>(&bearing_blocks_data[0]), // Loading turn lane data
bearing_blocks * sizeof(bearing_blocks_data[0])); boost::filesystem::ifstream lane_data_stream(config.turn_lane_data_path, std::ios::binary);
const auto lane_tupel_count = io::readElementCount64(lane_data_stream);
layout_ptr->SetBlockSize<util::guidance::LaneTupleIdPair>(DataLayout::TURN_LANE_DATA,
lane_tupel_count);
} }
std::uint64_t num_bearings;
intersection_stream.read(reinterpret_cast<char *>(&num_bearings), sizeof(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);
layout_ptr->SetBlockSize<DiscreteBearing>(DataLayout::BEARING_VALUES, num_bearings);
// Loading turn lane data
boost::filesystem::ifstream lane_data_stream(config.turn_lane_data_path, std::ios::binary);
std::uint64_t lane_tupel_count = 0;
lane_data_stream.read(reinterpret_cast<char *>(&lane_tupel_count), sizeof(lane_tupel_count));
layout_ptr->SetBlockSize<util::guidance::LaneTupleIdPair>(DataLayout::TURN_LANE_DATA,
lane_tupel_count);
if (!static_cast<bool>(intersection_stream))
throw util::exception("Failed to read bearing values from " +
config.intersection_class_path.string());
std::vector<util::guidance::EntryClass> entry_class_table;
if (!util::deserializeVector(intersection_stream, entry_class_table))
throw util::exception("Failed to read entry classes from " +
config.intersection_class_path.string());
layout_ptr->SetBlockSize<util::guidance::EntryClass>(DataLayout::ENTRY_CLASS,
entry_class_table.size());
} }
void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr) void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
@ -501,7 +520,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
// read actual data into shared memory object // // read actual data into shared memory object //
// hsgr checksum // Load the HSGR file
{ {
boost::filesystem::ifstream hsgr_input_stream(config.hsgr_data_path, std::ios::binary); boost::filesystem::ifstream hsgr_input_stream(config.hsgr_data_path, std::ios::binary);
auto hsgr_header = io::readHSGRHeader(hsgr_input_stream); auto hsgr_header = io::readHSGRHeader(hsgr_input_stream);
@ -527,9 +546,9 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
hsgr_input_stream.close(); hsgr_input_stream.close();
} }
// ram index file name // store the filename of the on-disk portion of the RTree
{ {
char *file_index_path_ptr = const auto file_index_path_ptr =
layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::FILE_INDEX_PATH); layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::FILE_INDEX_PATH);
// make sure we have 0 ending // make sure we have 0 ending
std::fill(file_index_path_ptr, std::fill(file_index_path_ptr,
@ -545,35 +564,33 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
{ {
/* To be replaced by io loading code */ /* To be replaced by io loading code */
boost::filesystem::ifstream name_stream(config.names_data_path, std::ios::binary); boost::filesystem::ifstream name_stream(config.names_data_path, std::ios::binary);
unsigned name_blocks = 0; const auto name_blocks = io::readElementCount32(name_stream);
name_stream.read((char *)&name_blocks, sizeof(unsigned)); const auto number_of_chars = io::readElementCount32(name_stream);
unsigned number_of_chars = 0;
name_stream.read((char *)&number_of_chars, sizeof(unsigned));
/* END to be replaced */ /* END to be replaced */
// Loading street names // Loading street names
unsigned *name_offsets_ptr = const auto name_offsets_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_OFFSETS); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_OFFSETS);
if (layout_ptr->GetBlockSize(DataLayout::NAME_OFFSETS) > 0) if (layout_ptr->GetBlockSize(DataLayout::NAME_OFFSETS) > 0)
{ {
name_stream.read((char *)name_offsets_ptr, name_stream.read(reinterpret_cast<char *>(name_offsets_ptr),
layout_ptr->GetBlockSize(DataLayout::NAME_OFFSETS)); layout_ptr->GetBlockSize(DataLayout::NAME_OFFSETS));
} }
unsigned *name_blocks_ptr = const auto name_blocks_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_BLOCKS); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_BLOCKS);
if (layout_ptr->GetBlockSize(DataLayout::NAME_BLOCKS) > 0) if (layout_ptr->GetBlockSize(DataLayout::NAME_BLOCKS) > 0)
{ {
name_stream.read((char *)name_blocks_ptr, name_stream.read(reinterpret_cast<char *>(name_blocks_ptr),
layout_ptr->GetBlockSize(DataLayout::NAME_BLOCKS)); layout_ptr->GetBlockSize(DataLayout::NAME_BLOCKS));
} }
char *name_char_ptr = const auto name_char_ptr =
layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::NAME_CHAR_LIST); layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::NAME_CHAR_LIST);
unsigned temp_length = 0;
name_stream.read((char *)&temp_length, sizeof(unsigned));
BOOST_ASSERT_MSG(layout_ptr->AlignBlockSize(temp_length) == const auto name_char_list_count = io::readElementCount32(name_stream);
BOOST_ASSERT_MSG(layout_ptr->AlignBlockSize(name_char_list_count) ==
layout_ptr->GetBlockSize(DataLayout::NAME_CHAR_LIST), layout_ptr->GetBlockSize(DataLayout::NAME_CHAR_LIST),
"Name file corrupted!"); "Name file corrupted!");
@ -587,20 +604,19 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
{ {
/* NOTE: file io - refactor this in the future */ /* NOTE: file io - refactor this in the future */
boost::filesystem::ifstream lane_data_stream(config.turn_lane_data_path, std::ios::binary); boost::filesystem::ifstream lane_data_stream(config.turn_lane_data_path, std::ios::binary);
std::uint64_t lane_tupel_count = 0; const auto lane_tupel_count = io::readElementCount64(lane_data_stream);
lane_data_stream.read(reinterpret_cast<char *>(&lane_tupel_count),
sizeof(lane_tupel_count));
/* END NOTE */ /* END NOTE */
// make sure do write canary... // Need to call GetBlockPtr -> it write the memory canary, even if no data needs to be
auto *turn_lane_data_ptr = layout_ptr->GetBlockPtr<util::guidance::LaneTupleIdPair, true>( // loaded.
memory_ptr, DataLayout::TURN_LANE_DATA); const auto turn_lane_data_ptr =
layout_ptr->GetBlockPtr<util::guidance::LaneTupleIdPair, true>(
memory_ptr, DataLayout::TURN_LANE_DATA);
if (layout_ptr->GetBlockSize(DataLayout::TURN_LANE_DATA) > 0) if (layout_ptr->GetBlockSize(DataLayout::TURN_LANE_DATA) > 0)
{ {
lane_data_stream.read(reinterpret_cast<char *>(turn_lane_data_ptr), lane_data_stream.read(reinterpret_cast<char *>(turn_lane_data_ptr),
layout_ptr->GetBlockSize(DataLayout::TURN_LANE_DATA)); layout_ptr->GetBlockSize(DataLayout::TURN_LANE_DATA));
} }
lane_data_stream.close();
} }
// Turn lane descriptions // Turn lane descriptions
@ -614,7 +630,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
throw util::exception("Failed to read lane descriptions from: " + throw util::exception("Failed to read lane descriptions from: " +
config.turn_lane_description_path.string()); config.turn_lane_description_path.string());
/* END NOTE */ /* END NOTE */
auto *turn_lane_offset_ptr = layout_ptr->GetBlockPtr<std::uint32_t, true>( const auto turn_lane_offset_ptr = layout_ptr->GetBlockPtr<std::uint32_t, true>(
memory_ptr, DataLayout::LANE_DESCRIPTION_OFFSETS); memory_ptr, DataLayout::LANE_DESCRIPTION_OFFSETS);
if (!lane_description_offsets.empty()) if (!lane_description_offsets.empty())
{ {
@ -623,11 +639,9 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
std::copy(lane_description_offsets.begin(), std::copy(lane_description_offsets.begin(),
lane_description_offsets.end(), lane_description_offsets.end(),
turn_lane_offset_ptr); turn_lane_offset_ptr);
std::vector<std::uint32_t> tmp;
lane_description_offsets.swap(tmp);
} }
auto *turn_lane_mask_ptr = const auto turn_lane_mask_ptr =
layout_ptr->GetBlockPtr<extractor::guidance::TurnLaneType::Mask, true>( layout_ptr->GetBlockPtr<extractor::guidance::TurnLaneType::Mask, true>(
memory_ptr, DataLayout::LANE_DESCRIPTION_MASKS); memory_ptr, DataLayout::LANE_DESCRIPTION_MASKS);
if (!lane_description_masks.empty()) if (!lane_description_masks.empty())
@ -636,8 +650,6 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
sizeof(lane_description_masks[0]) * lane_description_masks.size()); sizeof(lane_description_masks[0]) * lane_description_masks.size());
std::copy( std::copy(
lane_description_masks.begin(), lane_description_masks.end(), turn_lane_mask_ptr); lane_description_masks.begin(), lane_description_masks.end(), turn_lane_mask_ptr);
std::vector<extractor::guidance::TurnLaneType::Mask> tmp;
lane_description_masks.swap(tmp);
} }
} }
@ -651,33 +663,32 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
" for reading."); " for reading.");
} }
const auto number_of_original_edges = io::readElementCount(edges_input_stream); const auto number_of_original_edges = io::readElementCount64(edges_input_stream);
/* END NOTE */ /* END NOTE */
GeometryID *via_geometry_ptr = const auto via_geometry_ptr =
layout_ptr->GetBlockPtr<GeometryID, true>(memory_ptr, DataLayout::VIA_NODE_LIST); layout_ptr->GetBlockPtr<GeometryID, true>(memory_ptr, DataLayout::VIA_NODE_LIST);
unsigned *name_id_ptr = const auto name_id_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_ID_LIST); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::NAME_ID_LIST);
extractor::TravelMode *travel_mode_ptr = const auto travel_mode_ptr = layout_ptr->GetBlockPtr<extractor::TravelMode, true>(
layout_ptr->GetBlockPtr<extractor::TravelMode, true>(memory_ptr, memory_ptr, DataLayout::TRAVEL_MODE);
DataLayout::TRAVEL_MODE); const auto pre_turn_bearing_ptr =
util::guidance::TurnBearing *pre_turn_bearing_ptr =
layout_ptr->GetBlockPtr<util::guidance::TurnBearing, true>( layout_ptr->GetBlockPtr<util::guidance::TurnBearing, true>(
memory_ptr, DataLayout::PRE_TURN_BEARING); memory_ptr, DataLayout::PRE_TURN_BEARING);
util::guidance::TurnBearing *post_turn_bearing_ptr = const auto post_turn_bearing_ptr =
layout_ptr->GetBlockPtr<util::guidance::TurnBearing, true>( layout_ptr->GetBlockPtr<util::guidance::TurnBearing, true>(
memory_ptr, DataLayout::POST_TURN_BEARING); memory_ptr, DataLayout::POST_TURN_BEARING);
LaneDataID *lane_data_id_ptr = const auto lane_data_id_ptr =
layout_ptr->GetBlockPtr<LaneDataID, true>(memory_ptr, DataLayout::LANE_DATA_ID); layout_ptr->GetBlockPtr<LaneDataID, true>(memory_ptr, DataLayout::LANE_DATA_ID);
extractor::guidance::TurnInstruction *turn_instructions_ptr = const auto turn_instructions_ptr =
layout_ptr->GetBlockPtr<extractor::guidance::TurnInstruction, true>( layout_ptr->GetBlockPtr<extractor::guidance::TurnInstruction, true>(
memory_ptr, DataLayout::TURN_INSTRUCTION); memory_ptr, DataLayout::TURN_INSTRUCTION);
EntryClassID *entry_class_id_ptr = const auto entry_class_id_ptr =
layout_ptr->GetBlockPtr<EntryClassID, true>(memory_ptr, DataLayout::ENTRY_CLASSID); layout_ptr->GetBlockPtr<EntryClassID, true>(memory_ptr, DataLayout::ENTRY_CLASSID);
io::readEdges(edges_input_stream, io::readEdges(edges_input_stream,
@ -698,51 +709,50 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
boost::filesystem::ifstream geometry_input_stream(config.geometries_path, std::ios::binary); boost::filesystem::ifstream geometry_input_stream(config.geometries_path, std::ios::binary);
/* END NOTE */ /* END NOTE */
unsigned temporary_value; const auto geometry_index_count = io::readElementCount32(geometry_input_stream);
unsigned *geometries_index_ptr = const auto geometries_index_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::GEOMETRIES_INDEX); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::GEOMETRIES_INDEX);
geometry_input_stream.seekg(0, geometry_input_stream.beg); BOOST_ASSERT(geometry_index_count == layout_ptr->num_entries[DataLayout::GEOMETRIES_INDEX]);
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned));
BOOST_ASSERT(temporary_value == layout_ptr->num_entries[DataLayout::GEOMETRIES_INDEX]);
if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_INDEX) > 0) if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_INDEX) > 0)
{ {
geometry_input_stream.read((char *)geometries_index_ptr, geometry_input_stream.read(reinterpret_cast<char *>(geometries_index_ptr),
layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_INDEX)); layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_INDEX));
} }
NodeID *geometries_node_id_list_ptr = const auto geometries_node_id_list_ptr =
layout_ptr->GetBlockPtr<NodeID, true>(memory_ptr, DataLayout::GEOMETRIES_NODE_LIST); layout_ptr->GetBlockPtr<NodeID, true>(memory_ptr, DataLayout::GEOMETRIES_NODE_LIST);
geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned)); const auto geometry_node_lists_count = io::readElementCount32(geometry_input_stream);
BOOST_ASSERT(temporary_value == layout_ptr->num_entries[DataLayout::GEOMETRIES_NODE_LIST]); BOOST_ASSERT(geometry_node_lists_count ==
layout_ptr->num_entries[DataLayout::GEOMETRIES_NODE_LIST]);
if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_NODE_LIST) > 0) if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_NODE_LIST) > 0)
{ {
geometry_input_stream.read((char *)geometries_node_id_list_ptr, geometry_input_stream.read(reinterpret_cast<char *>(geometries_node_id_list_ptr),
layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_NODE_LIST)); layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_NODE_LIST));
} }
EdgeWeight *geometries_fwd_weight_list_ptr = layout_ptr->GetBlockPtr<EdgeWeight, true>( const auto geometries_fwd_weight_list_ptr = layout_ptr->GetBlockPtr<EdgeWeight, true>(
memory_ptr, DataLayout::GEOMETRIES_FWD_WEIGHT_LIST); memory_ptr, DataLayout::GEOMETRIES_FWD_WEIGHT_LIST);
BOOST_ASSERT(temporary_value == BOOST_ASSERT(geometry_node_lists_count ==
layout_ptr->num_entries[DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]); layout_ptr->num_entries[DataLayout::GEOMETRIES_FWD_WEIGHT_LIST]);
if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST) > 0) if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST) > 0)
{ {
geometry_input_stream.read( geometry_input_stream.read(
(char *)geometries_fwd_weight_list_ptr, reinterpret_cast<char *>(geometries_fwd_weight_list_ptr),
layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST)); layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_FWD_WEIGHT_LIST));
} }
EdgeWeight *geometries_rev_weight_list_ptr = layout_ptr->GetBlockPtr<EdgeWeight, true>( const auto geometries_rev_weight_list_ptr = layout_ptr->GetBlockPtr<EdgeWeight, true>(
memory_ptr, DataLayout::GEOMETRIES_REV_WEIGHT_LIST); memory_ptr, DataLayout::GEOMETRIES_REV_WEIGHT_LIST);
BOOST_ASSERT(temporary_value == BOOST_ASSERT(geometry_node_lists_count ==
layout_ptr->num_entries[DataLayout::GEOMETRIES_REV_WEIGHT_LIST]); layout_ptr->num_entries[DataLayout::GEOMETRIES_REV_WEIGHT_LIST]);
if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_REV_WEIGHT_LIST) > 0) if (layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_REV_WEIGHT_LIST) > 0)
{ {
geometry_input_stream.read( geometry_input_stream.read(
(char *)geometries_rev_weight_list_ptr, reinterpret_cast<char *>(geometries_rev_weight_list_ptr),
layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_REV_WEIGHT_LIST)); layout_ptr->GetBlockSize(DataLayout::GEOMETRIES_REV_WEIGHT_LIST));
} }
} }
@ -755,11 +765,11 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
throw util::exception("Could not open " + config.datasource_indexes_path.string() + throw util::exception("Could not open " + config.datasource_indexes_path.string() +
" for reading."); " for reading.");
} }
auto number_of_compressed_datasources = const auto number_of_compressed_datasources =
io::readElementCount(geometry_datasource_input_stream); io::readElementCount64(geometry_datasource_input_stream);
// load datasource information (if it exists) // load datasource information (if it exists)
auto datasources_list_ptr = const auto datasources_list_ptr =
layout_ptr->GetBlockPtr<uint8_t, true>(memory_ptr, DataLayout::DATASOURCES_LIST); layout_ptr->GetBlockPtr<uint8_t, true>(memory_ptr, DataLayout::DATASOURCES_LIST);
if (number_of_compressed_datasources > 0) if (number_of_compressed_datasources > 0)
{ {
@ -779,11 +789,10 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
" for reading."); " for reading.");
} }
const io::DatasourceNamesData datasource_names_data = const auto datasource_names_data = io::readDatasourceNames(datasource_names_input_stream);
io::readDatasourceNames(datasource_names_input_stream);
// load datasource name information (if it exists) // load datasource name information (if it exists)
auto datasource_name_data_ptr = const auto datasource_name_data_ptr =
layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::DATASOURCE_NAME_DATA); layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::DATASOURCE_NAME_DATA);
if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_DATA) > 0) if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_DATA) > 0)
{ {
@ -792,7 +801,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
datasource_name_data_ptr); datasource_name_data_ptr);
} }
auto datasource_name_offsets_ptr = layout_ptr->GetBlockPtr<std::size_t, true>( const auto datasource_name_offsets_ptr = layout_ptr->GetBlockPtr<std::size_t, true>(
memory_ptr, DataLayout::DATASOURCE_NAME_OFFSETS); memory_ptr, DataLayout::DATASOURCE_NAME_OFFSETS);
if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_OFFSETS) > 0) if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_OFFSETS) > 0)
{ {
@ -801,7 +810,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
datasource_name_offsets_ptr); datasource_name_offsets_ptr);
} }
auto datasource_name_lengths_ptr = layout_ptr->GetBlockPtr<std::size_t, true>( const auto datasource_name_lengths_ptr = layout_ptr->GetBlockPtr<std::size_t, true>(
memory_ptr, DataLayout::DATASOURCE_NAME_LENGTHS); memory_ptr, DataLayout::DATASOURCE_NAME_LENGTHS);
if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_LENGTHS) > 0) if (layout_ptr->GetBlockSize(DataLayout::DATASOURCE_NAME_LENGTHS) > 0)
{ {
@ -814,10 +823,10 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
// Loading list of coordinates // Loading list of coordinates
{ {
boost::filesystem::ifstream nodes_input_stream(config.nodes_data_path, std::ios::binary); boost::filesystem::ifstream nodes_input_stream(config.nodes_data_path, std::ios::binary);
io::readElementCount(nodes_input_stream); io::readElementCount64(nodes_input_stream);
util::Coordinate *coordinates_ptr = layout_ptr->GetBlockPtr<util::Coordinate, true>( const auto coordinates_ptr = layout_ptr->GetBlockPtr<util::Coordinate, true>(
memory_ptr, DataLayout::COORDINATE_LIST); memory_ptr, DataLayout::COORDINATE_LIST);
std::uint64_t *osmnodeid_ptr = const auto osmnodeid_ptr =
layout_ptr->GetBlockPtr<std::uint64_t, true>(memory_ptr, DataLayout::OSM_NODE_ID_LIST); layout_ptr->GetBlockPtr<std::uint64_t, true>(memory_ptr, DataLayout::OSM_NODE_ID_LIST);
util::PackedVector<OSMNodeID, true> osmnodeid_list; util::PackedVector<OSMNodeID, true> osmnodeid_list;
@ -836,7 +845,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
const auto timestamp_size = io::readNumberOfBytes(timestamp_stream); const auto timestamp_size = io::readNumberOfBytes(timestamp_stream);
/* END NOTE */ /* END NOTE */
char *timestamp_ptr = const auto timestamp_ptr =
layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::TIMESTAMP); layout_ptr->GetBlockPtr<char, true>(memory_ptr, DataLayout::TIMESTAMP);
io::readTimestamp(timestamp_stream, timestamp_ptr, timestamp_size); io::readTimestamp(timestamp_stream, timestamp_ptr, timestamp_size);
} }
@ -844,8 +853,10 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
// store search tree portion of rtree // store search tree portion of rtree
{ {
boost::filesystem::ifstream tree_node_file(config.ram_index_path, std::ios::binary); boost::filesystem::ifstream tree_node_file(config.ram_index_path, std::ios::binary);
io::readElementCount(tree_node_file); // perform this read so that we're at the right stream position for the next
auto rtree_ptr = // read.
io::readElementCount64(tree_node_file);
const auto rtree_ptr =
layout_ptr->GetBlockPtr<RTreeNode, true>(memory_ptr, DataLayout::R_SEARCH_TREE); layout_ptr->GetBlockPtr<RTreeNode, true>(memory_ptr, DataLayout::R_SEARCH_TREE);
io::readRamIndex( io::readRamIndex(
tree_node_file, rtree_ptr, layout_ptr->num_entries[DataLayout::R_SEARCH_TREE]); tree_node_file, rtree_ptr, layout_ptr->num_entries[DataLayout::R_SEARCH_TREE]);
@ -860,16 +871,15 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
" for reading."); " for reading.");
} }
std::uint32_t number_of_core_markers = 0; const auto number_of_core_markers = io::readElementCount32(core_marker_file);
core_marker_file.read((char *)&number_of_core_markers, sizeof(uint32_t));
/* END NOTE */ /* END NOTE */
// load core markers // load core markers
std::vector<char> unpacked_core_markers(number_of_core_markers); std::vector<char> unpacked_core_markers(number_of_core_markers);
core_marker_file.read((char *)unpacked_core_markers.data(), core_marker_file.read(reinterpret_cast<char *>(unpacked_core_markers.data()),
sizeof(char) * number_of_core_markers); sizeof(char) * number_of_core_markers);
unsigned *core_marker_ptr = const auto core_marker_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::CORE_MARKER); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::CORE_MARKER);
for (auto i = 0u; i < number_of_core_markers; ++i) for (auto i = 0u; i < number_of_core_markers; ++i)
@ -902,8 +912,9 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
util::exception("Could not open " + config.properties_path.string() + " for reading!"); util::exception("Could not open " + config.properties_path.string() + " for reading!");
} }
io::readPropertiesCount(); io::readPropertiesCount();
auto profile_properties_ptr = layout_ptr->GetBlockPtr<extractor::ProfileProperties, true>( const auto profile_properties_ptr =
memory_ptr, DataLayout::PROPERTIES); layout_ptr->GetBlockPtr<extractor::ProfileProperties, true>(memory_ptr,
DataLayout::PROPERTIES);
io::readProperties(profile_properties_stream, io::readProperties(profile_properties_stream,
profile_properties_ptr, profile_properties_ptr,
sizeof(extractor::ProfileProperties)); sizeof(extractor::ProfileProperties));
@ -926,10 +937,8 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
throw util::exception("Failed to bearing class ids read from " + throw util::exception("Failed to bearing class ids read from " +
config.names_data_path.string()); config.names_data_path.string());
unsigned bearing_blocks = 0; const auto bearing_blocks = io::readElementCount32(intersection_stream);
intersection_stream.read((char *)&bearing_blocks, sizeof(unsigned)); const auto sum_lengths = io::readElementCount32(intersection_stream);
unsigned sum_lengths = 0;
intersection_stream.read((char *)&sum_lengths, sizeof(unsigned));
std::vector<unsigned> bearing_offsets_data(bearing_blocks); std::vector<unsigned> bearing_offsets_data(bearing_blocks);
std::vector<typename util::RangeTable<16, true>::BlockT> bearing_blocks_data( std::vector<typename util::RangeTable<16, true>::BlockT> bearing_blocks_data(
@ -937,22 +946,23 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
if (bearing_blocks) if (bearing_blocks)
{ {
intersection_stream.read(reinterpret_cast<char *>(&bearing_offsets_data[0]), intersection_stream.read(reinterpret_cast<char *>(bearing_offsets_data.data()),
bearing_blocks * sizeof(bearing_offsets_data[0])); bearing_blocks *
sizeof(decltype(bearing_offsets_data)::value_type));
} }
if (bearing_blocks) if (bearing_blocks)
{ {
intersection_stream.read(reinterpret_cast<char *>(&bearing_blocks_data[0]), intersection_stream.read(reinterpret_cast<char *>(bearing_blocks_data.data()),
bearing_blocks * sizeof(bearing_blocks_data[0])); bearing_blocks *
sizeof(decltype(bearing_blocks_data)::value_type));
} }
std::uint64_t num_bearings; const auto num_bearings = io::readElementCount64(intersection_stream);
intersection_stream.read(reinterpret_cast<char *>(&num_bearings), sizeof(num_bearings));
std::vector<DiscreteBearing> bearing_class_table(num_bearings); std::vector<DiscreteBearing> bearing_class_table(num_bearings);
intersection_stream.read(reinterpret_cast<char *>(&bearing_class_table[0]), intersection_stream.read(reinterpret_cast<char *>(bearing_class_table.data()),
sizeof(bearing_class_table[0]) * num_bearings); sizeof(decltype(bearing_class_table)::value_type) * num_bearings);
std::vector<util::guidance::EntryClass> entry_class_table; std::vector<util::guidance::EntryClass> entry_class_table;
if (!util::deserializeVector(intersection_stream, entry_class_table)) if (!util::deserializeVector(intersection_stream, entry_class_table))
@ -962,14 +972,14 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
// load intersection classes // load intersection classes
if (!bearing_class_id_table.empty()) if (!bearing_class_id_table.empty())
{ {
auto bearing_id_ptr = layout_ptr->GetBlockPtr<BearingClassID, true>( const auto bearing_id_ptr = layout_ptr->GetBlockPtr<BearingClassID, true>(
memory_ptr, DataLayout::BEARING_CLASSID); memory_ptr, DataLayout::BEARING_CLASSID);
std::copy(bearing_class_id_table.begin(), bearing_class_id_table.end(), bearing_id_ptr); std::copy(bearing_class_id_table.begin(), bearing_class_id_table.end(), bearing_id_ptr);
} }
if (layout_ptr->GetBlockSize(DataLayout::BEARING_OFFSETS) > 0) if (layout_ptr->GetBlockSize(DataLayout::BEARING_OFFSETS) > 0)
{ {
auto *bearing_offsets_ptr = const auto bearing_offsets_ptr =
layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::BEARING_OFFSETS); layout_ptr->GetBlockPtr<unsigned, true>(memory_ptr, DataLayout::BEARING_OFFSETS);
std::copy( std::copy(
bearing_offsets_data.begin(), bearing_offsets_data.end(), bearing_offsets_ptr); bearing_offsets_data.begin(), bearing_offsets_data.end(), bearing_offsets_ptr);
@ -977,7 +987,7 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
if (layout_ptr->GetBlockSize(DataLayout::BEARING_BLOCKS) > 0) if (layout_ptr->GetBlockSize(DataLayout::BEARING_BLOCKS) > 0)
{ {
auto *bearing_blocks_ptr = const auto bearing_blocks_ptr =
layout_ptr->GetBlockPtr<typename util::RangeTable<16, true>::BlockT, true>( layout_ptr->GetBlockPtr<typename util::RangeTable<16, true>::BlockT, true>(
memory_ptr, DataLayout::BEARING_BLOCKS); memory_ptr, DataLayout::BEARING_BLOCKS);
std::copy(bearing_blocks_data.begin(), bearing_blocks_data.end(), bearing_blocks_ptr); std::copy(bearing_blocks_data.begin(), bearing_blocks_data.end(), bearing_blocks_ptr);
@ -985,14 +995,14 @@ void Storage::LoadData(DataLayout *layout_ptr, char *memory_ptr)
if (!bearing_class_table.empty()) if (!bearing_class_table.empty())
{ {
auto bearing_class_ptr = layout_ptr->GetBlockPtr<DiscreteBearing, true>( const auto bearing_class_ptr = layout_ptr->GetBlockPtr<DiscreteBearing, true>(
memory_ptr, DataLayout::BEARING_VALUES); memory_ptr, DataLayout::BEARING_VALUES);
std::copy(bearing_class_table.begin(), bearing_class_table.end(), bearing_class_ptr); std::copy(bearing_class_table.begin(), bearing_class_table.end(), bearing_class_ptr);
} }
if (!entry_class_table.empty()) if (!entry_class_table.empty())
{ {
auto entry_class_ptr = layout_ptr->GetBlockPtr<util::guidance::EntryClass, true>( const auto entry_class_ptr = layout_ptr->GetBlockPtr<util::guidance::EntryClass, true>(
memory_ptr, DataLayout::ENTRY_CLASS); memory_ptr, DataLayout::ENTRY_CLASS);
std::copy(entry_class_table.begin(), entry_class_table.end(), entry_class_ptr); std::copy(entry_class_table.begin(), entry_class_table.end(), entry_class_ptr);
} }