GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsHDU Class Referenceabstract

Abstract FITS extension base class. More...

#include <GFitsHDU.hpp>

Inheritance diagram for GFitsHDU:
GBase GFitsImage GFitsTable GFitsImageByte GFitsImageDouble GFitsImageFloat GFitsImageLong GFitsImageLongLong GFitsImageSByte GFitsImageShort GFitsImageULong GFitsImageUShort GFitsAsciiTable GFitsBinTable

Public Types

enum  HDUType { HT_IMAGE = 0, HT_ASCII_TABLE = 1, HT_BIN_TABLE = 2 }
 

Public Member Functions

 GFitsHDU (void)
 Void constructor. More...
 
 GFitsHDU (const GFitsHDU &hdu)
 Copy constructor. More...
 
virtual ~GFitsHDU (void)
 Destructor. More...
 
GFitsHDUoperator= (const GFitsHDU &hdu)
 Assignment operator. More...
 
virtual void clear (void)=0
 Clear object. More...
 
virtual GFitsHDUclone (void) const =0
 Clones object. More...
 
virtual std::string classname (void) const =0
 Return class name. More...
 
virtual HDUType exttype (void) const =0
 
virtual std::string print (const GChatter &chatter=NORMAL) const =0
 Print content of object. More...
 
int cards (void) const
 Return number of cards in HDU header. More...
 
const std::string & extname (void) const
 Return extension name. More...
 
void extname (const std::string &extname)
 Set HDU extension name (EXTNAME keyword) More...
 
const int & extno (void) const
 Return extension number. More...
 
void extno (const int &extno)
 Set extension number. More...
 
const GFitsHeaderheader (void) const
 Return extension header. More...
 
void header (const GFitsHeader &header)
 Set extension header. More...
 
bool has_card (const int &cardno) const
 Check existence of header card. More...
 
bool has_card (const std::string &keyname) const
 Checks for presence of header card. More...
 
GFitsHeaderCardcard (const int &cardno)
 Return header card. More...
 
const GFitsHeaderCardcard (const int &cardno) const
 Return header card (const version) More...
 
GFitsHeaderCardcard (const std::string &keyname)
 Return header card. More...
 
const GFitsHeaderCardcard (const std::string &keyname) const
 Return header card (const version) More...
 
void card (const GFitsHeaderCard &card)
 Append or update header card. More...
 
void card (const std::string &keyname, const std::string &value, const std::string &comment)
 Append or update string value header card. More...
 
void card (const std::string &keyname, const double &value, const std::string &comment)
 Append or update double precision value header card. More...
 
void card (const std::string &keyname, const int &value, const std::string &comment)
 Append or update integer value header card. More...
 
void card (const std::string &keyname, const bool &value, const std::string &comment)
 Append or update boolean value header card. More...
 
void card (const std::string &keyname, const char *value, const std::string &comment)
 Append or update character value header card. More...
 
std::string string (const std::string &keyname) const
 Return card value as string. More...
 
double real (const std::string &keyname) const
 Return card value as double precision. More...
 
int integer (const std::string &keyname) const
 Return card value as integer. 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 GFitsHDU &hdu)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void connect (void *fptr)
 Connect HDU to FITS file. More...
 
void move_to_hdu (void)
 Move FITS file pointer to HDU. More...
 
HDUType get_hdu_type (void) const
 Get HDU type from FITS file. More...
 
void open (void *vptr, int hdunum)
 Open HDU. More...
 
void save (void)
 Saves HDU. More...
 
std::string print_hdu (const GChatter &chatter=NORMAL) const
 Print basic HDU information. More...
 
std::string typecode (int type) const
 Return typecode as string. More...
 
virtual void data_open (void *vptr)=0
 
virtual void data_save (void)=0
 
virtual void data_close (void)=0
 
virtual void data_connect (void *vptr)=0
 

Protected Attributes

void * m_fitsfile
 FITS file pointer pointing on actual HDU. More...
 
int m_hdunum
 HDU number (starting from 0) More...
 
std::string m_name
 HDU name (extname) More...
 
GFitsHeader m_header
 HDU header. More...
 

Friends

class GFits
 

Detailed Description

Abstract FITS extension base class.

This class defines the abstract interface for a FITS extension, also known as Header Data Unit (HDU). Each HDU consists of a header and a data area. The header is composed of cards and is implemented by the GFitsHeader class. The data are is either an image or a table which are implemented as derived classes from GFitsHDU.

Todo:
Implement GFitsHDU* select(const std::string& expr) that applies to a table HDU for row selection.

