From 78154d8ac583476f70f38e0e69dd5132066d461e Mon Sep 17 00:00:00 2001 From: PrometheusPi Date: Fri, 13 Feb 2015 13:59:10 +0100 Subject: [PATCH 1/3] add check to allow plugins without restart files --- .../plugins/common/txtFileHandling.hpp | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/picongpu/include/plugins/common/txtFileHandling.hpp b/src/picongpu/include/plugins/common/txtFileHandling.hpp index a307562fc3..a7768bed34 100644 --- a/src/picongpu/include/plugins/common/txtFileHandling.hpp +++ b/src/picongpu/include/plugins/common/txtFileHandling.hpp @@ -1,5 +1,5 @@ /** - * Copyright 2015 Axel Huebl + * Copyright 2015 Axel Huebl, Richard Pausch * * This file is part of PIConGPU. * @@ -34,7 +34,8 @@ using namespace boost::filesystem; /** Restore a txt file from the checkpoint dir * * Restores a txt file from the checkpoint dir and starts appending to it. - * Opened files in \see outFile are closed and a valid handle is opened again. + * Opened files in \see outFile are closed and a valid handle is opened again + * if a restart file is found. Otherwise new output file stays untouched. * * \param outFile std::ofstream file handle to regular file that shall be restored * \param filename the file's name @@ -46,28 +47,46 @@ using namespace boost::filesystem; bool restoreTxtFile( std::ofstream& outFile, std::string filename, uint32_t restartStep, const std::string restartDirectory ) { - if( outFile.is_open() ) - outFile.close(); - + /* get restart time step as string */ std::stringstream sStep; sStep << restartStep; + /* set location of restart file and output file */ path src( restartDirectory + std::string("/") + filename + std::string(".") + sStep.str() ); path dst( filename ); - copy_file( src, - dst, - copy_option::overwrite_if_exists ); - - outFile.open( filename.c_str(), std::ofstream::out | std::ostream::app ); - if( !outFile ) + /* check whether restart file exists */ + std::ifstream restartFile(src.c_str()); + if(! restartFile.good()) { - std::cerr << "[Plugin] Can't open file '" << filename - << "', output disabled" << std::endl; - return false; + /* restart file does not exists */ + restartFile.close(); + std::cerr << "Plugin restart file: \n \t" << src << "\n was not found." << std::endl; + std::cerr << "Starting plugin from current time step." << std::endl; + return true; + } + else + { + /* restart file found - fix output file created at restart */ + restartFile.close(); + + if( outFile.is_open() ) + outFile.close(); + + copy_file( src, + dst, + copy_option::overwrite_if_exists ); + + outFile.open( filename.c_str(), std::ofstream::out | std::ostream::app ); + if( !outFile ) + { + std::cerr << "[Plugin] Can't open file '" << filename + << "', output disabled" << std::endl; + return false; + } + return true; } - return true; } /** Checkpoints a txt file From 1d35b57487fea08732472561469dd98c9c83f148 Mon Sep 17 00:00:00 2001 From: PrometheusPi Date: Mon, 16 Feb 2015 11:03:56 +0100 Subject: [PATCH 2/3] add changes suggested by @ax3l --- .../include/plugins/common/txtFileHandling.hpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/picongpu/include/plugins/common/txtFileHandling.hpp b/src/picongpu/include/plugins/common/txtFileHandling.hpp index a7768bed34..f6ef476645 100644 --- a/src/picongpu/include/plugins/common/txtFileHandling.hpp +++ b/src/picongpu/include/plugins/common/txtFileHandling.hpp @@ -57,20 +57,18 @@ using namespace boost::filesystem; path dst( filename ); /* check whether restart file exists */ - std::ifstream restartFile(src.c_str()); - if(! restartFile.good()) + if( !boost::filesystem::exists( src ) ) { /* restart file does not exists */ - restartFile.close(); - std::cerr << "Plugin restart file: \n \t" << src << "\n was not found." << std::endl; - std::cerr << "Starting plugin from current time step." << std::endl; + log ("Plugin restart file:"); + log ("\t %1%") % src ; + log ("was not found."); + log ("--> Starting plugin from current time step."); return true; } else { /* restart file found - fix output file created at restart */ - restartFile.close(); - if( outFile.is_open() ) outFile.close(); From 10839105ff1dc26c7950a5d361c78d405b08d91a Mon Sep 17 00:00:00 2001 From: PrometheusPi Date: Mon, 16 Feb 2015 11:43:12 +0100 Subject: [PATCH 3/3] make log output a one liner as suggested by @ax3l --- src/picongpu/include/plugins/common/txtFileHandling.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/picongpu/include/plugins/common/txtFileHandling.hpp b/src/picongpu/include/plugins/common/txtFileHandling.hpp index f6ef476645..e5f61d7724 100644 --- a/src/picongpu/include/plugins/common/txtFileHandling.hpp +++ b/src/picongpu/include/plugins/common/txtFileHandling.hpp @@ -60,10 +60,8 @@ using namespace boost::filesystem; if( !boost::filesystem::exists( src ) ) { /* restart file does not exists */ - log ("Plugin restart file:"); - log ("\t %1%") % src ; - log ("was not found."); - log ("--> Starting plugin from current time step."); + log ("Plugin restart file: %1% was not found. \ + --> Starting plugin from current time step.") % src; return true; } else