Class to read particle and simulation data from a '.xml' file.
More...
#include <ChkptPointFileReader.h>
|
std::tuple< std::vector< Particle >, int > | readFile (const std::filesystem::path &filepath) const |
| Reads particle data from a '.xml' file and returns a vector of particles. More...
|
|
|
static size_t | calculateHash (const std::filesystem::path &filepath) |
| Calculates the hash for the given input file. More...
|
|
static bool | detectSourceFileChanges (const std::string &filepath) |
| Checks if the given file contains a valid hash generated from the original input file. More...
|
|
Class to read particle and simulation data from a '.xml' file.
Definition at line 10 of file ChkptPointFileReader.h.
◆ calculateHash()
size_t ChkptPointFileReader::calculateHash |
( |
const std::filesystem::path & |
filepath | ) |
|
|
static |
Calculates the hash for the given input file.
- Parameters
-
filepath | Path to the input file to calculate the hash for |
Each CheckPoint saves the hash of the original it was created from. This function calculates the hash of the given file.
Definition at line 43 of file ChkptPointFileReader.cpp.
44 if (!std::filesystem::exists(filepath)) {
45 Logger::logger->warn(
"File '{}' does not exist. Using hash 0.", filepath.string());
49 std::ifstream input_file(filepath);
51 if (!input_file.is_open()) {
52 Logger::logger->error(
"Error: could not open file '{}'.", filepath.string());
56 auto buffer = std::stringstream();
57 buffer << input_file.rdbuf();
59 std::hash<std::string> hasher;
60 auto hash = hasher(buffer.str());
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
◆ detectSourceFileChanges()
bool ChkptPointFileReader::detectSourceFileChanges |
( |
const std::string & |
filepath | ) |
|
|
static |
Checks if the given file contains a valid hash generated from the original input file.
- Parameters
-
filepath | Path of the checkpoint file to check |
Each CheckPoint saves the hash of the original it was created from. This function checks if the original file still hashes to the same value. If not, the CheckPoint is invalid because it refers to a input file which has been changed since the CheckPoint was created.
Definition at line 64 of file ChkptPointFileReader.cpp.
65 auto checkpoint = CheckPoint(filepath, xml_schema::flags::dont_validate);
66 auto meta_data = checkpoint->MetaData();
68 std::ifstream input_file(meta_data.input_file());
70 auto buffer = std::stringstream();
71 buffer << input_file.rdbuf();
73 std::hash<std::string> hasher;
74 auto curr_hash = hasher(buffer.str());
76 bool hash_valid = curr_hash == meta_data.input_file_hash();
79 Logger::logger->warn(
"Source file '{}' has changed since last checkpoint. Original hash: {}, current hash: {}",
80 meta_data.input_file(), meta_data.input_file_hash(), curr_hash);
◆ readFile()
std::tuple< std::vector< Particle >, int > ChkptPointFileReader::readFile |
( |
const std::filesystem::path & |
filepath | ) |
const |
Reads particle data from a '.xml' file and returns a vector of particles.
- Parameters
-
filepath | Path to the file to read |
- Returns
- A tuple containing a vector of particles and the iteration number
Definition at line 19 of file ChkptPointFileReader.cpp.
21 auto checkpoint = CheckPoint(filepath, xml_schema::flags::dont_validate);
23 auto particle_data = checkpoint->ParticleData();
24 auto meta_data = checkpoint->MetaData();
28 std::vector<Particle> particles;
30 for (
auto xsd_particle : particle_data.particle()) {
32 particles.push_back(std::move(particle));
35 return std::make_tuple(particles, meta_data.current_iteration());
36 }
catch (
const xml_schema::exception& e) {
37 std::stringstream error_message;
38 error_message <<
"Error: could not parse file '" << filepath <<
"'.\n";
39 error_message << e << std::endl;
void summarizeMetadata(MetaDataDataType m)
static Particle convertToParticle(const ParticleType &particle)
Converts a particle type from the XSD format to the internal format.
The documentation for this class was generated from the following files: