-
Notifications
You must be signed in to change notification settings - Fork 226
Fix #702 Activate new plugins after restart #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that is not ideal for "cerr" but could be maybe better in a log level such as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will change this to a log warning. |
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line on the other hand is an unexpected state. even if log (Nevertheless, it would be clean if we introduce a specific, default-enabled log state that writes to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will keep this a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| << "', output disabled" << std::endl; | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** Checkpoints a txt file | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting way of checking that.
We usually use
if( !boost::filesystem::exists( src ) )for that - maybe that's more suited here, too.also saves you the
restartFile.close();lines below.boost:filesystemis already in the scope, so you can use a slickif( ! exists( src ) ):)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ax3l Thanks, that's way better. I will change it to
boost::filesystem::....