PSCF v1.3
FileMaster.h
1#ifndef UTIL_FILE_MASTER_H
2#define UTIL_FILE_MASTER_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/param/ParamComposite.h> // base class
12
13#include <ios>
14#include <fstream>
15#include <string>
16
17namespace Util
18{
19
143 {
144
145 public:
146
150 FileMaster();
151
157 FileMaster(const FileMaster& copy);
158
162 virtual ~FileMaster();
163
165
166
172 void setRootPrefix(const std::string& rootPrefix);
173
186 void setDirectoryId(int directoryId);
187
194 void setCommonControl();
195
201 void setParamFileName(const std::string& paramFileName);
202
208 void setCommandFileName(const std::string& commandFileName);
209
215 void setInputPrefix(const std::string& inputPrefix);
216
222 void setOutputPrefix(const std::string& outputPrefix);
223
231 virtual void readParameters(std::istream& in);
232
234
236
242 virtual void loadParameters(Serializable::IArchive &ar);
243
249 virtual void save(Serializable::OArchive &ar);
250
252
254
264 void open(const std::string& name, std::ifstream& in,
265 std::ios_base::openmode mode = std::ios_base::in) const;
266
276 void open(const std::string& name, std::ofstream& out,
277 std::ios_base::openmode mode = std::ios_base::out) const;
278
292 void openControlFile(const std::string& name,
293 std::ifstream& in) const;
294
305 void
306 openRestartIFile(const std::string& name, std::ifstream& in,
307 std::ios_base::openmode mode = std::ios_base::in)
308 const;
309
320 void
321 openRestartOFile(const std::string& name, std::ofstream& out,
322 std::ios_base::openmode mode = std::ios_base::out)
323 const;
324
335 void
336 openInputFile(const std::string& filename, std::ifstream& in,
337 std::ios_base::openmode mode = std::ios_base::in)
338 const;
339
350 void
351 openOutputFile(const std::string& filename, std::ofstream& out,
352 std::ios_base::openmode mode = std::ios_base::out)
353 const;
354
356
358
362 bool isCommonControl() const;
363
367 std::string paramFileName() const;
368
375 std::string commandFileName() const;
376
388 std::istream& paramFile();
389
405 std::istream& commandFile();
406
408
409 private:
410
411 /*
412 * Name of the parameter file.
413 */
414 std::string paramFileName_;
415
416 /*
417 * Name of the command file.
418 */
419 std::string commandFileName_;
420
421 /*
422 * Prefix for input data file names.
423 */
424 std::string inputPrefix_;
425
426 /*
427 * Prefix for output data file names.
428 */
429 std::string outputPrefix_;
430
431 /*
432 * The integer directory id prefix, for multi-system simulations.
433 */
434 std::string directoryIdPrefix_;
435
436 /*
437 * Path for the root directory of files for this simulation.
438 */
439 std::string rootPrefix_;
440
441 /*
442 * Pointer to the parameter file.
443 */
444 std::ifstream* paramFilePtr_;
445
446 /*
447 * Pointer to the command file.
448 */
449 std::ifstream* commandFilePtr_;
450
451 /*
452 * Has a directoryId prefix been set?
453 */
454 bool hasDirectoryId_;
455
456 /*
457 * Should we use a single parameter and command file?
458 */
459 bool isCommonControl_;
460
461 };
462
463 /*
464 * Return the command file base name.
465 */
466 inline std::string FileMaster::paramFileName() const
467 { return paramFileName_; }
468
469 /*
470 * Return the command file base name.
471 */
472 inline std::string FileMaster::commandFileName() const
473 { return commandFileName_; }
474
475}
476#endif
void openOutputFile(const std::string &filename, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output file.
virtual void save(Serializable::OArchive &ar)
Save internal state to file.
FileMaster()
Constructor.
void openRestartIFile(const std::string &name, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input restart dump file for reading.
std::istream & commandFile()
Get the command input stream by reference.
void openControlFile(const std::string &name, std::ifstream &in) const
Open an input parameter or command file.
void open(const std::string &name, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input file with a known path and open mode.
void openInputFile(const std::string &filename, std::ifstream &in, std::ios_base::openmode mode=std::ios_base::in) const
Open an input file.
virtual void readParameters(std::istream &in)
Read parameter file.
std::istream & paramFile()
Get a default parameter stream by reference.
void setParamFileName(const std::string &paramFileName)
Set the parameter file name.
std::string commandFileName() const
Return the command file name.
Definition FileMaster.h:472
virtual ~FileMaster()
Destructor.
bool isCommonControl() const
Is set for common param and command files?
void setRootPrefix(const std::string &rootPrefix)
Set the path from current directory to root directory.
void setCommonControl()
Enable "replicated" mode in multi-system simulations.
void setOutputPrefix(const std::string &outputPrefix)
Set the output file prefix string.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from file.
void setCommandFileName(const std::string &commandFileName)
Set the command file name.
void setDirectoryId(int directoryId)
Set an integer directory identifier for this processor.
void setInputPrefix(const std::string &inputPrefix)
Set the input file prefix string.
std::string paramFileName() const
Return the param file name, if any.
Definition FileMaster.h:466
void openRestartOFile(const std::string &name, std::ofstream &out, std::ios_base::openmode mode=std::ios_base::out) const
Open an output restart file for writing.
ParamComposite()
Constructor.
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
Utility classes for scientific computation.