Definition at line 51 of file GFitsHDU.hpp.

Member Enumeration Documentation

Enumerator
HT_IMAGE 
HT_ASCII_TABLE 
HT_BIN_TABLE 

Definition at line 66 of file GFitsHDU.hpp.

Constructor & Destructor Documentation

GFitsHDU::GFitsHDU ( void  )

Void constructor.

Definition at line 72 of file GFitsHDU.cpp.

References init_members().

GFitsHDU::GFitsHDU ( const GFitsHDU hdu)

Copy constructor.

Parameters
[in]hduHDU from which the instance should be constructed.

Definition at line 87 of file GFitsHDU.cpp.

References copy_members(), and init_members().

GFitsHDU::~GFitsHDU ( void  )
virtual

Destructor.

Definition at line 103 of file GFitsHDU.cpp.

References free_members().

Member Function Documentation

GFitsHeaderCard & GFitsHDU::card ( const int &  cardno)
inline
const GFitsHeaderCard & GFitsHDU::card ( const int &  cardno) const
inline

Return header card (const version)

Parameters
[in]cardnoNumber of card in header.
Returns
Header card.

Definition at line 272 of file GFitsHDU.hpp.

References GFitsHeader::at(), and m_header.

GFitsHeaderCard & GFitsHDU::card ( const std::string &  keyname)
inline

Return header card.

Parameters
[in]keynameName of header card.
Returns
Header card.

Definition at line 285 of file GFitsHDU.hpp.

References GFitsHeader::at(), and m_header.

const GFitsHeaderCard & GFitsHDU::card ( const std::string &  keyname) const
inline

Return header card (const version)

Parameters
[in]keynameName of header card.
Returns
Header card.

Definition at line 298 of file GFitsHDU.hpp.

References GFitsHeader::at(), and m_header.

void GFitsHDU::card ( const GFitsHeaderCard card)
inline

Append or update header card.

Parameters
[in]cardHeader card.

Definition at line 310 of file GFitsHDU.hpp.

References GFitsHeader::append(), and m_header.

void GFitsHDU::card ( const std::string &  keyname,
const std::string &  value,
const std::string &  comment 
)
inline

Append or update string value header card.

Parameters
[in]keynameName of the header card.
[in]valueString value of the header card.
[in]commentComment of the header card.

Definition at line 325 of file GFitsHDU.hpp.

References GFitsHeader::append(), card(), and m_header.

void GFitsHDU::card ( const std::string &  keyname,
const double &  value,
const std::string &  comment 
)
inline

Append or update double precision value header card.

Parameters
[in]keynameName of the header card.
[in]valueDouble precision value of the header card.
[in]commentComment of the header card.

Definition at line 342 of file GFitsHDU.hpp.

References GFitsHeader::append(), card(), and m_header.

void GFitsHDU::card ( const std::string &  keyname,
const int &  value,
const std::string &  comment 
)
inline

Append or update integer value header card.

Parameters
[in]keynameName of the header card.
[in]valueInteger value of the header card.
[in]commentComment of the header card.

Definition at line 359 of file GFitsHDU.hpp.

References GFitsHeader::append(), card(), and m_header.

void GFitsHDU::card ( const std::string &  keyname,
const bool &  value,
const std::string &  comment 
)
inline

Append or update boolean value header card.

Parameters
[in]keynameName of the header card.
[in]valueBoolean value of the header card.
[in]commentComment of the header card.

Definition at line 376 of file GFitsHDU.hpp.

References GFitsHeader::append(), card(), and m_header.

void GFitsHDU::card ( const std::string &  keyname,
const char *  value,
const std::string &  comment 
)
inline

Append or update character value header card.

Parameters
[in]keynameName of the header card.
[in]valueCharacter value of the header card.
[in]commentComment of the header card.

Definition at line 393 of file GFitsHDU.hpp.

References GFitsHeader::append(), card(), m_header, and string().

int GFitsHDU::cards ( void  ) const
inline

Return number of cards in HDU header.

Returns
Number of cards in HDU header.

Returns the number of cards in the header of the FITS extension.

Definition at line 148 of file GFitsHDU.hpp.

References m_header, and GFitsHeader::size().

virtual std::string GFitsHDU::classname ( void  ) const
pure virtual

Return class name.

Returns
String containing the class name.

Returns the class name for non-abstract classes in a human readable way.

Implements GBase.

