deduplicate code for loading profile properties into io.hpp
This commit is contained in:
parent
ceddfada3d
commit
51ebadfc45
@ -123,9 +123,8 @@ class InternalDataFacade final : public BaseDataFacade
|
|||||||
{
|
{
|
||||||
throw util::exception("Could not open " + properties_path.string() + " for reading.");
|
throw util::exception("Could not open " + properties_path.string() + " for reading.");
|
||||||
}
|
}
|
||||||
|
auto PropertiesSize = storage::io::readPropertiesSize();
|
||||||
in_stream.read(reinterpret_cast<char *>(&m_profile_properties),
|
storage::io::readProperties(in_stream, reinterpret_cast<char *>(&m_profile_properties), PropertiesSize);
|
||||||
sizeof(m_profile_properties));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadLaneTupleIdPairs(const boost::filesystem::path &lane_data_path)
|
void LoadLaneTupleIdPairs(const boost::filesystem::path &lane_data_path)
|
||||||
|
@ -15,6 +15,16 @@ namespace storage
|
|||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
|
|
||||||
|
inline std::size_t readPropertiesSize() { return 1; }
|
||||||
|
|
||||||
|
template <typename PropertiesT>
|
||||||
|
inline void readProperties(boost::filesystem::ifstream &properties_stream,
|
||||||
|
PropertiesT properties[],
|
||||||
|
std::size_t PropertiesSize)
|
||||||
|
{
|
||||||
|
properties_stream.read(properties, PropertiesSize);
|
||||||
|
}
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct HSGRHeader
|
struct HSGRHeader
|
||||||
{
|
{
|
||||||
@ -39,8 +49,10 @@ inline HSGRHeader readHSGRHeader(boost::filesystem::ifstream &input_stream)
|
|||||||
|
|
||||||
HSGRHeader header;
|
HSGRHeader header;
|
||||||
input_stream.read(reinterpret_cast<char *>(&header.checksum), sizeof(header.checksum));
|
input_stream.read(reinterpret_cast<char *>(&header.checksum), sizeof(header.checksum));
|
||||||
input_stream.read(reinterpret_cast<char *>(&header.number_of_nodes), sizeof(header.number_of_nodes));
|
input_stream.read(reinterpret_cast<char *>(&header.number_of_nodes),
|
||||||
input_stream.read(reinterpret_cast<char *>(&header.number_of_edges), sizeof(header.number_of_edges));
|
sizeof(header.number_of_nodes));
|
||||||
|
input_stream.read(reinterpret_cast<char *>(&header.number_of_edges),
|
||||||
|
sizeof(header.number_of_edges));
|
||||||
|
|
||||||
BOOST_ASSERT_MSG(0 != header.number_of_nodes, "number of nodes is zero");
|
BOOST_ASSERT_MSG(0 != header.number_of_nodes, "number of nodes is zero");
|
||||||
// number of edges can be zero, this is the case in a few test fixtures
|
// number of edges can be zero, this is the case in a few test fixtures
|
||||||
@ -48,7 +60,7 @@ inline HSGRHeader readHSGRHeader(boost::filesystem::ifstream &input_stream)
|
|||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needs to be called after HSGRHeader() to get the correct offset in the stream
|
// Needs to be called after readHSGRHeader() to get the correct offset in the stream
|
||||||
template <typename NodeT, typename EdgeT>
|
template <typename NodeT, typename EdgeT>
|
||||||
void readHSGR(boost::filesystem::ifstream &input_stream,
|
void readHSGR(boost::filesystem::ifstream &input_stream,
|
||||||
NodeT *node_buffer,
|
NodeT *node_buffer,
|
||||||
@ -59,7 +71,6 @@ void readHSGR(boost::filesystem::ifstream &input_stream,
|
|||||||
input_stream.read(reinterpret_cast<char *>(node_buffer), number_of_nodes * sizeof(NodeT));
|
input_stream.read(reinterpret_cast<char *>(node_buffer), number_of_nodes * sizeof(NodeT));
|
||||||
input_stream.read(reinterpret_cast<char *>(edge_buffer), number_of_edges * sizeof(EdgeT));
|
input_stream.read(reinterpret_cast<char *>(edge_buffer), number_of_edges * sizeof(EdgeT));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the size of the timestamp in a file
|
// Returns the size of the timestamp in a file
|
||||||
inline std::uint32_t readTimestampSize(boost::filesystem::ifstream ×tamp_input_stream)
|
inline std::uint32_t readTimestampSize(boost::filesystem::ifstream ×tamp_input_stream)
|
||||||
{
|
{
|
||||||
|
@ -273,8 +273,10 @@ Storage::ReturnCode Storage::Run(int max_wait)
|
|||||||
tree_node_file.read((char *)&tree_size, sizeof(uint32_t));
|
tree_node_file.read((char *)&tree_size, sizeof(uint32_t));
|
||||||
shared_layout_ptr->SetBlockSize<RTreeNode>(SharedDataLayout::R_SEARCH_TREE, tree_size);
|
shared_layout_ptr->SetBlockSize<RTreeNode>(SharedDataLayout::R_SEARCH_TREE, tree_size);
|
||||||
|
|
||||||
// load profile properties
|
// allocate space in shared memory for profile properties
|
||||||
shared_layout_ptr->SetBlockSize<extractor::ProfileProperties>(SharedDataLayout::PROPERTIES, 1);
|
std::size_t PropertiesSize = io::readPropertiesSize();
|
||||||
|
shared_layout_ptr->SetBlockSize<extractor::ProfileProperties>(SharedDataLayout::PROPERTIES,
|
||||||
|
PropertiesSize);
|
||||||
|
|
||||||
// read timestampsize
|
// read timestampsize
|
||||||
boost::filesystem::ifstream timestamp_stream(config.timestamp_path);
|
boost::filesystem::ifstream timestamp_stream(config.timestamp_path);
|
||||||
@ -760,7 +762,7 @@ Storage::ReturnCode Storage::Run(int max_wait)
|
|||||||
hsgr_input_stream.close();
|
hsgr_input_stream.close();
|
||||||
|
|
||||||
// load profile properties
|
// load profile properties
|
||||||
auto profile_properties_ptr =
|
extractor::ProfileProperties *profile_properties_ptr =
|
||||||
shared_layout_ptr->GetBlockPtr<extractor::ProfileProperties, true>(
|
shared_layout_ptr->GetBlockPtr<extractor::ProfileProperties, true>(
|
||||||
shared_memory_ptr, SharedDataLayout::PROPERTIES);
|
shared_memory_ptr, SharedDataLayout::PROPERTIES);
|
||||||
boost::filesystem::ifstream profile_properties_stream(config.properties_path);
|
boost::filesystem::ifstream profile_properties_stream(config.properties_path);
|
||||||
@ -768,8 +770,9 @@ Storage::ReturnCode Storage::Run(int max_wait)
|
|||||||
{
|
{
|
||||||
util::exception("Could not open " + config.properties_path.string() + " for reading!");
|
util::exception("Could not open " + config.properties_path.string() + " for reading!");
|
||||||
}
|
}
|
||||||
profile_properties_stream.read(reinterpret_cast<char *>(profile_properties_ptr),
|
io::readProperties(profile_properties_stream,
|
||||||
sizeof(extractor::ProfileProperties));
|
reinterpret_cast<char *>(profile_properties_ptr),
|
||||||
|
PropertiesSize);
|
||||||
|
|
||||||
// load intersection classes
|
// load intersection classes
|
||||||
if (!bearing_class_id_table.empty())
|
if (!bearing_class_id_table.empty())
|
||||||
|
Loading…
Reference in New Issue
Block a user