Path Integral Quantum Monte Carlo
communicator.h
Go to the documentation of this file.
1 
9 #ifndef COMMUNICATOR_H
10 #define COMMUNICATOR_H
11 
12 #include "common.h"
13 #include "constants.h"
14 #include <cstring>
15 #include <fstream>
16 
17 
18 // ========================================================================
19 // File Class
20 // ========================================================================
25 class File
26 {
27  public:
28 
29  File(string, string, string, string);
30  File(string);
31  ~File() {close();}
32 
33  /* Return the file stream */
34  fstream & stream() {
35  return rwfile;
36  }
37 
38  /* Open the primary file */
39  void open(ios_base::openmode);
40 
41  /* Reset and rename the primary file */
42  void reset();
43  void rename();
44 
45  /* Close the file if open */
46  void close();
47 
48  bool exists() {return exists_;}
49 
50  protected:
51  friend class Communicator; // Friends for I/O
52 
53  string name; // The File name
54  string bakname; // The backup name
55 
56  bool exists_; // Does the file exist? Check on creation.
57 
58  fstream rwfile; // The i/o file object
59 
60  /* An alternate open which takes a filename */
61  void open(ios_base::openmode,string);
62 
63 };
64 
65 // ========================================================================
66 // Communicator Class
67 // ========================================================================
77 {
78  public:
79  static Communicator* getInstance();
80 
82  void init(double,bool,string,string);
83 
85  File *file(string type) {
86  if (!file_.count(type))
87  initFile(type);
88  return &file_.at(type);
89  }
90 
91  void updateNames();
92 
93  protected:
94  Communicator() {}
97 
98  private:
99  ios_base::openmode mode; // The file i/o mode
100 
101  string ensemble; // The type of ensemble
102  string dataName; // The labelling scheme of the output files
103  string header; // A unique file header
104 
105  string initName; // A possible initial file name
106  string fixedName; // A posible fixed file name
107  string baseDir; // The output base directory
108 
109  double tau; // A local copy of the actual imaginary time step.
110 
111  boost::ptr_map<string,File> file_; // The file map
112 
113  /* Initialize a input/output file */
114  void initFile(string);
115 };
116 
117 
118 /**************************************************************************/
123  return temp;
124 }
125 #endif
126 
Performs input/output.
Definition: communicator.h:77
File * file(string type)
Get method returning file object.
Definition: communicator.h:85
void init(double, bool, string, string)
Initialize the output files.
static Communicator * getInstance()
This public method gets an instance of the Communicator object, only one can ever exist at a time.
Communicator & operator=(const Communicator &)
Singleton equals.
void updateNames()
Update the data name and rename any existing files.
Communicator(const Communicator &)
Copy constructor.
A basic input/output file class.
Definition: communicator.h:26
void reset()
Reset a file.
void rename()
Rename a file.
bool exists()
did the file exist before opening?
Definition: communicator.h:48
File(string, string, string, string)
Constructor.
void close()
Close the file.
void open(ios_base::openmode)
Open the file.
Global common header with shared dependencies and methods.
ensemble
Each move can operate on only the digaonal ensemble, only the off-diagonal ensemble,...
Definition: common.h:133
Communicator * communicate()
Global public access to the communcator singleton.
Definition: communicator.h:121
ConstantParameters class definition.