Stride Reference Manual  1.0
Hdf5Saver.h
Go to the documentation of this file.
1 #pragma once
2 
9 #ifdef HDF5_USED
10 
11 #include "H5Cpp.h"
12 
13 #endif
14 
15 #include "util/Observer.h"
16 #include "sim/Simulator.h"
17 #include "sim/SimulatorRunMode.h"
18 #include "core/Cluster.h"
19 #include <boost/property_tree/xml_parser.hpp>
20 #include <string>
21 #include <vector>
22 
23 using std::vector;
24 using namespace boost::property_tree;
25 using std::string;
26 #ifdef HDF5_USED
27 using H5::H5File;
28 using H5::Group;
29 #endif
30 
31 
32 namespace stride {
33 
34 class Hdf5Saver : public util::Observer<Simulator> {
35 #ifdef HDF5_USED
36 public:
37  Hdf5Saver(string filename, const ptree& pt_config, int frequency,
38  RunMode run_mode = RunMode::Initial, int start_timestep = 0);
39 
41  virtual void update(const Simulator& sim);
42 
44  void forceSave(const Simulator& sim, int timestep = -1);
45 
46 private:
47  void saveTimestep(const Simulator& sim);
48 
50  void saveClusters(Group& group, string dataset_name, const vector<Cluster>& clusters) const;
51 
53  void savePersonTIData(H5File& file, const Simulator& sim) const;
54 
56  void savePersonTDData(Group& group, const Simulator& sim) const;
57 
59  void saveTravellers(Group& group, const Simulator& sim) const;
60 
62  void saveTimestepMetadata(H5File& file, unsigned int total_amt, unsigned int current, bool create = false) const;
63 
65  void saveRngState(Group& group, const Simulator& sim) const;
66 
68  void saveCalendar(Group& group, const Simulator& sim) const;
69 
71  void saveConfigs(H5File& file, const ptree& pt_config) const;
72 
73 private:
74  string m_filename;
75  int m_frequency;
76  int m_current_step;
77  unsigned int m_timestep;
78  unsigned int m_save_count;
79 #endif
80 #ifndef HDF5_USED
81  // These dummy headers are used as an interface for when no hdf5 is included, but everything still needs to compile.
82  public:
83  Hdf5Saver(string filename, const ptree& pt_config, int frequency,
84  RunMode run_mode = RunMode::Initial, int start_timestep = 0) {}
85 
87  virtual void update(const Simulator& sim) {}
88 
90  void forceSave(const Simulator& sim, int timestep = -1) {}
91 #endif
92 };
93 
94 }
Hdf5Saver(string filename, const ptree &pt_config, int frequency, RunMode run_mode=RunMode::Initial, int start_timestep=0)
Definition: Hdf5Saver.h:83
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
Interface/Implementation of Observer.
virtual void update(const Simulator &sim)
Update function which is called by the subject.
Definition: Hdf5Saver.h:87
Header for the Simulator class.
Main class that contains and direct the virtual world.
Definition: Simulator.h:64
Header for the core Cluster class.
void forceSave(const Simulator &sim, int timestep=-1)
Forces a save to the hdf5 file, with an optional timestep argument which specifies a new timestep sav...
Definition: Hdf5Saver.h:90