GammaLib
2.1.0.dev
|
Filename class. More...
#include <GFilename.hpp>
Public Member Functions | |
GFilename (void) | |
Void constructor. More... | |
GFilename (const std::string &filename) | |
Filename constructor. More... | |
GFilename (const char *filename) | |
Filename constructor. More... | |
GFilename (const GFilename &filename) | |
Copy constructor. More... | |
virtual | ~GFilename (void) |
Destructor. More... | |
GFilename & | operator= (const GFilename &filename) |
Assignment operator. More... | |
void | clear (void) |
Clear file name. More... | |
GFilename * | clone (void) const |
Clone file name. More... | |
std::string | classname (void) const |
Return class name. More... | |
bool | is_empty (void) const |
Signal if filename is empty. More... | |
int | length (void) const |
Return length of filename. More... | |
std::string | url (void) const |
Return Uniform Resource Locator (URL) More... | |
std::string | protocol (void) const |
Return access protocol. More... | |
std::string | path (void) const |
Return access path. More... | |
std::string | file (void) const |
Return name of file. More... | |
std::string | type (void) const |
Return file type. More... | |
bool | exists (void) const |
Checks whether file exists. More... | |
bool | is_fits (void) const |
Checks whether file is a FITS file. More... | |
void | remove (void) const |
Remove file from disk. More... | |
std::string | extname (const std::string &defaultname="") const |
Return extension name. More... | |
const std::string & | expression (void) const |
Return expression name. More... | |
int | extno (const int &defaultno=-1) const |
Return extension number. More... | |
int | extver (const int &defaultver=0) const |
Return extension version number. More... | |
bool | has_extname (void) const |
Signal if filename has an extension name. More... | |
bool | has_extno (void) const |
Signal if filename has an extension number. More... | |
bool | has_extver (void) const |
Signal if filename has an extension version. More... | |
bool | has_expression (void) const |
Signal if filename has an expression. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print file name information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GFilename &filename) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_filename (const std::string &filename) |
Set file name. More... | |
Protected Attributes | |
std::string | m_filename |
Full file name. More... | |
std::string | m_url |
File name (with stripped extension info) More... | |
std::string | m_protocol |
Access protocol. More... | |
std::string | m_path |
Access path. More... | |
std::string | m_file |
Name of file. More... | |
std::string | m_extname |
Extension name ("": not set) More... | |
int | m_extno |
Extension number (-1: not set) More... | |
int | m_extver |
Extension version (0: not set) More... | |
std::string | m_expression |
Selection expression ("": not set) More... | |
Friends | |
std::string | operator+ (const GFilename &filename, const std::string &string) |
String addition operator. More... | |
std::string | operator+ (const std::string &string, const GFilename &filename) |
String addition operator. More... | |
bool | operator== (const GFilename &a, const GFilename &b) |
Filename equality operator. More... | |
bool | operator!= (const GFilename &a, const GFilename &b) |
Filename inequality operator. More... | |
Filename class.
This class handles filenames. A filename is a string composed of an optional protocol (http:, ftp:, file:), an absolute or relative access path, a file, and optionally a FITS extension. Examples of valid file names are
myfits.fits myfile.fits[EVENTS] ./data/myfile.fits ~/data/myfile.fits /home/myuser/data/myfile.fits http://www.irap.omp.eu/data/myfile.fits ftp://www.irap.omp.eu/data/myfile.fits file:///home/myuser/data/myfile.fits
A filename without the optional FITS extension is called a Uniform Resource Locator (URL) an is accessed using the url() method. The URL can be decomposed into the protocol, access path and the filename using the protocol(), path(), and file().
The FITS extension is implemente using the GFitsExtension class.
Definition at line 62 of file GFilename.hpp.
GFilename::GFilename | ( | void | ) |
Void constructor.
Definition at line 65 of file GFilename.cpp.
References init_members().
Referenced by clone().
GFilename::GFilename | ( | const std::string & | filename | ) |
Filename constructor.
[in] | filename | File name. |
Constructs GFilename object by assigning a filename
.
Definition at line 82 of file GFilename.cpp.
References init_members(), and set_filename().
GFilename::GFilename | ( | const char * | filename | ) |
Filename constructor.
[in] | filename | File name. |
Constructs GFilename object by assigning a filename
.
Definition at line 102 of file GFilename.cpp.
References init_members(), and set_filename().
GFilename::GFilename | ( | const GFilename & | filename | ) |
Copy constructor.
[in] | filename | File name. |
Definition at line 120 of file GFilename.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 148 of file GFilename.hpp.
|
virtual |
Clear file name.
Implements GBase.
Definition at line 188 of file GFilename.cpp.
References free_members(), and init_members().
Referenced by GFits::copy_members(), GModelSpatialDiffuseCube::cube(), GCOMModelDRM::init_members(), GMWLObservation::init_members(), GCTAAeffPerfTable::init_members(), GCTABackgroundPerfTable::init_members(), GEphemerides::init_members(), GXmlDocument::init_members(), GSPIObservation::init_members(), GCTACubeBackground::init_members(), GCTAAeffArf::init_members(), GSkyRegions::init_members(), GCTABackground2D::init_members(), GCTABackground3D::init_members(), GModelTemporalLightCurve::init_members(), GCTAAeff2D::init_members(), GCTAPsfPerfTable::init_members(), GCTAModelSkyCube::init_members(), GCTACubeExposure::init_members(), GCTAPsfVector::init_members(), GModelSpatialDiffuseMap::init_members(), GCTAModelSpatialLookup::init_members(), GModelSpectralTable::init_members(), GCTAPsfTable::init_members(), GCTAEdispRmf::init_members(), GCTAEventList::init_members(), GCTAPsf2D::init_members(), GCTACubePsf::init_members(), GRmf::init_members(), GCTACubeEdisp::init_members(), GSPIResponse::init_members(), GGti::init_members(), GCTAPsfKing::init_members(), GArf::init_members(), GCTAEdispPerfTable::init_members(), GModelSpectralFunc::init_members(), GModelSpatialDiffuseCube::init_members(), GLog::init_members(), GModelTemporalPhaseCurve::init_members(), GFits::init_members(), GCTAEdisp2D::init_members(), GPha::init_members(), GCTAObservation::init_members(), GCOMObservation::init_members(), and set_filename().
|
virtual |
Clone file name.
Implements GBase.
Definition at line 206 of file GFilename.cpp.
References GFilename().
|
protected |
Copy class members.
[in] | filename | File name. |
Definition at line 562 of file GFilename.cpp.
References m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, and m_url.
Referenced by GFilename(), and operator=().
bool GFilename::exists | ( | void | ) | const |
Checks whether file exists.
Checks whether a file exists on disk. In case that the file is a FITS file, the method also checks whether a compressed version of the file (with a .gz, .Z, .z, or .zip extension) exists on disk (see is_fits() method).
Definition at line 223 of file GFilename.cpp.
References is_fits(), and url().
Referenced by GCaldb::cifname(), GCTAEdisp2D::fetch(), GCTAResponseIrf::irf_filename(), GCOMInstChars::load(), GCOMD1Response::load(), GCOMD2Response::load(), GCOMResponse::load(), GXml::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), GCOMObservation::read(), GDaemon::recover_valid_xml(), remove(), GCsv::save(), GFits::saveto(), GDaemon::update_statistics(), and GCOMObservation::write().
|
inline |
Return expression name.
Definition at line 243 of file GFilename.hpp.
References m_expression.
std::string GFilename::extname | ( | const std::string & | defaultname = "" | ) | const |
Return extension name.
[in] | defaultname | Default extension name (default: ""). |
Returns the extension name. If no extension name is given the name provided by the defaultname
argument will be used. By default, the defaultname
parameter is an empty string.
Definition at line 385 of file GFilename.cpp.
References has_extname(), and m_extname.
Referenced by GCTAEventList::fetch(), GCTAEdisp2D::fetch(), GMWLSpectrum::load(), GCTAAeffArf::load(), GCTAPsfVector::load(), GCTABackground3D::load(), GCTABackground2D::load(), GCTAAeff2D::load(), GCTAPsf2D::load(), GCTAPsfKing::load(), GCTAPsfTable::load(), GGti::load(), GCTAModelSpatialLookup::load(), GEnergies::load(), GNodeArray::load(), GEbounds::load(), GSkyMap::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), GCTAEventList::read(), GCTAObservation::read(), GCOMIaq::save(), GCTABackground2D::save(), GCTABackground3D::save(), GGti::save(), GCTAAeff2D::save(), GCTAModelSpatialLookup::save(), GEnergies::save(), GNodeArray::save(), GEbounds::save(), GCTAPsf2D::save(), GCTAPsfTable::save(), GCTAPsfKing::save(), GCTAObservation::save(), GCOMDri::save(), GCTAEdisp2D::save(), GSkyMap::save(), set_filename(), and GCTAEventList::write().
int GFilename::extno | ( | const int & | defaultno = -1 | ) | const |
Return extension number.
[in] | defaultno | Default extension number (default: -11). |
Returns the extension number. If no extension number is given the number provided by the defaultno
argument will be used. By default, the defaultno
parameter is set to -1.
Definition at line 410 of file GFilename.cpp.
References has_extno(), and m_extno.
Referenced by GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), and GSkyMap::load().
int GFilename::extver | ( | const int & | defaultver = 0 | ) | const |
Return extension version number.
[in] | defaultver | Default extension version number (default: 0). |
Returns the extension version number. If no extension version number is given the number provided by the defaultver
argument will be used. By default, the defaultextver
parameter is set to 0.
Definition at line 435 of file GFilename.cpp.
References has_extver(), and m_extver.
Referenced by set_filename().
|
inline |
Return name of file.
Returns the name of the file.
Definition at line 231 of file GFilename.hpp.
References gammalib::expand_env(), and m_file.
Referenced by type(), and gammalib::xml_file_reduce().
|
protected |
Delete class members.
Definition at line 583 of file GFilename.cpp.
Referenced by clear(), operator=(), and ~GFilename().
|
inline |
Signal if filename has an expression.
Definition at line 291 of file GFilename.hpp.
References m_expression.
Referenced by print(), and GCTAEventList::read().
|
inline |
Signal if filename has an extension name.
Definition at line 255 of file GFilename.hpp.
References m_extname.
Referenced by extname(), GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), GSkyMap::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), print(), GCOMIaq::save(), GCTAObservation::save(), and GSkyMap::save().
|
inline |
Signal if filename has an extension number.
Definition at line 267 of file GFilename.hpp.
References m_extno.
Referenced by extno(), GMWLSpectrum::load(), GCTAModelSpatialLookup::load(), GSkyMap::load(), and print().
|
inline |
Signal if filename has an extension version.
Definition at line 279 of file GFilename.hpp.
References m_extver.
|
protected |
Initialise class members.
Definition at line 539 of file GFilename.cpp.
References m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, and m_url.
Referenced by clear(), GFilename(), and operator=().
|
inline |
Signal if filename is empty.
Definition at line 160 of file GFilename.hpp.
References m_filename.
Referenced by GCTAEventList::fetch(), GCTAEdisp2D::fetch(), GModelSpatialDiffuseCube::fetch_cube(), GCOMInstChars::load(), GCOMD1Response::load(), GCOMD2Response::load(), GCOMResponse::load(), GModelSpatialDiffuseMap::load(), GCTAModelSpatialLookup::load(), GModelSpectralTable::load(), GCTAResponseIrf::load(), GCOMObservation::load_drb(), GCOMObservation::load_drw(), GModelTemporalLightCurve::load_nodes(), GModelSpectralFunc::load_nodes(), GModelTemporalPhaseCurve::load_nodes(), GCOMStatus::load_status(), GSPIObservation::print(), GCTAEventList::print(), GCOMObservation::print(), GGti::print(), GCTAEventList::read(), GSPIObservation::write(), GCTAResponseIrf::write(), GCTAObservation::write(), GGti::write(), GCOMObservation::write(), gammalib::xml_file_expand(), and gammalib::xml_file_reduce().
bool GFilename::is_fits | ( | void | ) | const |
Checks whether file is a FITS file.
Test if the file or a compressed version of the file (with a .gz, .Z, .z, or .zip extension) is a FITS file. This method is thread safe.
Definition at line 313 of file GFilename.cpp.
References url().
Referenced by exists(), GEphemerides::fetch_data(), GApplication::gCO2e(), GPulsar::load(), GCOMResponse::load(), GCTAResponseIrf::load_aeff(), GCTAResponseIrf::load_background(), GCTAResponseIrf::load_edisp(), GCTAResponseIrf::load_psf(), and GCOMObservation::read().
|
inline |
Return length of filename.
Returns the length of the filename, excluding any FITS extension.
Definition at line 174 of file GFilename.hpp.
References m_url.
Referenced by GCTAObservation::has_events(), and set_filename().
Assignment operator.
[in] | filename | File name. |
Definition at line 158 of file GFilename.cpp.
References copy_members(), free_members(), and init_members().
|
inline |
Return access path.
Returns the access path of the file.
Definition at line 217 of file GFilename.hpp.
References gammalib::expand_env(), and m_path.
Referenced by GSPIResponse::load_irfs(), gammalib::spi_hdu(), gammalib::spi_num_hdus(), gammalib::xml_file_expand(), and gammalib::xml_file_reduce().
Print file name information.
[in] | chatter | Chattiness (default: NORMAL). |
Implements GBase.
Definition at line 456 of file GFilename.cpp.
References has_expression(), has_extname(), has_extno(), has_extver(), m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, m_url, gammalib::parformat(), SILENT, and gammalib::str().
|
inline |
Return access protocol.
Returns the access protocol of the file.
Definition at line 203 of file GFilename.hpp.
References gammalib::expand_env(), and m_protocol.
void GFilename::remove | ( | void | ) | const |
Remove file from disk.
Removes file or a compressed version of the file (with a .gz, .Z, .z, or .zip extension) if it exists on disk.
Definition at line 345 of file GFilename.cpp.
References exists(), and url().
Referenced by GFits::open(), and GFits::saveto().
|
protected |
Set file name.
[in] | filename | File name. |
GException::invalid_argument | Invalid file name specified. |
Sets all attributes of the object by parsing the file name. The file name can have one of the following formats:
file.fits No extension file.fits[1] Extension number 1 (starting from 0) file.fits[EVENTS] EVENTS extension file.fits[EVENTS,2] Version 2 of the EVENTS extension
Definition at line 606 of file GFilename.cpp.
References clear(), extname(), extver(), G_SET_FILENAME, length(), m_expression, m_extname, m_extno, m_extver, m_file, m_filename, m_path, m_protocol, m_url, gammalib::strip_whitespace(), gammalib::toint(), and gammalib::toupper().
Referenced by GFilename().
std::string GFilename::type | ( | void | ) | const |
Return file type.
Returns the file type based on the file extension name. Possible file types are
Type Extension names fits .fits / .fit
For any other file types an empty string will be returned. Any compression extensions such as .gz
, .Z
, .z
or .zip
will be stripped.
Definition at line 264 of file GFilename.cpp.
References file(), and m_file.
Referenced by GObservations::likelihood::save().
|
inline |
Return Uniform Resource Locator (URL)
Returns the Uniform Resource Locator without FITS extension. Any environment variable in the URL string will be expanded.
Definition at line 189 of file GFilename.hpp.
References gammalib::expand_env(), and m_url.
Referenced by GDaemon::alive(), GDaemon::create_lock_file(), GDaemon::create_xml(), GDaemon::delete_lock_file(), exists(), GEphemerides::fetch_data(), gammalib::host_country(), is_fits(), GCTABackgroundPerfTable::load(), GCTAAeffPerfTable::load(), GCTAPsfPerfTable::load(), GPulsar::load(), GSkyRegions::load(), GCsv::load(), GApplicationPars::load(), GCTAEdispPerfTable::load(), GCTAModelSpatialLookup::load(), GRmf::load(), GArf::load(), GCTAObservation::load(), GObservations::load(), GPha::load(), GModels::load(), GXml::load(), GPulsar::load_fits(), GSPIResponse::load_irf(), GSPIResponse::load_irfs(), GModelSpectralFunc::load_nodes(), GPulsar::load_parfile(), GPulsar::load_psrtime(), GDaemon::lock_pid(), GLog::open(), GFits::open(), GLog::operator<<(), GEphemerides::print(), GSPIObservation::print(), GModelTemporalLightCurve::print(), GModelSpectralTable::print(), GSPIResponse::print(), GModelSpectralFunc::print(), GModelTemporalPhaseCurve::print(), GSPIEventCube::read(), GMWLSpectrum::read(), GSPIEventCube::read_models(), GDaemon::recover_valid_xml(), remove(), GCOMIaq::save(), GCOMTim::save(), GResponseVectorCache::save(), GCTAEventList::save(), GSkyRegions::save(), GCsv::save(), GCTABackground2D::save(), GApplicationPars::save(), GCTABackground3D::save(), GCTAAeff2D::save(), GGti::save(), GCTAModelSpatialLookup::save(), GRmf::save(), GEnergies::save(), GModelSpectralTable::save(), GArf::save(), GNodeArray::save(), GEbounds::save(), GCTAPsf2D::save(), GCTAPsfTable::save(), GCTAPsfKing::save(), GCTAObservation::save(), GPha::save(), GCTAEdisp2D::save(), GSkyMap::save(), GXml::save(), GFits::saveto(), GDaemon::update_host_country(), GDaemon::update_statistics(), GCTAObservation::write(), GDaemon::write_heartbeat(), and GApplication::write_statistics().
Filename inequality operator.
[in] | a | First filename. |
[in] | b | Second filename. |
Definition at line 347 of file GFilename.hpp.
|
friend |
String addition operator.
[in] | filename | Filename. |
[in] | string | String. |
Definition at line 305 of file GFilename.hpp.
|
friend |
String addition operator.
[in] | string | String. |
[in] | filename | Filename. |
Definition at line 319 of file GFilename.hpp.
Filename equality operator.
[in] | a | First filename. |
[in] | b | Second filename. |
Definition at line 333 of file GFilename.hpp.
|
protected |
Selection expression ("": not set)
Definition at line 124 of file GFilename.hpp.
Referenced by copy_members(), expression(), has_expression(), init_members(), print(), and set_filename().
|
protected |
Extension name ("": not set)
Definition at line 121 of file GFilename.hpp.
Referenced by copy_members(), extname(), has_extname(), init_members(), print(), and set_filename().
|
protected |
Extension number (-1: not set)
Definition at line 122 of file GFilename.hpp.
Referenced by copy_members(), extno(), has_extno(), init_members(), print(), and set_filename().
|
protected |
Extension version (0: not set)
Definition at line 123 of file GFilename.hpp.
Referenced by copy_members(), extver(), has_extver(), init_members(), print(), and set_filename().
|
protected |
Name of file.
Definition at line 120 of file GFilename.hpp.
Referenced by copy_members(), file(), init_members(), print(), set_filename(), and type().
|
protected |
Full file name.
Definition at line 116 of file GFilename.hpp.
Referenced by copy_members(), init_members(), is_empty(), print(), and set_filename().
|
protected |
Access path.
Definition at line 119 of file GFilename.hpp.
Referenced by copy_members(), init_members(), path(), print(), and set_filename().
|
protected |
Access protocol.
Definition at line 118 of file GFilename.hpp.
Referenced by copy_members(), init_members(), print(), protocol(), and set_filename().
|
protected |
File name (with stripped extension info)
Definition at line 117 of file GFilename.hpp.
Referenced by copy_members(), init_members(), length(), print(), set_filename(), and url().