OutputFileHandler Class Reference

#include <OutputFileHandler.hpp>

Collaboration diagram for OutputFileHandler:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 OutputFileHandler (const std::string &rDirectory, bool cleanOutputDirectory=true)
std::string GetOutputDirectoryFullPath () 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 ()

Private Member Functions

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 "/").


Detailed Description

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 48 of file OutputFileHandler.hpp.


Constructor & Destructor Documentation

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.

Note:
This MUST be called collectively, since it contains a barrier call.
Parameters:
rDirectory the directory to put output files in.
cleanOutputDirectory whether to remove any existing files in the output directory

Definition at line 41 of file OutputFileHandler.cpp.

References PetscTools::AmMaster(), PetscTools::Barrier(), EXCEPTION, MakeFoldersAndReturnFullPath(), mDirectory, and MPIABORTIFNON0.


Member Function Documentation

void OutputFileHandler::AddTrailingSlash ( std::string &  rDirectory  )  [static, private]

Takes a reference to a string and adds a trailing slash if one is not already present

Parameters:
rDirectory The directory name to add a trailing slash to.

Definition at line 187 of file OutputFileHandler.cpp.

Referenced by GetChasteTestOutputDirectory(), and MakeFoldersAndReturnFullPath().

std::string OutputFileHandler::MakeFoldersAndReturnFullPath ( const std::string &  rDirectory  )  const [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.

Note:
Contains a barrier, so must be called collectively.
Parameters:
rDirectory pathname of the output directory, relative to where Chaste output will be stored (user shouldn't care about this).
Returns:
full pathname to the output directory

Definition at line 105 of file OutputFileHandler.cpp.

References AddTrailingSlash(), PetscTools::AmMaster(), PetscTools::Barrier(), GetChasteTestOutputDirectory(), and MPIABORTIFNON0.

Referenced by OutputFileHandler().

std::string OutputFileHandler::GetChasteTestOutputDirectory (  )  [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 "./testoutput" if it is not set.

Attempts to return an absolute path, but may get confused by odd setups. Eventually we'll move to using boost::filesystem, which would be more robust.

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 75 of file OutputFileHandler.cpp.

References AddTrailingSlash().

Referenced by OutputDirectoryFifoQueue::CreateNextDir(), ArchiveLocationInfo::GetArchiveRelativePath(), ArchiveLocationInfo::GetIsDirRelativeToChasteTestOutput(), MakeFoldersAndReturnFullPath(), and FileFinder::SetPath().

std::string OutputFileHandler::GetOutputDirectoryFullPath (  )  const

void OutputFileHandler::SetArchiveDirectory (  )  const

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.

Parameters:
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).
Returns:
a managed pointer to the opened file stream.

Definition at line 159 of file OutputFileHandler.cpp.

References EXCEPTION, and mDirectory.

Referenced by AbstractHdf5Converter< ELEMENT_DIM, SPACE_DIM >::AbstractHdf5Converter(), VtkMeshWriter< ELEMENT_DIM, SPACE_DIM >::AddProvenance(), AbstractConvergenceTester< CELL, CARDIAC_PROBLEM, DIM, PROBLEM_DIM >::Converge(), ColumnDataWriter::CreateFixedDimensionFile(), ColumnDataWriter::CreateInfoFile(), CellMLToSharedLibraryConverter::CreateOptionsFile(), VertexBasedCellPopulation< DIM >::CreateOutputFiles(), MeshBasedCellPopulation< DIM >::CreateOutputFiles(), AbstractCellPopulation< DIM >::CreateOutputFiles(), CardiacSimulation::CreateResumeXmlFile(), CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), CardiacElectroMechanicsProblem< DIM >::DetermineWatchedNodes(), ColumnDataWriter::EndDefineMode(), StreeterFibreGenerator< SPACE_DIM >::GenerateOrthotropicFibreOrientation(), HoneycombMeshGenerator::HoneycombMeshGenerator(), MeshalyzerMeshWriter< ELEMENT_DIM, SPACE_DIM >::OpenElementFile(), MeshalyzerMeshWriter< ELEMENT_DIM, SPACE_DIM >::OpenFaceFile(), MeshalyzerMeshWriter< ELEMENT_DIM, SPACE_DIM >::OpenNodeFile(), OpenOutputFile(), CellBasedSimulation< DIM >::OutputSimulationSetup(), ExecutableSupport::PrintError(), ProgressReporter::ProgressReporter(), LogFile::Set(), VertexCryptSimulation2d::SetupWriteBetaCatenin(), CryptSimulation2d::SetupWriteBetaCatenin(), CellBasedSimulationWithPdes< DIM >::SetupWritePdeSolution(), SimpleDataWriter::SimpleDataWriter(), CellBasedSimulation< DIM >::Solve(), Hdf5ToMeshalyzerConverter< ELEMENT_DIM, SPACE_DIM >::Write(), Hdf5ToCmguiConverter< ELEMENT_DIM, SPACE_DIM >::Write(), QuadraticMesh< DIM >::WriteBoundaryElementFile(), CmguiDeformedSolutionsWriter< DIM >::WriteCmguiScript(), Hdf5ToCmguiConverter< ELEMENT_DIM, SPACE_DIM >::WriteCmguiScript(), AbstractNonlinearElasticitySolver< COMPRESSIBILITY_TYPE, DIM >::WriteCurrentDeformation(), CmguiDeformedSolutionsWriter< DIM >::WriteDeformationPositions(), TrianglesMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteElementsAsFaces(), TrianglesMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteFacesAsEdges(), TrianglesMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteFiles(), CmguiMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteFiles(), VertexMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteFiles(), AbstractTetrahedralMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteFilesUsingMesh(), PostProcessingWriter< ELEMENT_DIM, SPACE_DIM >::WriteGenericFile(), HeartGeometryInformation< SPACE_DIM >::WriteLayerForEachNode(), ExecutableSupport::WriteMachineInfoFile(), MeshalyzerMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteMetaFile(), 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).

Parameters:
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
mode optionally, flags to use when opening the file (defaults are as for std::ofstream).

Definition at line 171 of file OutputFileHandler.cpp.

References OpenOutputFile().

FileFinder OutputFileHandler::CopyFileTo ( const FileFinder rSourceFile  )  const

Copy the given file to this output directory.

Parameters:
rSourceFile the file to copy
Returns:
the copied file

Definition at line 196 of file OutputFileHandler.cpp.

References PetscTools::AmMaster(), PetscTools::Barrier(), EXCEPTION, FindFile(), FileFinder::GetAbsolutePath(), FileFinder::GetLeafName(), GetOutputDirectoryFullPath(), FileFinder::IsFile(), and MPIABORTIFNON0.

FileFinder OutputFileHandler::FindFile ( std::string  leafName  )  const

Get a FileFinder for a file in this output directory.

Parameters:
leafName the name of the file to find

Definition at line 210 of file OutputFileHandler.cpp.

References RelativeTo::Absolute, and GetOutputDirectoryFullPath().

Referenced by CopyFileTo().


The documentation for this class was generated from the following files:

Generated on Mon Apr 18 11:37:41 2011 for Chaste by  doxygen 1.5.5