Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Euclid::XYDataset::AsciiParser Class Reference

Tool for reading ASCII tables from streams. More...

#include <AsciiParser.h>

Inheritance diagram for Euclid::XYDataset::AsciiParser:
Inheritance graph
[legend]
Collaboration diagram for Euclid::XYDataset::AsciiParser:
Collaboration graph
[legend]

Public Member Functions

 AsciiParser (const std::string &regex_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< XYDatasetgetDataset (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.
 
- Public Member Functions inherited from Euclid::XYDataset::FileParser
virtual ~FileParser ()=default
 Default destructor.
 

Private Attributes

std::string m_regex_name
 

Detailed Description

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.

Exceptions
ElementException: File not found

Definition at line 53 of file AsciiParser.h.

Constructor & Destructor Documentation

◆ AsciiParser()

Euclid::XYDataset::AsciiParser::AsciiParser ( const std::string regex_str = "^\\s*#\\s*(\\w+)\\s*$")
inlineexplicit

Constructor Tool for reading ASCII tables from streams.

Parameters
regex_strThe regex for extracting the dataset name. The default is defined as "^\\s*#\\s*(\\w+)\\s*$".

Definition at line 62 of file AsciiParser.h.

◆ ~AsciiParser()

virtual Euclid::XYDataset::AsciiParser::~AsciiParser ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ getDataset()

std::unique_ptr< XYDataset > Euclid::XYDataset::AsciiParser::getDataset ( const std::string file)
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

Parameters
fileFilename of the file to be read including the absolute path
Returns
A unique pointer to a XYDatatset object or null pointer.

Implements Euclid::XYDataset::FileParser.

Definition at line 101 of file AsciiParser.cpp.

References std::vector< T >::begin(), std::move(), and std::transform().

Here is the call graph for this function:

◆ getName()

std::string Euclid::XYDataset::AsciiParser::getName ( const std::string file)
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

Parameters
fileFilename of the file to be read including absolute path
Returns
The name of the datatset
Exceptions
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().

Here is the call graph for this function:

◆ getParameter()

std::string Euclid::XYDataset::AsciiParser::getParameter ( const std::string file,
const std::string key_word 
)
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.

Parameters
fileFilename of the file to be read including absolute path
key_wordkey word identifying the parameter
Returns
The name of the datatset
Exceptions
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().

Here is the call graph for this function:

◆ isDatasetFile()

bool Euclid::XYDataset::AsciiParser::isDatasetFile ( const std::string file)
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.

Parameters
fileFilename of the FITS file to be read including the absolute path.
Returns
true if it is a FITS file with dataset(at least with one HDU table)

Implements Euclid::XYDataset::FileParser.

Definition at line 120 of file AsciiParser.cpp.

References std::string::empty(), std::getline(), and std::ifstream::good().

Here is the call graph for this function:

Member Data Documentation

◆ m_regex_name

std::string Euclid::XYDataset::AsciiParser::m_regex_name
private

Definition at line 132 of file AsciiParser.h.

Referenced by getName().


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