Check for valid data files. Implements #224
This commit is contained in:
+47
-20
@@ -50,28 +50,31 @@ struct _ExcessRemover {
|
||||
};
|
||||
|
||||
template<typename EdgeT>
|
||||
NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeID> &bollardNodes, std::vector<NodeID> &trafficLightNodes, std::vector<NodeInfo> * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) {
|
||||
NodeID readBinaryOSRMGraphFromStream(
|
||||
std::istream &in,
|
||||
std::vector<EdgeT>& edgeList,
|
||||
std::vector<NodeID> &bollardNodes,
|
||||
std::vector<NodeID> &trafficLightNodes,
|
||||
std::vector<NodeInfo> * int2ExtNodeMap,
|
||||
std::vector<_Restriction> & inputRestrictions
|
||||
) {
|
||||
const UUID uuid_orig;
|
||||
UUID uuid_loaded;
|
||||
in.read((char *) &uuid_loaded, sizeof(UUID));
|
||||
if(!uuid_loaded.IsMagicNumberOK()) {
|
||||
ERR("hsgr input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
|
||||
if( uuid_loaded.TestHSGR(uuid_orig) ) {
|
||||
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
|
||||
WARN(
|
||||
".hsgr was prepared with different build.\n"
|
||||
".osrm was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
NodeID n, source, target;
|
||||
EdgeID m;
|
||||
short dir;// direction (0 = open, 1 = forward, 2+ = open)
|
||||
ExternalNodeMap ext2IntNodeMap;
|
||||
in.read((char*)&n, sizeof(NodeID));
|
||||
DEBUG("Importing n = " << n << " nodes ");
|
||||
INFO("Importing n = " << n << " nodes ");
|
||||
_Node node;
|
||||
for (NodeID i=0; i<n; ++i) {
|
||||
in.read((char*)&node, sizeof(_Node));
|
||||
@@ -88,7 +91,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeL
|
||||
std::vector<NodeID>(trafficLightNodes).swap(trafficLightNodes);
|
||||
|
||||
in.read((char*)&m, sizeof(unsigned));
|
||||
DEBUG(" and " << m << " edges ");
|
||||
INFO(" and " << m << " edges ");
|
||||
for(unsigned i = 0; i < inputRestrictions.size(); ++i) {
|
||||
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode);
|
||||
if( intNodeID == ext2IntNodeMap.end()) {
|
||||
@@ -380,19 +383,43 @@ NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
|
||||
}
|
||||
|
||||
template<typename NodeT, typename EdgeT>
|
||||
unsigned readHSGRFromStream(std::istream &in, std::vector<NodeT>& nodeList, std::vector<EdgeT> & edgeList, unsigned * checkSum) {
|
||||
unsigned numberOfNodes = 0;
|
||||
in.read((char*) checkSum, sizeof(unsigned));
|
||||
in.read((char*) & numberOfNodes, sizeof(unsigned));
|
||||
nodeList.resize(numberOfNodes + 1);
|
||||
in.read((char*) &(nodeList[0]), numberOfNodes*sizeof(NodeT));
|
||||
unsigned readHSGRFromStream(
|
||||
std::istream &hsgr_input_stream,
|
||||
std::vector<NodeT> & node_list,
|
||||
std::vector<EdgeT> & edge_list,
|
||||
unsigned * check_sum
|
||||
) {
|
||||
UUID uuid_loaded, uuid_orig;
|
||||
hsgr_input_stream.read((char *)&uuid_loaded, sizeof(UUID));
|
||||
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
|
||||
WARN(
|
||||
".hsgr was prepared with different build.\n"
|
||||
"Reprocess to get rid of this warning."
|
||||
)
|
||||
}
|
||||
|
||||
unsigned numberOfEdges = 0;
|
||||
in.read((char*) &numberOfEdges, sizeof(unsigned));
|
||||
edgeList.resize(numberOfEdges);
|
||||
in.read((char*) &(edgeList[0]), numberOfEdges*sizeof(EdgeT));
|
||||
unsigned number_of_nodes = 0;
|
||||
hsgr_input_stream.read((char*) check_sum, sizeof(unsigned));
|
||||
hsgr_input_stream.read((char*) & number_of_nodes, sizeof(unsigned));
|
||||
node_list.resize(number_of_nodes + 1);
|
||||
hsgr_input_stream.read(
|
||||
(char*) &(node_list[0]),
|
||||
number_of_nodes*sizeof(NodeT)
|
||||
);
|
||||
|
||||
return numberOfNodes;
|
||||
unsigned number_of_edges = 0;
|
||||
hsgr_input_stream.read(
|
||||
(char*) &number_of_edges,
|
||||
sizeof(unsigned)
|
||||
);
|
||||
|
||||
edge_list.resize(number_of_edges);
|
||||
hsgr_input_stream.read(
|
||||
(char*) &(edge_list[0]),
|
||||
number_of_edges*sizeof(EdgeT)
|
||||
);
|
||||
|
||||
return number_of_nodes;
|
||||
}
|
||||
|
||||
#endif // GRAPHLOADER_H
|
||||
|
||||
+33
-2
@@ -59,6 +59,37 @@ const bool UUID::IsMagicNumberOK() const {
|
||||
return 1297240911 == magic_number;
|
||||
}
|
||||
|
||||
const bool UUID::TestHSGR(const UUID & other) const {
|
||||
const bool UUID::TestGraphUtil(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("hsgr input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_graph, md5_graph+32, other.md5_graph);
|
||||
}
|
||||
}
|
||||
|
||||
const bool UUID::TestPrepare(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("extracted input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_prepare, md5_prepare+32, other.md5_prepare);
|
||||
}
|
||||
|
||||
const bool UUID::TestRTree(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("r-tree input file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_tree, md5_tree+32, other.md5_tree);
|
||||
}
|
||||
|
||||
const bool UUID::TestNodeInfo(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("nodes file misses magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_nodeinfo, md5_nodeinfo+32, other.md5_nodeinfo);
|
||||
}
|
||||
|
||||
const bool UUID::TestQueryObjects(const UUID & other) const {
|
||||
if(!other.IsMagicNumberOK()) {
|
||||
ERR("missing magic number. Check or reprocess the file");
|
||||
}
|
||||
return std::equal(md5_objects, md5_objects+32, other.md5_objects);
|
||||
}
|
||||
|
||||
+7
-1
@@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#ifndef UUID_H
|
||||
#define UUID_H
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/uuid/uuid.hpp> // uuid class
|
||||
#include <boost/uuid/uuid_generators.hpp> // generators
|
||||
@@ -39,7 +41,11 @@ public:
|
||||
~UUID();
|
||||
const boost::uuids::uuid & GetUUID() const;
|
||||
const bool IsMagicNumberOK() const;
|
||||
const bool TestHSGR(const UUID & other) const;
|
||||
const bool TestGraphUtil(const UUID & other) const;
|
||||
const bool TestPrepare(const UUID & other) const;
|
||||
const bool TestRTree(const UUID & other) const;
|
||||
const bool TestNodeInfo(const UUID & other) const;
|
||||
const bool TestQueryObjects(const UUID & other) const;
|
||||
private:
|
||||
const unsigned magic_number;
|
||||
char md5_prepare[33];
|
||||
|
||||
Reference in New Issue
Block a user