diff --git a/examples/serialized_custom_source/serialized_source_ring.cpp b/examples/serialized_custom_source/serialized_source_ring.cpp index 560a99345..7e19bc579 100644 --- a/examples/serialized_custom_source/serialized_source_ring.cpp +++ b/examples/serialized_custom_source/serialized_source_ring.cpp @@ -23,9 +23,11 @@ class SerialisedSource { // The deserialisation routine populates the constructor from well defined elements // in the input XML document. + // Note that the source will have already been read from file, so what will be passed + // in here is a string-like serialized value (not the path to the serialized value). static SerialisedSource from_xml(char* serialised_source) { pugi::xml_document doc; - doc.load_file(serialised_source); + doc.load_string(serialised_source); pugi::xml_node root_node = doc.root().child("Source"); double radius = root_node.child("Radius").text().as_double(); double energy = root_node.child("Energy").text().as_double(); diff --git a/src/source.cpp b/src/source.cpp index 86dac6b3f..d7bcf726b 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -99,7 +99,13 @@ SourceDistribution::SourceDistribution(pugi::xml_node node) } if (check_for_node(node, "serialization")) { - serialization = get_node_value(node, "serialization", false, true); + // If the source is serialized then make sure we only load it from file once, otherwise there will + // be a significant I/O overhead. + pugi::xml_document doc; + doc.load_file(get_node_value(node, "serialization", false, true).c_str()); + std::stringstream ss; + doc.print(ss); + serialization = ss.str(); } } else {