Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Tool for reading ASCII tables from streams. More...
#include <AsciiParser.h>
Public Member Functions | |
AsciiParser (const std::string ®ex_str="^\\s*#\\s*(\\w+)\\s*$") | |
Constructor Tool for reading ASCII tables from streams. | |
std::string | getName (const std::string &file) override |
Get the dataset name of a ASCII file. | |
std::string | getParameter (const std::string &file, const std::string &key_word) override |
Get the parameter identified by a given key_word value from a file. | |
std::unique_ptr< XYDataset > | getDataset (const std::string &file) override |
Get a XYDataset object reading data from an ASCII file. | |
bool | isDatasetFile (const std::string &file) override |
Check that the ASCII file is a dataset file(with at least one line with
2 double values) | |
virtual | ~AsciiParser ()=default |
Default destructor. | |
![]() | |
virtual | ~FileParser ()=default |
Default destructor. | |
Private Attributes | |
std::string | m_regex_name |
Tool for reading ASCII tables from streams.
The AsciiParser reads ASCII files which contain space or tab separated tables of two columns. The first column contains the X data and the second the Y data. The name of the dataset is extracted from the first non-empty line of the file, as the first match of a regular expression. If the regular expression does not match, the name of the file (excluding the extension) is used as the name of the dataset. Comments are supported by using the "#" character.
ElementException | : File not found |
Definition at line 53 of file AsciiParser.h.
|
inlineexplicit |
Constructor Tool for reading ASCII tables from streams.
regex_str | The regex for extracting the dataset name. The default is defined as "^\\s*#\\s*(\\w+)\\s*$". |
Definition at line 62 of file AsciiParser.h.
|
virtualdefault |
Default destructor.
|
overridevirtual |
Get a XYDataset object reading data from an ASCII file.
Read an ASCII file and put the data into a XYDataset object. It makes the assumption that the file only contains two columns of double values
file | Filename of the file to be read including the absolute path |
Implements Euclid::XYDataset::FileParser.
Definition at line 101 of file AsciiParser.cpp.
References std::vector< T >::begin(), std::move(), and std::transform().
|
overridevirtual |
Get the dataset name of a ASCII file.
This function gets the name of a dataset.The datatset name could be the filename or is included in the file. If the dataset is not included into the file, the filename itself is the dataset name removing the path and the extension. If the dataset name is inside the file the function looks for a line starting with a "#" character and extract the word after the hash
file | Filename of the file to be read including absolute path |
ElementException | : File not found |
Implements Euclid::XYDataset::FileParser.
Definition at line 42 of file AsciiParser.cpp.
References std::getline(), getParameter(), std::ifstream::good(), m_regex_name, Euclid::XYDataset::removeAllBeforeLastSlash(), Euclid::XYDataset::removeExtension(), and std::smatch::str().
|
overridevirtual |
Get the parameter identified by a given key_word value from a file.
This function gets the the parameter if present in the fits HDU keyword. Return an empty string if the key word is not present.
file | Filename of the file to be read including absolute path |
key_word | key word identifying the parameter |
ElementException | : File not found |
Implements Euclid::XYDataset::FileParser.
Definition at line 71 of file AsciiParser.cpp.
References std::getline(), std::ifstream::good(), and std::smatch::str().
Referenced by getName().
|
overridevirtual |
Check that the ASCII file is a dataset file(with at least one line with 2 double values)
This checking should avoid reading any files which do not contain any dataset.
file | Filename of the FITS file to be read including the absolute path. |
Implements Euclid::XYDataset::FileParser.
Definition at line 120 of file AsciiParser.cpp.
References std::string::empty(), std::getline(), and std::ifstream::good().
|
private |
Definition at line 132 of file AsciiParser.h.
Referenced by getName().