SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Logger.h
1 
20 #pragma once
21 
22 #include <mxx/comm.hpp>
23 #include <fstream>
24 #include "EventListener.h"
25 
26 // Forward declare.
27 namespace Json {
28  class Value;
29 }
30 
31 namespace SSAGES
32 {
34 
41  class Logger : public EventListener
42  {
43  protected:
44  mxx::comm world_;
45  mxx::comm comm_;
46 
48  std::vector<unsigned int> cvmask_;
49 
51  std::string filename_;
52 
54  std::ofstream log_;
55 
57  bool append_;
58 
59  public:
61 
69  Logger(unsigned int frequency, const std::string& filename, const MPI_Comm& world, const MPI_Comm& comm) :
70  EventListener(frequency), world_(world), comm_(comm), cvmask_(), filename_(filename),
71  append_(false)
72  {}
73 
75 
81  virtual void PreSimulation(Snapshot* snapshot, const class CVManager& cvmanager) override;
82 
84 
90  virtual void PostIntegration(Snapshot* snapshot, const class CVManager& cvmanager) override;
91 
93 
99  virtual void PostSimulation(Snapshot* snapshot, const class CVManager& cvmanager) override;
100 
103  void SetCVMask(const std::vector<unsigned int>& mask)
104  {
105  cvmask_ = mask;
106  }
107 
109 
112  void SetAppend(bool append)
113  {
114  append_ = append;
115  }
116 
118 
127  static Logger* Build(const Json::Value& json,
128  const MPI_Comm& world,
129  const MPI_Comm& comm,
130  const std::string& path);
131 
133  virtual ~Logger()
134  {
135  }
136  };
137 }
Collective variable manager.
Definition: CVManager.h:43
Base abstract class for listening in to events fired by "Hook".
Definition: EventListener.h:36
Base class for logging SSAGES data.
Definition: Logger.h:42
mxx::comm comm_
Local MPI communicator.
Definition: Logger.h:45
std::vector< unsigned int > cvmask_
Mask which identifies which CVs to log.
Definition: Logger.h:48
void SetAppend(bool append)
Set append mode.
Definition: Logger.h:112
void SetCVMask(const std::vector< unsigned int > &mask)
Sets the collective variable mask.
Definition: Logger.h:103
Logger(unsigned int frequency, const std::string &filename, const MPI_Comm &world, const MPI_Comm &comm)
Constructor.
Definition: Logger.h:69
std::ofstream log_
Log file stream.
Definition: Logger.h:54
virtual void PostIntegration(Snapshot *snapshot, const class CVManager &cvmanager) override
Logger call post integration.
Definition: Logger.cpp:55
virtual ~Logger()
Destructor.
Definition: Logger.h:133
virtual void PreSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Logger call prior to simulation initiation.
Definition: Logger.cpp:34
bool append_
Append mode?
Definition: Logger.h:57
mxx::comm world_
Global MPI communicator.
Definition: Logger.h:44
std::string filename_
Name of logfile.
Definition: Logger.h:51
static Logger * Build(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a Logger from JSON node.
Definition: Logger.cpp:75
virtual void PostSimulation(Snapshot *snapshot, const class CVManager &cvmanager) override
Logger call post simulation.
Definition: Logger.cpp:71
Class containing a snapshot of the current simulation in time.
Definition: Snapshot.h:48