11 Logger::logger->info(
"Loaded checkpoint file with following metadata:");
13 Logger::logger->info(
" - Original file hash: {}", m.input_file_hash());
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;
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());
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);
void summarizeMetadata(MetaDataDataType m)
static bool detectSourceFileChanges(const std::string &filepath)
Checks if the given file contains a valid hash generated from the original input file.
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.
static size_t calculateHash(const std::filesystem::path &filepath)
Calculates the hash for the given input file.
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
static Particle convertToParticle(const ParticleType &particle)
Converts a particle type from the XSD format to the internal format.