Skip to content

Commit

Permalink
Include the names of datasources in the vector tile outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat authored and TheMarex committed Mar 15, 2016
1 parent 76f899d commit e8c737d
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 31 deletions.
2 changes: 2 additions & 0 deletions include/contractor/contractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Contractor
const std::vector<std::string> &segment_speed_path,
const std::string &nodes_filename,
const std::string &geometry_filename,
const std::string &datasource_names_filename,
const std::string &datasource_indexes_filename,
const std::string &rtree_leaf_filename);
};
}
Expand Down
7 changes: 4 additions & 3 deletions include/contractor/contractor_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct ContractorConfig
node_based_graph_path = osrm_input_path.string() + ".nodes";
geometry_path = osrm_input_path.string() + ".geometry";
rtree_leaf_path = osrm_input_path.string() + ".fileIndex";
datasource_names_path = osrm_input_path.string() + ".datasource_names";
datasource_indexes_path = osrm_input_path.string() + ".datasource_indexes";
}

boost::filesystem::path config_file_path;
Expand All @@ -79,10 +81,9 @@ struct ContractorConfig
double core_factor;

std::vector<std::string> segment_speed_lookup_paths;
std::string datasource_indexes_path;
std::string datasource_names_path;

#ifdef DEBUG_GEOMETRY
std::string debug_geometry_path;
#endif
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion include/engine/datafacade/datafacade_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ class BaseDataFacade

// Returns the data source ids that were used to supply the edge
// weights. Will return an empty array when only the base profile is used.
virtual void GetUncompressedDatasources(const EdgeID,
virtual void GetUncompressedDatasources(const EdgeID id,
std::vector<uint8_t> &data_sources) const = 0;

// Gets the name of a datasource
virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const = 0;

virtual extractor::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const unsigned id) const = 0;

Expand Down
40 changes: 37 additions & 3 deletions include/engine/datafacade/internal_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class InternalDataFacade final : public BaseDataFacade
util::ShM<bool, false>::vector m_is_core_node;
util::ShM<unsigned, false>::vector m_segment_weights;
util::ShM<uint8_t, false>::vector m_datasource_list;
util::ShM<std::string, false>::vector m_datasource_names;

boost::thread_specific_ptr<InternalRTree> m_static_rtree;
boost::thread_specific_ptr<InternalGeospatialQuery> m_geospatial_query;
Expand Down Expand Up @@ -221,20 +222,33 @@ class InternalDataFacade final : public BaseDataFacade
number_of_compressed_geometries *
sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
}
}


std::ifstream datasources_stream((geometry_file.string() + ".sources").c_str(), std::ios::binary);
void LoadDatasourceInfo(const boost::filesystem::path &datasource_names_file,
const boost::filesystem::path &datasource_indexes_file)
{
std::ifstream datasources_stream(datasource_indexes_file.c_str(), std::ios::binary);
if (datasources_stream)
{
size_t number_of_datasources = 0;
datasources_stream.read(reinterpret_cast<char *>(&number_of_datasources), sizeof(size_t));
if (number_of_compressed_geometries > 0)
if (number_of_datasources > 0)
{
m_datasource_list.resize(number_of_datasources);
datasources_stream.read(reinterpret_cast<char *>(&(m_datasource_list[0])),
number_of_datasources * sizeof(uint8_t));
}
}

std::ifstream datasourcenames_stream(datasource_names_file.c_str(), std::ios::binary);
if (datasourcenames_stream)
{
std::string name;
while (std::getline(datasourcenames_stream, name))
{
m_datasource_names.push_back(name);
}
}
}

void LoadRTree()
Expand Down Expand Up @@ -284,6 +298,14 @@ class InternalDataFacade final : public BaseDataFacade
return it->second;
};

const auto optional_file_for = [&server_paths, &end_it](const std::string &path)
{
const auto it = server_paths.find(path);
if (it == end_it)
throw util::exception("no valid " + path + " file given in ini file");
return it->second;
};

ram_index_path = file_for("ramindex");
file_index_path = file_for("fileindex");

Expand All @@ -299,6 +321,9 @@ class InternalDataFacade final : public BaseDataFacade
util::SimpleLogger().Write() << "loading geometries";
LoadGeometries(file_for("geometries"));

util::SimpleLogger().Write() << "loading datasource info";
LoadDatasourceInfo(optional_file_for("datasource_names"), optional_file_for("datasource_indexes"));

util::SimpleLogger().Write() << "loading timestamp";
LoadTimestamp(file_for("timestamp"));

Expand Down Expand Up @@ -636,6 +661,15 @@ class InternalDataFacade final : public BaseDataFacade
}
}

virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final
{
if (datasource_name_id > m_datasource_names.size())
{
return "lua profile";
}
return m_datasource_names[datasource_name_id];
}

std::string GetTimestamp() const override final { return m_timestamp; }
};
}
Expand Down
44 changes: 44 additions & 0 deletions include/engine/datafacade/shared_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class SharedDataFacade final : public BaseDataFacade
util::ShM<bool, true>::vector m_is_core_node;
util::ShM<uint8_t, true>::vector m_datasource_list;

util::ShM<char, true>::vector m_datasource_name_data;
util::ShM<size_t, true>::vector m_datasource_name_offsets;
util::ShM<size_t, true>::vector m_datasource_name_lengths;

boost::thread_specific_ptr<std::pair<unsigned, std::shared_ptr<SharedRTree>>> m_static_rtree;
boost::thread_specific_ptr<SharedGeospatialQuery> m_geospatial_query;
boost::filesystem::path file_index_path;
Expand Down Expand Up @@ -240,6 +244,30 @@ class SharedDataFacade final : public BaseDataFacade
datasources_list(datasources_list_ptr,
data_layout->num_entries[storage::SharedDataLayout::DATASOURCES_LIST]);
m_datasource_list = std::move(datasources_list);

auto datasource_name_data_ptr =
data_layout->GetBlockPtr<char>(
shared_memory, storage::SharedDataLayout::DATASOURCE_NAME_DATA);
typename util::ShM<char, true>::vector
datasource_name_data(datasource_name_data_ptr,
data_layout->num_entries[storage::SharedDataLayout::DATASOURCE_NAME_DATA]);
m_datasource_name_data = std::move(datasource_name_data);

auto datasource_name_offsets_ptr =
data_layout->GetBlockPtr<size_t>(
shared_memory, storage::SharedDataLayout::DATASOURCE_NAME_OFFSETS);
typename util::ShM<size_t, true>::vector
datasource_name_offsets(datasource_name_offsets_ptr,
data_layout->num_entries[storage::SharedDataLayout::DATASOURCE_NAME_OFFSETS]);
m_datasource_name_offsets = std::move(datasource_name_offsets);

auto datasource_name_lengths_ptr =
data_layout->GetBlockPtr<size_t>(
shared_memory, storage::SharedDataLayout::DATASOURCE_NAME_LENGTHS);
typename util::ShM<size_t, true>::vector
datasource_name_lengths(datasource_name_lengths_ptr,
data_layout->num_entries[storage::SharedDataLayout::DATASOURCE_NAME_LENGTHS]);
m_datasource_name_lengths = std::move(datasource_name_lengths);
}

public:
Expand Down Expand Up @@ -670,6 +698,22 @@ class SharedDataFacade final : public BaseDataFacade
}
}

virtual std::string GetDatasourceName(const uint8_t datasource_name_id) const override final
{
std::string result;

if (datasource_name_id > m_datasource_name_offsets.size())
{
return "lua profile";
}

std::copy(m_datasource_name_data.begin() + m_datasource_name_offsets[datasource_name_id],
m_datasource_name_data.begin() + m_datasource_name_offsets[datasource_name_id] + m_datasource_name_lengths[datasource_name_id],
std::back_inserter(result));

return result;
}

std::string GetTimestamp() const override final { return m_timestamp; }
};
}
Expand Down
2 changes: 2 additions & 0 deletions include/engine/engine_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct EngineConfig
{"coredata", base.string() + ".core"},
{"geometries", base.string() + ".geometry"},
{"timestamp", base.string() + ".timestamp"},
{"datasource_names", base.string() + ".datasource_names"},
{"datasource_indexes", base.string() + ".datasource_indexes"},
{"namesdata", base.string() + ".names"}}
{
}
Expand Down
9 changes: 0 additions & 9 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,11 @@ class EdgeBasedGraphFactory
void CompressGeometry();
unsigned RenumberEdges();
void GenerateEdgeExpandedNodes();
#ifdef DEBUG_GEOMETRY
void GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename,
lua_State *lua_state,
const std::string &edge_segment_lookup_filename,
const std::string &edge_fixed_penalties_filename,
const bool generate_edge_lookup,
const std::string &debug_turns_path);
#else
void GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename,
lua_State *lua_state,
const std::string &edge_segment_lookup_filename,
const std::string &edge_fixed_penalties_filename,
const bool generate_edge_lookup);
#endif