Implemented in GFitsImageByte, GFitsImageDouble, GFitsImageFloat, GFitsImageLong, GFitsImageLongLong, GFitsImageSByte, GFitsImageShort, GFitsImageULong, GFitsImageUShort, GFitsTable, GFitsImage, GFitsAsciiTable, and GFitsBinTable.

virtual void GFitsHDU::clear ( void  )
pure virtual

Clear object.

Sets the object to a clean initial state. After calling the method the object will be in the same state as it were if an empty instance of the object would have been created.

Implements GBase.

Implemented in GFitsImageByte, GFitsImageDouble, GFitsImageFloat, GFitsImageLong, GFitsImageLongLong, GFitsImageSByte, GFitsImageShort, GFitsImageULong, GFitsImageUShort, GFitsTable, GFitsImage, GFitsAsciiTable, and GFitsBinTable.

virtual GFitsHDU* GFitsHDU::clone ( void  ) const
pure virtual

Clones object.

Returns
Pointer to deep copy of object.

Creates a deep copy of the object and returns a pointer to the object.

Implements GBase.

Implemented in GFitsImageByte, GFitsImageDouble, GFitsImageFloat, GFitsImageLong, GFitsImageLongLong, GFitsImageSByte, GFitsImageShort, GFitsImageULong, GFitsImageUShort, GFitsTable, GFitsImage, GFitsAsciiTable, and GFitsBinTable.

Referenced by GFits::append(), GFits::insert(), and GFits::set().

void GFitsHDU::connect ( void *  vptr)
protected

Connect HDU to FITS file.

Parameters
[in]vptrFITS file pointer.

Connects the HDU to the file specified by the FITS file pointer. Sets also the HDU number (or extension number, starting from 0). This method does nothing if the file pointer in not valid.

Definition at line 192 of file GFitsHDU.cpp.

References data_connect(), FPTR, FPTR_COPY, m_fitsfile, and m_hdunum.

Referenced by GFits::append(), GFits::extend(), and GFits::insert().

void GFitsHDU::copy_members ( const GFitsHDU hdu)
protected

Copy class members.

Parameters
[in]hduHDU to be copied.

Assumes that all memory has been freed correctly before calling.

Definition at line 489 of file GFitsHDU.cpp.

References FPTR_COPY, m_fitsfile, m_hdunum, m_header, and m_name.

Referenced by GFitsHDU(), and operator=().

virtual void GFitsHDU::data_close ( void  )
protectedpure virtual

Implemented in GFitsTable, and GFitsImage.

virtual void GFitsHDU::data_connect ( void *  vptr)
protectedpure virtual

Implemented in GFitsTable, and GFitsImage.

Referenced by connect().

virtual void GFitsHDU::data_open ( void *  vptr)
protectedpure virtual

Implemented in GFitsTable, and GFitsImage.

Referenced by open().

virtual void GFitsHDU::data_save ( void  )
protectedpure virtual

Implemented in GFitsTable, and GFitsImage.

Referenced by save().

void GFitsHDU::extname ( const std::string &  extname)

Set HDU extension name (EXTNAME keyword)

Parameters
[in]extnameName of HDU.

This method sets the extension name of the HDU. The extension name will be saved in the 'EXTNAME' header keyword. The header attached to the HDU will be automatically updated by this method.

Definition at line 160 of file GFitsHDU.cpp.

References GFitsHeader::append(), extname(), m_header, and m_name.

const int & GFitsHDU::extno ( void  ) const
inline

Return extension number.

Returns
Extension number (starting from 0 for the primary image).

Returns the number of the FITS extension.

Definition at line 176 of file GFitsHDU.hpp.

References m_hdunum.

Referenced by GFits::append(), GFits::extend(), extno(), and GFits::insert().

void GFitsHDU::extno ( const int &  extno)
inline

Set extension number.

Parameters
[in]extnoExtension number (starting from 0 for the primary image).

Set the number of the FITS extension.

Definition at line 190 of file GFitsHDU.hpp.

References extno(), and m_hdunum.

GFitsHDU::HDUType GFitsHDU::get_hdu_type ( void  ) const
protected

Get HDU type from FITS file.

Exceptions
GException::runtime_errorNo FITS file has been opened.

Definition at line 245 of file GFitsHDU.cpp.

References __ffghdt, FPTR, G_GET_HDU_TYPE, and m_fitsfile.

bool GFitsHDU::has_card ( const std::string &  keyname) const
inline

Checks for presence of header card.

Parameters
[in]keynameName of header card.
Returns
True if card with specified keyname exists in header.

Definition at line 246 of file GFitsHDU.hpp.

