![]() |
Chaste Commit::333233612e3dcc941d260418acd7b5ccdc30390e
|
#include <OutputFileHandler.hpp>
Public Member Functions | |
OutputFileHandler (const std::string &rDirectory, bool cleanOutputDirectory=true) | |
OutputFileHandler (const FileFinder &rDirectory, bool cleanOutputDirectory=true) | |
std::string | GetOutputDirectoryFullPath () const |
std::string | GetRelativePath () const |
void | SetArchiveDirectory () const |
out_stream | OpenOutputFile (const std::string &rFileName, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const |
out_stream | OpenOutputFile (const std::string &rFileName, unsigned number, const std::string &rFileFormat, std::ios_base::openmode mode=std::ios::out|std::ios::trunc) const |
FileFinder | CopyFileTo (const FileFinder &rSourceFile) const |
FileFinder | FindFile (std::string leafName) const |
Static Public Member Functions | |
static std::string | GetChasteTestOutputDirectory () |
Static Public Attributes | |
static const std::string | SIG_FILE_NAME |
Private Member Functions | |
void | CommonConstructor (const std::string &rDirectory, bool cleanOutputDirectory) |
std::string | MakeFoldersAndReturnFullPath (const std::string &rDirectory) const |
Static Private Member Functions | |
static void | AddTrailingSlash (std::string &rDirectory) |
Private Attributes | |
std::string | mDirectory |
The directory to store output files in (always ends in "/") | |
This file abstracts stuff that needs to be done when creating output files for tests. It defines some helpful functions, so that things that are otherwise repeated in lots of places are just done here.
Definition at line 54 of file OutputFileHandler.hpp.
OutputFileHandler::OutputFileHandler | ( | const std::string & | rDirectory, |
bool | cleanOutputDirectory = true |
||
) |
Create an OutputFileHandler that will create output files in the given directory. The directory name should be relative to the place where Chaste test output is stored. If the user needs to know where this is, use the GetChasteTestOutputDirectory method.
Will check that the directory exists and create it if needed.
rDirectory | the directory to put output files in. |
cleanOutputDirectory | whether to remove any existing files in the output directory |
Definition at line 90 of file OutputFileHandler.cpp.
References CommonConstructor().
OutputFileHandler::OutputFileHandler | ( | const FileFinder & | rDirectory, |
bool | cleanOutputDirectory = true |
||
) |
Create an OutputFileHandler that will create output files in the given directory. This must be located inside the folder where Chaste test output is stored, and will typically be obtained with the FindFile method of this class from a parent handler.
Will check that the directory exists and create it if needed.
rDirectory | the directory to put output files in |
cleanOutputDirectory | whether to remove any existing files in the output directory |
Definition at line 97 of file OutputFileHandler.cpp.
References RelativeTo::ChasteTestOutput, CommonConstructor(), EXCEPTION, FileFinder::GetAbsolutePath(), and FileFinder::GetRelativePath().
|
staticprivate |
Takes a reference to a string and adds a trailing slash if one is not already present
rDirectory | The directory name to add a trailing slash to. |
Definition at line 282 of file OutputFileHandler.cpp.
Referenced by GetChasteTestOutputDirectory(), and MakeFoldersAndReturnFullPath().
|
private |
Functionality common to both constructors.
rDirectory | relative path to the directory to put output files in |
cleanOutputDirectory | whether to remove any existing files in the output directory |
Definition at line 121 of file OutputFileHandler.cpp.
References RelativeTo::Absolute, PetscTools::AmMaster(), PetscTools::Barrier(), EXCEPTION, FileFinder::Exists(), MakeFoldersAndReturnFullPath(), mDirectory, and SIG_FILE_NAME.
Referenced by OutputFileHandler(), and OutputFileHandler().
FileFinder OutputFileHandler::CopyFileTo | ( | const FileFinder & | rSourceFile | ) | const |
Copy the given file to this output directory.
rSourceFile | the file to copy |
Definition at line 291 of file OutputFileHandler.cpp.
References RelativeTo::Absolute, PetscTools::AmMaster(), PetscTools::Barrier(), EXCEPTION, FileFinder::GetAbsolutePath(), GetOutputDirectoryFullPath(), FileFinder::IsFile(), and TERMINATE.
Referenced by CellMLLoader::LoadCellMLFile().
FileFinder OutputFileHandler::FindFile | ( | std::string | leafName | ) | const |
leafName | the name of the file to find |
Definition at line 317 of file OutputFileHandler.cpp.
References RelativeTo::Absolute, and GetOutputDirectoryFullPath().
Referenced by CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), HoneycombMeshGenerator::HoneycombMeshGenerator(), ToroidalHoneycombMeshGenerator::ToroidalHoneycombMeshGenerator(), AbstractConvergenceTester< CELL, CARDIAC_PROBLEM, DIM, PROBLEM_DIM >::Converge(), CardiacSimulation::CreateAndRun(), GetRelativePath(), ImmersedBoundaryCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), VertexBasedCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), and CellMLLoader::LoadCellMLFile().
|
static |
Static method for getting the test output directory (the directory where chaste stores test output). This is set from the environment variable CHASTE_TEST_OUTPUT, and defaults to "/tmp/$USER/testoutput" if it is not set.
Attempts to return an absolute path, but may get confused by odd setups.
Static so an output file handler does not have to be created if the test output directory is wanted for, say, reading a file.
Definition at line 162 of file OutputFileHandler.cpp.
References RelativeTo::AbsoluteOrCwd, AddTrailingSlash(), DefaultChasteTestOutput(), FileFinder::GetAbsolutePath(), and FileFinder::SetPath().
Referenced by ArchiveLocationInfo::GetArchiveRelativePath(), ExecutableSupport::GetBuildInfo(), ArchiveLocationInfo::GetIsDirRelativeToChasteTestOutput(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::InitialiseWriter(), MakeFoldersAndReturnFullPath(), FileFinder::PrivateRemove(), and FileFinder::SetPath().
std::string OutputFileHandler::GetOutputDirectoryFullPath | ( | ) | const |
Definition at line 239 of file OutputFileHandler.cpp.
References mDirectory.
Referenced by ColumnDataReader::ColumnDataReader(), CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), HoneycombMeshGenerator::HoneycombMeshGenerator(), ToroidalHoneycombMeshGenerator::ToroidalHoneycombMeshGenerator(), DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ConstructCuboid(), DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ConstructLinearMesh(), DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ConstructRectangularMesh(), CopyFileTo(), CardiacSimulation::CreateResumeXmlFile(), FindFile(), ColumnDataWriter::GetOutputDirectory(), ImmersedBoundaryCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), VertexBasedCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM >::OutputSimulationSetup(), CardiacSimulationArchiver< PROBLEM_CLASS >::Save(), SetArchiveDirectory(), and HeartConfig::Write().
std::string OutputFileHandler::GetRelativePath | ( | ) | const |
Definition at line 244 of file OutputFileHandler.cpp.
References RelativeTo::ChasteTestOutput, FindFile(), and FileFinder::GetRelativePath().
|
private |
Check that the desired output directory exists and is writable by us. Create it if needed. Return the full pathname of the output directory.
The environment variable CHASTE_TEST_OUTPUT will be examined. If it is set and non-empty it is taken to be a directory where test output should be stored. Otherwise the current directory is used.
rDirectory | pathname of the output directory, relative to where Chaste output will be stored (user shouldn't care about this). |
Definition at line 183 of file OutputFileHandler.cpp.
References AddTrailingSlash(), PetscTools::AmMaster(), PetscTools::Barrier(), GetChasteTestOutputDirectory(), SIG_FILE_NAME, and TERMINATE.
Referenced by CommonConstructor().
out_stream OutputFileHandler::OpenOutputFile | ( | const std::string & | rFileName, |
std::ios_base::openmode | mode = std::ios::out | std::ios::trunc |
||
) | const |
Open an output file in our directory, and check it was opened successfully. Throws an Exception if not.
rFileName | the name of the file to open, relative to the output directory. |
mode | optionally, flags to use when opening the file (defaults are as for std::ofstream). |
Definition at line 255 of file OutputFileHandler.cpp.
References EXCEPTION, and mDirectory.
Referenced by CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), Hdf5ToTxtConverter< ELEMENT_DIM, SPACE_DIM >::Hdf5ToTxtConverter(), HoneycombMeshGenerator::HoneycombMeshGenerator(), ProgressReporter::ProgressReporter(), SimpleDataWriter::SimpleDataWriter(), ToroidalHoneycombMeshGenerator::ToroidalHoneycombMeshGenerator(), AbstractCellPopulation< DIM >::AddCellUsingLocationIndex(), AbstractConvergenceTester< CELL, CARDIAC_PROBLEM, DIM, PROBLEM_DIM >::Converge(), ColumnDataWriter::CreateFixedDimensionFile(), ColumnDataWriter::CreateInfoFile(), CardiacSimulation::CreateResumeXmlFile(), CardiacElectroMechanicsProblem< DIM, ELEC_PROB_DIM >::DetermineWatchedNodes(), ColumnDataWriter::EndDefineMode(), ActivationOutputModifier::FinaliseAtEnd(), ImmersedBoundaryCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), VertexBasedCellPopulation< DIM >::GetTetrahedralMeshForPdeModifier(), SingleTraceOutputModifier::InitialiseAtStart(), OpenOutputFile(), AbstractCellBasedWriter< ELEMENT_DIM, SPACE_DIM >::OpenOutputFile(), AbstractCellBasedWriter< ELEMENT_DIM, SPACE_DIM >::OpenOutputFileForAppend(), AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM >::OutputSimulationSetup(), StreeterFibreGenerator< SPACE_DIM >::PreWriteCalculations(), ExecutableSupport::PrintError(), LogFile::Set(), AbstractPdeModifier< DIM >::SetupSolve(), LinearParabolicPdeSystemWithCoupledOdeSystemSolver< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::SolveAndWriteResultsToFile(), ImmersedBoundarySvgWriter< DIM >::UpdateAtEndOfTimeStep(), AbstractPerElementWriter< ELEMENT_DIM, SPACE_DIM, DATA_SIZE >::WriteData(), PostProcessingWriter< ELEMENT_DIM, SPACE_DIM >::WriteGenericFileToMeshalyzer(), HeartGeometryInformation< SPACE_DIM >::WriteLayerForEachNode(), ExecutableSupport::WriteMachineInfoFile(), ExecutableSupport::WriteProvenanceInfoFile(), PseudoEcgCalculator< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::WritePseudoEcg(), and DiscreteSystemForceCalculator::WriteResultsToFile().
out_stream OutputFileHandler::OpenOutputFile | ( | const std::string & | rFileName, |
unsigned | number, | ||
const std::string & | rFileFormat, | ||
std::ios_base::openmode | mode = std::ios::out | std::ios::trunc |
||
) | const |
This just calls the other OpenOutputFile after concatenating the first three arguments together to make the full filename. For example OpenOutputFile("results_", 3, ".dat") creates results_3.dat. See documentation for OpenOutputFile(std::string, std::ios_base::openmode).
rFileName | the root name of the file to open |
number | the number to append to the root name of the file |
rFileFormat | the file format (extension) |
mode | optionally, flags to use when opening the file (defaults are as for std::ofstream). |
Definition at line 266 of file OutputFileHandler.cpp.
References OpenOutputFile().
void OutputFileHandler::SetArchiveDirectory | ( | ) | const |
Helper method to set up ArchiveLocationInfo.
Definition at line 276 of file OutputFileHandler.cpp.
References RelativeTo::Absolute, GetOutputDirectoryFullPath(), and ArchiveLocationInfo::SetArchiveDirectory().
|
private |
The directory to store output files in (always ends in "/")
Definition at line 168 of file OutputFileHandler.hpp.
Referenced by CommonConstructor(), GetOutputDirectoryFullPath(), and OpenOutputFile().
|
static |
The name of the Chaste signature file added to folders we create.
Definition at line 165 of file OutputFileHandler.hpp.
Referenced by CommonConstructor(), MakeFoldersAndReturnFullPath(), and FileFinder::PrivateRemove().