void InsertEdgeBasedNode(const NodeID u, const NodeID v);

Expand Down
4 changes: 2 additions & 2 deletions include/storage/shared_datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ struct SharedDataLayout
CORE_MARKER,
DATASOURCES_LIST,
DATASOURCE_NAME_DATA,
DATASOURCE_NAME_INDEXES,
DATASOURCE_NAME_LENGTHS
DATASOURCE_NAME_OFFSETS,
DATASOURCE_NAME_LENGTHS,
NUM_BLOCKS
};

Expand Down
4 changes: 4 additions & 0 deletions include/util/routed_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ populate_base_path(std::unordered_map<std::string, boost::filesystem::path> &ser
BOOST_ASSERT(server_paths.find("namesdata") != server_paths.end());
server_paths["timestamp"] = base_string + ".timestamp";
BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end());
server_paths["datasource_indexes"] = base_string + ".datasource_indexes";
BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end());
server_paths["datasource_names"] = base_string + ".datasource_names";
BOOST_ASSERT(server_paths.find("timestamp") != server_paths.end());
}

// check if files are give and whether they exist at all
Expand Down
22 changes: 19 additions & 3 deletions src/contractor/contractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ int Contractor::Run()
std::size_t max_edge_id = LoadEdgeExpandedGraph(
config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path,
config.edge_penalty_path, config.segment_speed_lookup_paths, config.node_based_graph_path,
config.geometry_path, config.rtree_leaf_path);
config.geometry_path, config.datasource_names_path, config.datasource_indexes_path,
config.rtree_leaf_path);

// Contracting the edge-expanded graph

Expand Down Expand Up @@ -130,6 +131,8 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
const std::vector<std::string> &segment_speed_filenames,
const std::string &nodes_filename,
const std::string &geometry_filename,
const std::string &datasource_names_filename,
const std::string &datasource_indexes_filename,
const std::string &rtree_leaf_filename)
{
util::SimpleLogger().Write() << "Opening " << edge_based_graph_filename;
Expand Down Expand Up @@ -395,17 +398,30 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
}

{
std::ofstream datasource_stream(geometry_filename + ".sources", std::ios::binary);
std::ofstream datasource_stream(datasource_indexes_filename, std::ios::binary);
if (!datasource_stream)
{
throw util::exception("Failed to open " + geometry_filename + ".sources for writing");
throw util::exception("Failed to open " + datasource_indexes_filename + " for writing");
}
auto number_of_datasource_entries = m_geometry_datasource.size();
datasource_stream.write(reinterpret_cast<const char *>(&number_of_datasource_entries),
sizeof(number_of_datasource_entries));
datasource_stream.write(reinterpret_cast<char *>(&(m_geometry_datasource[0])),
number_of_datasource_entries * sizeof(uint8_t));
}

{
std::ofstream datasource_stream(datasource_names_filename, std::ios::binary);
if (!datasource_stream)
{
throw util::exception("Failed to open " + datasource_names_filename + " for writing");
}
datasource_stream << "lua profile" << std::endl;
for (auto const &name : segment_speed_filenames)
{
datasource_stream << name << std::endl;
}
}
}

// TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily
Expand Down
2 changes: 1 addition & 1 deletion src/engine/plugins/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// Writing field type 4 == variant type
protozero::pbf_writer values_writer(layer_writer, 4);
// Attribute value 1 == string type
values_writer.add_string(1, "datasource " + std::to_string(i));
values_writer.add_string(1, facade.GetDatasourceName(i));
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/extractor/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,7 @@ Extractor::BuildEdgeExpandedGraph(std::vector<QueryNode> &internal_to_external_n

edge_based_graph_factory.Run(config.edge_output_path, lua_state,
config.edge_segment_lookup_path, config.edge_penalty_path,
config.generate_edge_lookup
#ifdef DEBUG_GEOMETRY
,
config.debug_turns_path
#endif
);
config.generate_edge_lookup);

lua_close(lua_state);

Expand Down
Loading

0 comments on commit e8c737d

Please sign in to comment.