diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 9a28815f8b40f5123197bfcdca9cc76aab4cebee..95f6f7d0c2445332c34ce9d06426a1228139d7be 100644 --- a/src/tools/OFile.cpp +++ b/src/tools/OFile.cpp @@ -62,7 +62,8 @@ size_t OFile::llwrite(const char*ptr,size_t s){ OFile::OFile(): linked(NULL), fieldChanged(false), - backstring("bck") + backstring("bck"), + enforceRestart_(false) { fmtField(); buflen=1; @@ -361,10 +362,15 @@ FileBase& OFile::flush(){ } bool OFile::checkRestart()const{ - if(plumed && plumed->getRestart()) return true; + if(enforceRestart_ || (plumed && plumed->getRestart() ) ) return true; else return false; } +OFile& OFile::enforceRestart(){ + enforceRestart_=true; + return *this; +} + } diff --git a/src/tools/OFile.h b/src/tools/OFile.h index bd45eeaa5420dd33f1d8c0191bad04f924b7e3e5..243e08a0490d5265ba7457989a23764582cc2be0 100644 --- a/src/tools/OFile.h +++ b/src/tools/OFile.h @@ -85,8 +85,8 @@ When a OFile object is used in PLUMED it can be convenient to link() it to the Action object where it is defined, or to the PlumedMain object. This will save in the OFile a pointer to the linked object and will allow to have some extra information. E.g., if PLUMED is restarting, -files will be appended (notice that this is the only way to -append a OFile - there is no way to enforce it). +files will be appended. Notice that one can enforce this behavior using +the enforceRestart() method before opening a file. To have all files managed consistently, it is important to use OFile in the proper way. This should allow multi-replica plumed, restart and backups to work in @@ -181,6 +181,8 @@ public virtual FileBase{ unsigned findField(const std::string&name)const; /// check if we are restarting bool checkRestart()const; +/// True if restart behavior should be forced + bool enforceRestart_; public: /// Constructor OFile(); @@ -249,6 +251,9 @@ this method can be used to clean the field list. OFile&rewind(); /// Flush a file virtual FileBase&flush(); +/// Enforce restart, also if the attached plume object is not restarting. +/// Useful for tests + OFile&enforceRestart(); }; /// Write using << syntax