10#include "FileMaster.h"
12#include <util/mpi/MpiLoader.h>
32 hasDirectoryId_(false),
33 isCommonControl_(false)
42 inputPrefix_(other.inputPrefix_),
43 outputPrefix_(other.outputPrefix_),
44 directoryIdPrefix_(other.directoryIdPrefix_),
45 rootPrefix_(other.rootPrefix_),
48 hasDirectoryId_(other.hasDirectoryId_),
49 isCommonControl_(other.isCommonControl_)
58 paramFilePtr_->close();
61 if (commandFilePtr_) {
62 commandFilePtr_->close();
63 delete commandFilePtr_;
71 { rootPrefix_ = rootPrefix; }
78 std::stringstream sMyId;
80 directoryIdPrefix_ = sMyId.str();
81 directoryIdPrefix_ +=
"/";
82 hasDirectoryId_ =
true;
89 { isCommonControl_ =
true; }
95 { inputPrefix_ = inputPrefix; }
101 { outputPrefix_ = outputPrefix; }
120 if (commandFileName_.empty()) {
121 readOptional<std::string>(in,
"commandFileName", commandFileName_);
123 readOptional<std::string>(in,
"inputPrefix", inputPrefix_);
124 readOptional<std::string>(in,
"outputPrefix", outputPrefix_);
132 loadParameter<std::string>(ar,
"inputPrefix", inputPrefix_);
133 loadParameter<std::string>(ar,
"outputPrefix", outputPrefix_);
136 loader.
load(isCommonControl_);
138 ar >> isCommonControl_;
149 ar << isCommonControl_;
158 return *paramFilePtr_;
160 if (paramFileName_.empty()) {
161 if (!hasDirectoryId_ || isCommonControl_) {
164 paramFileName_ =
"param";
167 paramFilePtr_ =
new std::ifstream();
171 return *paramFilePtr_;
180 if (commandFilePtr_) {
181 return *commandFilePtr_;
183 if (commandFileName_.empty()) {
184 commandFileName_ =
"commands";
186 commandFilePtr_ =
new std::ifstream();
190 return *commandFilePtr_;
199 std::ios_base::openmode mode)
const
201 in.open(name.c_str(), mode);
203 std::string message =
"Error opening input file. Filename: ";
214 std::ios_base::openmode mode)
const
216 out.open(name.c_str(), mode);
218 std::string message =
"Error opening output file. Filename: ";
228 std::ifstream& in)
const
230 std::string filename(rootPrefix_);
231 if (hasDirectoryId_ && !isCommonControl_) {
232 filename += directoryIdPrefix_;
243 std::ios_base::openmode mode)
const
245 std::string filename(rootPrefix_);
246 if (hasDirectoryId_) {
247 filename += directoryIdPrefix_;
250 open(filename, in, mode);
258 std::ios_base::openmode mode)
const
261 std::string filename(rootPrefix_);
262 if (hasDirectoryId_) {
263 filename = directoryIdPrefix_;
266 open(filename, out, mode);
274 std::ios_base::openmode mode)
const
277 std::string filename(rootPrefix_);
278 if (hasDirectoryId_) {
279 filename += directoryIdPrefix_;
281 filename += inputPrefix_;
283 open(filename, in, mode);
292 std::ios_base::openmode mode)
const
295 std::string filename(rootPrefix_);
296 if (hasDirectoryId_) {
297 filename += directoryIdPrefix_;
299 filename += outputPrefix_;
302 open(filename, out, mode);
309 {
return ((!hasDirectoryId_) || isCommonControl_); }
Saving archive for binary istream.
Saving / output archive for binary ostream.
A FileMaster manages input and output files for a simulation.
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.
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 ¶mFileName)
Set the parameter file name.
std::string commandFileName() const
Return the command file name.
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.
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.
Provides methods for MPI-aware loading of data from input archive.
void load(Data &value)
Load and broadcast a single Data value.
void setClassName(const char *className)
Set class name string.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.