From 6e4cdfc44c93329e037dec187c032b05f98cb982 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Mon, 7 Apr 2014 16:54:18 +0200 Subject: [PATCH] Added possibility to enforce append mode in OFile --- src/tools/OFile.cpp | 10 ++++++++-- src/tools/OFile.h | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 9a28815f8..95f6f7d0c 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 bd45eeaa5..243e08a04 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 -- GitLab