Utility class for reading delimited data (e.g., CSV data). More...
#include <MixedDataDelimitedFileReader.h>
Public Types | |
| enum class | HeaderFlag { OFF = 0 , ON = 1 , AUTO = 2 } |
| enum class | FormatFlag { COLUMNS = 0 , ROWS = 1 } |
Public Member Functions | |
| MixedDataDelimitedFileReader (const std::string &filename) | |
| MixedDataDelimitedFileReader (const std::string &filename, const libMesh::Parallel::Communicator *comm) | |
| template<typename T > | |
| const std::vector< T > | getData (const std::string &name) const |
| Converts a specific named column in the data set to a vector of a specified type. | |
| template<typename T > | |
| const std::vector< T > | getData (std::size_t index_column) const |
| Converts a column in the data set to a vector of a specified type. | |
| void | read () |
| Perform the actual data reading. | |
| std::size_t | numEntries () const |
| Get the total number of entries in the file. | |
| void | setFileName (const std::string &new_file) |
| Set the file name, used to change the file to read from We also reset the column/row names as a second read might have different names. | |
| const std::vector< std::string > & | getNames () const |
| Return the column/row names. | |
| const std::vector< std::vector< T > > & | getData () const |
| Return the rows/columns of data. | |
| const std::vector< Point > | getDataAsPoints () const |
| Get the data in Point format. | |
| const std::vector< Point > | getDataAsPoints () const |
| void | setIgnoreEmptyLines (bool value) |
| Set/Get methods for file format controls. | |
| bool | getIgnoreEmptyLines () const |
| void | setFormatFlag (FormatFlag value) |
| FormatFlag | getFormatFlag () const |
| void | setDelimiter (const std::string &value) |
| const std::string & | setDelimiter () const |
| void | setHeaderFlag (HeaderFlag value) |
| HeaderFlag | getHeaderFlag () const |
| void | setComment (const std::string &value) |
| const std::string & | getComment () const |
Public Attributes | |
| const std::size_t | INVALID_SIZE = std::numeric_limits<std::size_t>::max() |
Protected Member Functions | |
| template<typename T > | |
| std::vector< T > | convertVector (const std::vector< std::string > &column) const |
| Given a column of a data set this will convert it to a vector of the requested type. | |
Protected Attributes | |
| std::string | _filename |
| The supplied filename. | |
| HeaderFlag | _header_flag |
| Flag indicating if the file contains a header. | |
| std::string | _delimiter |
| The delimiter separating the supplied data entires. | |
| bool | _ignore_empty_lines |
| Flag for ignoring empty lines. | |
| std::vector< std::string > | _names |
| Storage for the read or generated column names. | |
| std::vector< std::vector< T > > | _data |
| Storage for the read data columns. | |
| const libMesh::Parallel::Communicator *const | _communicator |
| Communicator. | |
| FormatFlag | _format_flag |
| Format "rows" vs "columns". | |
| std::vector< std::size_t > | _row_offsets |
| Row offsets (only used with _format == "rows") | |
| std::string | _row_comment |
| Hide row comments. | |
Private Member Functions | |
| void | processLine (const std::string &line, std::vector< T > &row, const unsigned int &num) |
| Populate supplied vector with content from line. | |
| bool | preprocessLine (std::string &line, const unsigned int &num) |
| Check the content of the line and if it should be skipped. | |
| const std::string & | delimiter (const std::string &line) |
| Determine the delimiter. | |
| bool | header (const std::string &line) |
| Return the header flag, if it is set to AUTO attempt to determine if a header exists in line. | |
| void | readColumnData (std::ifstream &stream_data, std::vector< T > &output) |
| Read the numeric data as rows or columns into a single vector. | |
| void | readRowData (std::ifstream &stream_data, std::vector< T > &output) |
Utility class for reading delimited data (e.g., CSV data).
where the csv has columns of mixed data types
| filename | A string for the filename to read. |
This class allows csv files to contain columns of mixed data types. All of the data is internally stored as string data and then converted to the requested type when getData<T> is called. If a communicator is provide then it will only read on processor 0 and broadcast the data to all processors. If not provided it will read on all processors.
Definition at line 28 of file MixedDataDelimitedFileReader.h.
|
stronginherited |
| Enumerator | |
|---|---|
| COLUMNS | |
| ROWS | |
Definition at line 46 of file DelimitedFileReader.h.
|
stronginherited |
| Enumerator | |
|---|---|
| OFF | |
| ON | |
| AUTO | |
Definition at line 39 of file DelimitedFileReader.h.
|
inline |
Definition at line 31 of file MixedDataDelimitedFileReader.h.
|
inline |
Definition at line 35 of file MixedDataDelimitedFileReader.h.
|
inlineprotected |
Given a column of a data set this will convert it to a vector of the requested type.
| T | the type to convert the column to |
| column | the column of the dataset provided as a string |
| mooseError | if the requested column index does not exist within the dataset |
| std::invalid_argument | if one of the entries in the requested column cannot be converted to the requested type |
Definition at line 91 of file MixedDataDelimitedFileReader.h.
|
privateinherited |
Determine the delimiter.
If the setDelimiter method is not called the data is inspected, if a ',' is found it is assumed to be the delimiter as is the case for \t. Otherwise a space is used.
Definition at line 389 of file DelimitedFileReader.C.
|
inlineinherited |
Definition at line 93 of file DelimitedFileReader.h.
|
inherited |
Return the rows/columns of data.
The outer vector is column and the inner the rows.
Definition at line 146 of file DelimitedFileReader.C.
Referenced by TimedSubdomainModifier::buildFromFile(), PiecewiseTabularInterface::buildFromFile(), CSVFileTimes::CSVFileTimes(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), PropertyReadFile::getBlockData(), getData(), getData(), PropertyReadFile::getElementData(), PropertyReadFile::getFileNames(), PropertyReadFile::getNodeData(), PropertyReadFile::getVoronoiData(), PropertyReadFile::initVoronoiCenterPoints(), and PropertyReadFile::readData().
|
inline |
Converts a specific named column in the data set to a vector of a specified type.
| The | type to convert the column to |
| name | the name of the column in the data file |
| mooseError | if the requested column name does not exist within the dataset |
| std::invalid_argument | if one of the entries in the requested column cannot be converted to the requested type |
Definition at line 54 of file MixedDataDelimitedFileReader.h.
Referenced by CSVTimeSequenceStepper::init().
|
inline |
Converts a column in the data set to a vector of a specified type.
| T | The type to convert the column to |
| index_column | the index of the desired column |
| mooseError | if the requested column index does not exist within the dataset |
| std::invalid_argument | if one of the entries in the requested column cannot be converted to the requested type |
Definition at line 72 of file MixedDataDelimitedFileReader.h.
|
inherited |
Get the data in Point format.
This performs checks that the data is of valid dimensions to do so.
Definition at line 185 of file DelimitedFileReader.C.
Referenced by FilePositions::FilePositions(), NearestPointBase< UserObjectType, BaseType >::fillPoints(), SpatialUserObjectVectorPostprocessor::fillPoints(), CombinerGenerator::fillPositions(), MultiApp::fillPositions(), and XYDelaunayGenerator::XYDelaunayGenerator().
|
inherited |
Definition at line 153 of file DelimitedFileReader.C.
|
inlineinherited |
Definition at line 84 of file DelimitedFileReader.h.
|
inlineinherited |
Definition at line 90 of file DelimitedFileReader.h.
|
inlineinherited |
Definition at line 81 of file DelimitedFileReader.h.
|
inherited |
Return the column/row names.
Definition at line 139 of file DelimitedFileReader.C.
Referenced by TimedSubdomainModifier::buildFromFile(), PiecewiseTabularInterface::buildFromFile(), and CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor().
|
privateinherited |
Return the header flag, if it is set to AUTO attempt to determine if a header exists in line.
Definition at line 405 of file DelimitedFileReader.C.
|
inherited |
Get the total number of entries in the file.
Definition at line 128 of file DelimitedFileReader.C.
|
privateinherited |
Check the content of the line and if it should be skipped.
| line | Complete line being read. |
| num | The current line number. |
Definition at line 342 of file DelimitedFileReader.C.
|
privateinherited |
Populate supplied vector with content from line.
| line | The line to extract data from. |
| row | The vector to populate. |
| num | The current line number. |
Definition at line 361 of file DelimitedFileReader.C.
|
inherited |
Perform the actual data reading.
This is a separate method to allow for the filename to be read multiple times.
Definition at line 38 of file DelimitedFileReader.C.
Referenced by TimedSubdomainModifier::buildFromFile(), PiecewiseTabularInterface::buildFromFile(), CSVFileTimes::CSVFileTimes(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), FilePositions::FilePositions(), NearestPointBase< UserObjectType, BaseType >::fillPoints(), SpatialUserObjectVectorPostprocessor::fillPoints(), CombinerGenerator::fillPositions(), MultiApp::fillPositions(), PropertyReadFile::getFileNames(), CSVTimeSequenceStepper::init(), PropertyReadFile::readData(), and XYDelaunayGenerator::XYDelaunayGenerator().
|
privateinherited |
Read the numeric data as rows or columns into a single vector.
Definition at line 217 of file DelimitedFileReader.C.
|
privateinherited |
Definition at line 288 of file DelimitedFileReader.C.
|
inlineinherited |
Definition at line 92 of file DelimitedFileReader.h.
Referenced by TimedSubdomainModifier::buildFromFile(), and PiecewiseTabularInterface::buildFromFile().
|
inlineinherited |
Definition at line 87 of file DelimitedFileReader.h.
|
inlineinherited |
Definition at line 86 of file DelimitedFileReader.h.
Referenced by TimedSubdomainModifier::buildFromFile(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), and CSVTimeSequenceStepper::init().
|
inlineinherited |
Set the file name, used to change the file to read from We also reset the column/row names as a second read might have different names.
Definition at line 98 of file DelimitedFileReader.h.
Referenced by PropertyReadFile::initialize().
|
inlineinherited |
Definition at line 83 of file DelimitedFileReader.h.
Referenced by PiecewiseTabularInterface::buildFromFile(), CSVFileTimes::CSVFileTimes(), FilePositions::FilePositions(), NearestPointBase< UserObjectType, BaseType >::fillPoints(), SpatialUserObjectVectorPostprocessor::fillPoints(), CombinerGenerator::fillPositions(), MultiApp::fillPositions(), PropertyReadFile::readData(), and XYDelaunayGenerator::XYDelaunayGenerator().
|
inlineinherited |
Definition at line 89 of file DelimitedFileReader.h.
Referenced by TimedSubdomainModifier::buildFromFile(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), PropertyReadFile::getFileNames(), and CSVTimeSequenceStepper::init().
|
inlineinherited |
Set/Get methods for file format controls.
IgnoreEmptyLines: When true all empty lines are ignored, when false an error is produced. FormatFlag: Set the file format (rows vs. columns). Delimiter: Set the file delimiter (if unset it will be detected). HeaderFlag: Set the header flag (TRUE used the first row has header, FALSE assumes no header, and AUTO will attempt to determine if a header exists). Comment: Set the comment character, by default no comment character is used.
Definition at line 80 of file DelimitedFileReader.h.
Referenced by CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor().
|
protectedinherited |
Communicator.
Definition at line 150 of file DelimitedFileReader.h.
|
protectedinherited |
Storage for the read data columns.
Definition at line 147 of file DelimitedFileReader.h.
|
protectedinherited |
The delimiter separating the supplied data entires.
Definition at line 138 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setDelimiter(), and MooseUtils::DelimitedFileReaderTempl< T >::setDelimiter().
|
protectedinherited |
The supplied filename.
Definition at line 132 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setFileName().
|
protectedinherited |
Format "rows" vs "columns".
Definition at line 153 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::getFormatFlag(), and MooseUtils::DelimitedFileReaderTempl< T >::setFormatFlag().
|
protectedinherited |
Flag indicating if the file contains a header.
Definition at line 135 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::getHeaderFlag(), and MooseUtils::DelimitedFileReaderTempl< T >::setHeaderFlag().
|
protectedinherited |
Flag for ignoring empty lines.
Definition at line 141 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::getIgnoreEmptyLines(), and MooseUtils::DelimitedFileReaderTempl< T >::setIgnoreEmptyLines().
|
protectedinherited |
Storage for the read or generated column names.
Definition at line 144 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setFileName().
|
protectedinherited |
Hide row comments.
Definition at line 159 of file DelimitedFileReader.h.
Referenced by MooseUtils::DelimitedFileReaderTempl< T >::getComment(), and MooseUtils::DelimitedFileReaderTempl< T >::setComment().
|
protectedinherited |
Row offsets (only used with _format == "rows")
Definition at line 156 of file DelimitedFileReader.h.
|
inherited |
Definition at line 52 of file DelimitedFileReader.h.