References GFitsHeader::contains(), and m_header.

const GFitsHeader & GFitsHDU::header ( void  ) const
inline

Return extension header.

Returns
Extension header.

Returns the extension header.

Definition at line 205 of file GFitsHDU.hpp.

References m_header.

Referenced by header(), GRmf::read(), GArf::read(), GPha::read(), GLATEventCube::read_gti(), GCOMIaq::remove_cards(), and GFitsTable::update_header().

void GFitsHDU::header ( const GFitsHeader header)
inline

Set extension header.

Parameters
[in]headerExtension header.

Sets the extension header.

Definition at line 219 of file GFitsHDU.hpp.

References header(), and m_header.

void GFitsHDU::init_members ( void  )
protected
void GFitsHDU::move_to_hdu ( void  )
protected

Move FITS file pointer to HDU.

Exceptions
GException::runtime_errorNo FITS file has been opened.

Moves FITS file pointer to the actual HDU. This operation should preceed any FITS file manipulation.

Definition at line 222 of file GFitsHDU.cpp.

References gammalib::fits_move_to_hdu(), FPTR, G_MOVE_TO_HDU, m_fitsfile, and m_hdunum.

Referenced by GFitsImage::load_image().

void GFitsHDU::open ( void *  vptr,
int  hdunum 
)
protected

Open HDU.

Parameters
[in]vptrFITS file pointer.
[in]hdunumNumber of HDU (starting from 0).
Exceptions
GException::invalid_argumentFITS file pointer does not point to an open FITS file
GException::fits_errorUnable to open FITS HDU.

Opens an (existing) HDU in the FITS file. This method does NOT create any HDU if it does not exist. Opening consists of fetching all header cards (by opening an associated GFitsHeader instance) and of opening the data area (which can be of type Image or Table)

Definition at line 285 of file GFitsHDU.cpp.

References GFitsHeader::contains(), data_open(), gammalib::fits_move_to_hdu(), FPTR, FPTR_COPY, G_OPEN, GFitsHeader::load(), m_fitsfile, m_hdunum, m_header, m_name, GFitsHeader::string(), and gammalib::strip_whitespace().

Referenced by GFits::new_primary(), and GFits::open().

GFitsHDU & GFitsHDU::operator= ( const GFitsHDU hdu)

Assignment operator.

Parameters
[in]hduHDU which should be assigned.

Definition at line 124 of file GFitsHDU.cpp.

References copy_members(), free_members(), and init_members().

Referenced by GFitsTable::operator=(), and GFitsImage::operator=().

virtual std::string GFitsHDU::print ( const GChatter chatter = NORMAL) const
pure virtual

Print content of object.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing the content of the object.

Formats the content in a standard way and puts this content in a C++ string that is returned.

Implements GBase.

Implemented in GFitsImage, and GFitsTable.

std::string GFitsHDU::print_hdu ( const GChatter chatter = NORMAL) const
protected

Print basic HDU information.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing basic HDU information.

Definition at line 373 of file GFitsHDU.cpp.

References m_hdunum, m_name, gammalib::parformat(), SILENT, and gammalib::str().

Referenced by GFitsTable::print(), and GFitsImage::print().

void GFitsHDU::save ( void  )
protected

Saves HDU.

Save the HDU to the FITS file. In case that the HDU does not exist in the file it will be created (by the save_data() method). In the special case that no first HDU exists, an empty primary image is created.

Todo:
Put the m_header.save(FPTR(m_fitsfile)) call in the data_save() methods

Definition at line 340 of file GFitsHDU.cpp.

References data_save(), FPTR, m_fitsfile, m_header, and GFitsHeader::save().

std::string GFitsHDU::typecode ( int  type) const
protected

Return typecode as string.

Parameters
[in]typeType code.

Definition at line 398 of file GFitsHDU.cpp.

References __TBIT, __TBYTE, __TDOUBLE, __TFLOAT, __TLOGICAL, __TLONG, __TLONGLONG, __TSBYTE, __TSHORT, __TSTRING, __TULONG, and __TUSHORT.

Referenced by GFitsTable::data_open(), and GFitsImage::print().

Friends And Related Function Documentation

friend class GFits
friend

Definition at line 54 of file GFitsHDU.hpp.

Member Data Documentation

int GFitsHDU::m_hdunum
protected
std::string GFitsHDU::m_name
protected

HDU name (extname)

Definition at line 135 of file GFitsHDU.hpp.

Referenced by copy_members(), extname(), init_members(), open(), and print_hdu().


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