BioDynaMo  v1.05.120-25dc9790
simulation_backup.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #include "core/simulation_backup.h"
16 
17 namespace bdm {
18 
19 SimulationBackup::SimulationBackup(const std::string& backup_file,
20  const std::string& restore_file)
21  : backup_file(backup_file), restore_file(restore_file) {
22  backup_ = true;
23  if (backup_file == "") {
24  backup_ = false;
25  Log::Info("SimulationBackup",
26  "No backup file name given. No backups will be made!");
27  } else if (backup_file == restore_file) {
29  "SimulationBackup",
30  "Backup file is identical to restore file. Will be overridden after "
31  "restore.");
32  }
33 
34  if (restore_file == "") {
35  restore_ = false;
36  } else if (!FileExists(restore_file)) {
37  Log::Fatal("SimulationBackup",
38  "Given restore file does not exist: ", restore_file);
39  }
40 }
41 
43  if (restore_) {
44  IntegralTypeWrapper<size_t>* wrapper = nullptr;
46  wrapper);
47  if (wrapper != nullptr) {
48  return wrapper->Get();
49  } else {
50  Log::Fatal("SimulationBackup", "Failed to retrieve SimulationSteps.");
51  return 0;
52  }
53  } else {
54  Log::Fatal("SimulationBackup",
55  "Requested to restore data, but no restore file given.");
56  return 0;
57  }
58 }
59 
60 bool SimulationBackup::BackupEnabled() const { return backup_; }
61 
63 
64 const std::string SimulationBackup::kSimulationName = "simulation";
65 const std::string SimulationBackup::kSimulationStepName =
66  "completed_simulation_steps";
67 const std::string SimulationBackup::kRuntimeVariableName = "runtime_variable";
68 
69 std::vector<std::function<void()>> SimulationBackup::after_restore_event_ = {};
70 
71 } // namespace bdm
bdm::SimulationBackup::kRuntimeVariableName
static const std::string kRuntimeVariableName
Definition: simulation_backup.h:38
bdm
Definition: agent.cc:39
bdm::IntegralTypeWrapper
Definition: io.h:64
bdm::SimulationBackup::SimulationBackup
SimulationBackup(const std::string &backup_file, const std::string &restore_file)
Definition: simulation_backup.cc:19
bdm::SimulationBackup::restore_
bool restore_
Definition: simulation_backup.h:119
bdm::GetPersistentObject
bool GetPersistentObject(const char *root_file, const char *obj_name, T *&empty_obj)
Gets the persistent object from the specified ROOT file.
Definition: io.h:101
simulation_backup.h
bdm::IntegralTypeWrapper::Get
const T & Get() const
Definition: io.h:68
bdm::Log::Warning
static void Warning(const std::string &location, const Args &... parts)
Prints warning message.
Definition: log.h:67
bdm::Log::Info
static void Info(const std::string &location, const Args &... parts)
Prints information message.
Definition: log.h:55
bdm::SimulationBackup::GetSimulationStepsFromBackup
size_t GetSimulationStepsFromBackup() const
Definition: simulation_backup.cc:42
bdm::FileExists
bool FileExists(const std::string &file_name)
Definition: io.cc:78
bdm::SimulationBackup::BackupEnabled
bool BackupEnabled() const
Definition: simulation_backup.cc:60
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::SimulationBackup::RestoreEnabled
bool RestoreEnabled() const
Definition: simulation_backup.cc:62
bdm::SimulationBackup::backup_file
std::string backup_file
Definition: simulation_backup.h:120
bdm::SimulationBackup::kSimulationStepName
static const std::string kSimulationStepName
Definition: simulation_backup.h:37
bdm::SimulationBackup::kSimulationName
static const std::string kSimulationName
Definition: simulation_backup.h:36
bdm::SimulationBackup::restore_file
std::string restore_file
Definition: simulation_backup.h:121
bdm::SimulationBackup::backup_
bool backup_
Definition: simulation_backup.h:118
bdm::SimulationBackup::after_restore_event_
static std::vector< std::function< void()> > after_restore_event_
Definition: simulation_backup.h:47