Stride Reference Manual  1.0
Hdf5Loader.h
Go to the documentation of this file.
1 #pragma once
2 
8 #ifdef HDF5_USED
9 
10 #include "H5Cpp.h"
11 
12 #endif
13 
14 #include "util/Observer.h"
15 #include "sim/Simulator.h"
16 #include <boost/property_tree/xml_parser.hpp>
17 #include <string>
18 #include <memory>
19 
20 using namespace boost::property_tree;
21 using std::shared_ptr;
22 using std::string;
23 
24 
25 namespace stride {
26 
27 class Hdf5Loader {
28 #ifdef HDF5_USED
29 public:
30  Hdf5Loader(const char* filename);
31 
33  void loadFromTimestep(unsigned int timestep, shared_ptr<Simulator> sim) const;
34 
36  void extendSimulation(shared_ptr<Simulator> sim) const {
37  loadFromTimestep(this->getLastSavedTimestep(), sim);
38  }
39 
40 
41 public:
42  ptree getConfig() const { return m_pt_config; }
43 
44  ptree getDisease() const { return m_pt_disease; }
45 
46  ptree getContact() const { return m_pt_contact; }
47 
49  unsigned int getLastSavedTimestep() const;
50 
51 public:
53  static void extractConfigs(string filename);
54 
55 
56 private:
58  void updateClusterImmuneIndices(shared_ptr<Simulator> sim) const;
59 
61  void loadClusters(H5::H5File& file, string full_dataset_name, std::vector<Cluster>& cluster,
62  shared_ptr<Simulator> sim) const;
63 
65  void loadCalendar(H5::H5File& file, string dataset_name, shared_ptr<Simulator> sim) const;
66 
68  void loadPersonTDData(H5::H5File& file, string dataset_name, shared_ptr<Simulator> sim) const;
69 
71  void loadRngState(H5::H5File& file, string dataset_name, shared_ptr<Simulator> sim) const;
72 
74  void loadTravellers(H5::H5File& file, string dataset_name, shared_ptr<Simulator> sim) const;
75 
77  void loadConfigs();
78 
79 
80 private:
81  const char* m_filename;
82 
83  ptree m_pt_config;
84  ptree m_pt_disease;
85  ptree m_pt_contact;
86 #endif
87 #ifndef HDF5_USED
88  // These dummy headers are used as an interface for when no hdf5 is included, but everything still needs to compile.
89  public:
90  Hdf5Loader(const char* filename) {}
91 
93  void loadFromTimestep(unsigned int timestep, shared_ptr<Simulator> sim) const {}
94 
96  void extendSimulation(shared_ptr<Simulator> sim) const {}
97 
98 
99  public:
100  ptree getConfig() const { ptree result; return result; }
101  ptree getDisease() const { ptree result; return result; }
102  ptree getContact() const { ptree result; return result; }
103 
105  unsigned int getLastSavedTimestep() const { return 0; }
106 
107  public:
109  static void extractConfigs(string filename) {}
110 #endif
111 };
112 
113 }
void extendSimulation(shared_ptr< Simulator > sim) const
Extend the simulation at the last saved timestep.
Definition: Hdf5Loader.h:96
void loadFromTimestep(unsigned int timestep, shared_ptr< Simulator > sim) const
Load from timestep, if the specified timestep is present in the hdf5 file.
Definition: Hdf5Loader.h:93
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
Hdf5Loader(const char *filename)
Definition: Hdf5Loader.h:90
ptree getDisease() const
Definition: Hdf5Loader.h:101
Interface/Implementation of Observer.
static void extractConfigs(string filename)
Extract the configuration files saved in the hdf5 file.
Definition: Hdf5Loader.h:109
Header for the Simulator class.
ptree getConfig() const
Definition: Hdf5Loader.h:100
unsigned int getLastSavedTimestep() const
Retrieves the last saved timestep index in the hdf5 file.
Definition: Hdf5Loader.h:105
ptree getContact() const
Definition: Hdf5Loader.h:102