BioDynaMo  v1.05.159-3be850bb
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
const T & Get() const
Definition: io.h:68
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
static void Info(const std::string &location, const Args &... parts)
Prints information message.
Definition: log.h:55
static void Warning(const std::string &location, const Args &... parts)
Prints warning message.
Definition: log.h:67
static std::vector< std::function< void()> > after_restore_event_
static const std::string kSimulationName
static const std::string kSimulationStepName
SimulationBackup(const std::string &backup_file, const std::string &restore_file)
static const std::string kRuntimeVariableName
size_t GetSimulationStepsFromBackup() const
Definition: agent.cc:39
bool FileExists(const std::string &file_name)
Definition: io.cc:78
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