GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFitsHeader Class Reference

Interface for FITS header class. More...

#include <GFitsHeader.hpp>

Inheritance diagram for GFitsHeader:
GContainer GBase

Public Member Functions

 GFitsHeader (void)
 Constructor. More...
 
 GFitsHeader (const GFitsHeader &header)
 Copy constructor. More...
 
virtual ~GFitsHeader (void)
 Destructor. More...
 
GFitsHeaderoperator= (const GFitsHeader &header)
 Assignment operator. More...
 
GFitsHeaderCardoperator[] (const int &cardno)
 Return header card. More...
 
const GFitsHeaderCardoperator[] (const int &cardno) const
 Return pointer to model (const version) More...
 
GFitsHeaderCardoperator[] (const std::string &keyname)
 Return header card. More...
 
const GFitsHeaderCardoperator[] (const std::string &keyname) const
 Return header card (const version) More...
 
void clear (void)
 Clear header. More...
 
GFitsHeaderclone (void) const
 Clone header. More...
 
std::string classname (void) const
 Return class name. More...
 
GFitsHeaderCardat (const int &cardno)
 Return header card. More...
 
const GFitsHeaderCardat (const int &cardno) const
 Return header card (const version) More...
 
GFitsHeaderCardat (const std::string &keyname)
 Return header card. More...
 
const GFitsHeaderCardat (const std::string &keyname) const
 Return header card (const version) More...
 
std::string string (const int &cardno) const
 Return header card value as string value. More...
 
std::string string (const std::string &keyname) const
 Return header card value as string value. More...
 
double real (const int &cardno) const
 Return header card value as double precision value. More...
 
double real (const std::string &keyname) const
 Return header card value as double precision value. More...
 
int integer (const int &cardno) const
 Return header card value as integer value. More...
 
int integer (const std::string &keyname) const
 Return header card value as integer value. More...
 
int size (void) const
 Return number of cards in header. More...
 
bool is_empty (void) const
 Signals if there are no cards in the FITS header. More...
 
GFitsHeaderCardappend (const GFitsHeaderCard &card)
 Append or update header card. More...
 
GFitsHeaderCardinsert (const int &cardno, const GFitsHeaderCard &card)
 Insert card into header. More...
 
GFitsHeaderCardinsert (const std::string &keyname, const GFitsHeaderCard &card)
 Insert card into header. More...
 
void remove (const int &cardno)
 Remove card from header. More...
 
void remove (const std::string &keyname)
 Remove card from header. More...
 
void reserve (const int &num)
 Reserves space for cards in FITS header. More...
 
void extend (const GFitsHeader &header)
 Append header. More...
 
bool contains (const int &cardno) const
 Check if card is present in header. More...
 
bool contains (const std::string &keyname) const
 Check if card is present in header. More...
 
void load (void *vptr)
 Load header from FITS file. More...
 
void save (void *vptr) const
 Save header to FITS file. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print FITS header information. More...
 
- Public Member Functions inherited from GContainer
virtual ~GContainer (void)
 Destructor. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Private Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GFitsHeader &header)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
int get_index (const std::string &keyname) const
 Get index of header card. More...
 
void update_keyname_map (void)
 Update the header card pointers. More...
 

Private Attributes

std::vector< GFitsHeaderCardm_cards
 Header cards. More...
 
std::map< std::string,
GFitsHeaderCard * > 
m_keyname_map
 Header pointers. More...
 

Detailed Description

Interface for FITS header class.

The FITS header class is a container class for header cards.

All cards of a FITS file extension will be held in memory, so no link to a FITS file is required. Cards are read from a file using the load() method, and cards are saved into a file using the save() method.

Definition at line 49 of file GFitsHeader.hpp.

Constructor & Destructor Documentation

GFitsHeader::GFitsHeader ( void  )

Constructor.

Definition at line 70 of file GFitsHeader.cpp.

References init_members().

Referenced by clone().

GFitsHeader::GFitsHeader ( const GFitsHeader header)

Copy constructor.

Parameters
headerFITS header.

Definition at line 85 of file GFitsHeader.cpp.

References copy_members(), and init_members().

GFitsHeader::~GFitsHeader ( void  )
virtual

Destructor.

Definition at line 101 of file GFitsHeader.cpp.

References free_members().

Member Function Documentation

GFitsHeaderCard & GFitsHeader::append ( const GFitsHeaderCard card)

Append or update header card.

Parameters
[in]cardHeader card.
Returns
Reference to appended header card.

If the keyname of the header card does not yet exist in the header (or if the keyname is COMMENT or HISTORY) then append the header card to the header. If the keyname exists already, the header card is updated.

Definition at line 427 of file GFitsHeader.cpp.

References get_index(), GFitsHeaderCard::keyname(), m_cards, m_keyname_map, size(), and update_keyname_map().

Referenced by GFitsHDU::card(), GFitsHDU::extname(), GFitsImage::init_image_header(), GFitsBinTable::init_table_header(), GFitsAsciiTable::init_table_header(), and GCTAOnOffObservation::set().

GFitsHeaderCard & GFitsHeader::at ( const int &  cardno)

Return header card.

Parameters
[in]cardnoNumber of card in header [0,...,size()-1]
Returns
Header card.
Exceptions
GException::out_of_rangeCard number out of range.

Definition at line 186 of file GFitsHeader.cpp.

References contains(), G_AT1, m_cards, and size().

Referenced by GFitsHDU::card(), GFitsHDU::integer(), operator[](), GFitsHDU::real(), and GFitsHDU::string().

const GFitsHeaderCard & GFitsHeader::at ( const int &  cardno) const

Return header card (const version)

Parameters
[in]cardnoNumber of card in header [0,...,size()-1]
Returns
Header card.
Exceptions
GException::out_of_rangeCard number out of range.

Definition at line 209 of file GFitsHeader.cpp.

References contains(), G_AT1, m_cards, and size().

GFitsHeaderCard & GFitsHeader::at ( const std::string &  keyname)

Return header card.

Parameters
[in]keynameName of header card
Returns
Header card.
Exceptions
GException::invalid_argumentKey name not found.

Definition at line 232 of file GFitsHeader.cpp.

References G_AT2, get_index(), and m_cards.

const GFitsHeaderCard & GFitsHeader::at ( const std::string &  keyname) const

Return header card (const version)

Parameters
[in]keynameName of header card
Returns
Header card.
Exceptions
GException::invalid_argumentKey name not found.

Definition at line 257 of file GFitsHeader.cpp.

References G_AT2, get_index(), and m_cards.

std::string GFitsHeader::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GFitsHeader").

Implements GBase.

Definition at line 113 of file GFitsHeader.hpp.

void GFitsHeader::clear ( void  )
virtual

Clear header.

Implements GBase.

Definition at line 153 of file GFitsHeader.cpp.

References free_members(), and init_members().

Referenced by GRmf::init_members(), GArf::init_members(), and GPha::init_members().

GFitsHeader * GFitsHeader::clone ( void  ) const
virtual

Clone header.

Returns
Pointer to deep copy of header.

Implements GBase.

Definition at line 171 of file GFitsHeader.cpp.

References GFitsHeader().

bool GFitsHeader::contains ( const int &  cardno) const
inline

Check if card is present in header.

Parameters
[in]cardnoNumber of card in header.
Returns
True of card exists, false otherwise.

Signals whether a card with specified card number exists in header.

Definition at line 223 of file GFitsHeader.hpp.

References size().

Referenced by at(), GFitsHDU::has_card(), integer(), GFitsHDU::open(), real(), remove(), string(), and GFitsTable::update_header().

bool GFitsHeader::contains ( const std::string &  keyname) const
inline

Check if card is present in header.

Parameters
[in]keynameName of header card.
Returns
True of card exists, false otherwise.

Signals whether a card with specified keyname exists in header.

Definition at line 238 of file GFitsHeader.hpp.

References get_index().

void GFitsHeader::copy_members ( const GFitsHeader header)
private

Copy class members.

Parameters
[in]headerFITS header.

Definition at line 765 of file GFitsHeader.cpp.

References m_cards, and update_keyname_map().

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

void GFitsHeader::extend ( const GFitsHeader header)

Append header.

Parameters
[in]headerFITS header.

Append all cards from a FITS header to the actual header.

Definition at line 600 of file GFitsHeader.cpp.

References is_empty(), m_cards, reserve(), size(), and update_keyname_map().

void GFitsHeader::free_members ( void  )
private

Delete class members.

Definition at line 781 of file GFitsHeader.cpp.

Referenced by clear(), operator=(), and ~GFitsHeader().

int GFitsHeader::get_index ( const std::string &  keyname) const
private

Get index of header card.

Parameters
[in]keynameHeader card key name.
Returns
Index of header card (-1 if keyname is not found)

Returns index of header card based on the keyname. If no header card is found, -1 is returned.

Definition at line 797 of file GFitsHeader.cpp.

References m_cards, and m_keyname_map.

Referenced by append(), at(), contains(), insert(), integer(), real(), remove(), and string().

void GFitsHeader::init_members ( void  )
private

Initialise class members.

Definition at line 749 of file GFitsHeader.cpp.

References m_cards, and m_keyname_map.

Referenced by clear(), GFitsHeader(), and operator=().

GFitsHeaderCard & GFitsHeader::insert ( const int &  cardno,
const GFitsHeaderCard card 
)

Insert card into header.

Parameters
[in]cardnoHeader card number [0,...,size()-1].
[in]cardHeader card.
Returns
Reference to inserted header card.
Exceptions
GException::out_of_rangeCard number out of range.

Inserts a card into the header before the card with the specified card number cardno.

Definition at line 465 of file GFitsHeader.cpp.

References G_INSERT1, is_empty(), m_cards, size(), and update_keyname_map().

GFitsHeaderCard & GFitsHeader::insert ( const std::string &  keyname,
const GFitsHeaderCard card 
)

Insert card into header.

Parameters
[in]keynameHeader card key name.
[in]cardHeader card.
Returns
Reference to inserted header card.
Exceptions
GException::invalid_argumentKey name not found.

Inserts a card into the header before the card with the specified keyname.

Definition at line 508 of file GFitsHeader.cpp.

References G_INSERT2, get_index(), m_cards, and update_keyname_map().

int GFitsHeader::integer ( const int &  cardno) const

Return header card value as integer value.

Parameters
[in]cardnoHeader card number [0,...,size()-1].
Returns
Header card integer value.
Exceptions
GException::out_of_rangeCard number out of range.

Definition at line 378 of file GFitsHeader.cpp.

References contains(), G_INTEGER1, m_cards, and size().

Referenced by integer().

int GFitsHeader::integer ( const std::string &  keyname) const

Return header card value as integer value.

Parameters
[in]keynameHeader card key name.
Returns
Header card integer value.
Exceptions
GException::invalid_argumentKey name not found.

Definition at line 401 of file GFitsHeader.cpp.

References G_INTEGER2, get_index(), integer(), and m_cards.

bool GFitsHeader::is_empty ( void  ) const
inlinevirtual

Signals if there are no cards in the FITS header.

Returns
True if there are no cards in the FITS header, false otherwise

Signals if there are no cards in the FITS header.

Implements GContainer.

Definition at line 193 of file GFitsHeader.hpp.

References m_cards.

Referenced by extend(), and insert().

void GFitsHeader::load ( void *  vptr)

Load header from FITS file.

Parameters
[in]vptrFITS file void pointer.
Exceptions
GException::fits_errorFITS error occured.

Loads all header cards into memory. Any header cards that existed before will be dropped.

Definition at line 639 of file GFitsHeader.cpp.

References __ffghsp, gammalib::fits_move_to_hdu(), FPTR, G_OPEN, m_cards, GFitsHeaderCard::read(), reserve(), and update_keyname_map().

Referenced by GFitsHDU::open().

GFitsHeader & GFitsHeader::operator= ( const GFitsHeader header)

Assignment operator.

Parameters
headerFITS header.
Returns
FITS header.

Definition at line 123 of file GFitsHeader.cpp.

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

GFitsHeaderCard & GFitsHeader::operator[] ( const int &  cardno)
inline

Return header card.

Parameters
[in]cardnoNumber of card in header [0,...,size()-1]
Returns
Header card.

Definition at line 126 of file GFitsHeader.hpp.

References m_cards.

const GFitsHeaderCard & GFitsHeader::operator[] ( const int &  cardno) const
inline

Return pointer to model (const version)

Parameters
[in]cardnoNumber of card in header [0,...,size()-1]
Returns
Header card.

Definition at line 139 of file GFitsHeader.hpp.

References m_cards.

GFitsHeaderCard & GFitsHeader::operator[] ( const std::string &  keyname)
inline

Return header card.

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

Definition at line 152 of file GFitsHeader.hpp.

References at().

const GFitsHeaderCard & GFitsHeader::operator[] ( const std::string &  keyname) const
inline

Return header card (const version)

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

Definition at line 165 of file GFitsHeader.hpp.

References at().

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

Print FITS header information.

Parameters
[in]chatterChattiness.
Returns
String containing FITS header information.

Implements GBase.

Definition at line 715 of file GFitsHeader.cpp.

References m_cards, NORMAL, SILENT, size(), and gammalib::str().

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

double GFitsHeader::real ( const int &  cardno) const

Return header card value as double precision value.

Parameters
[in]cardnoHeader card number [0,...,size()-1].
Returns
Header card double precision value.
Exceptions
GException::out_of_rangeCard number out of range.

Definition at line 330 of file GFitsHeader.cpp.

References contains(), G_REAL1, m_cards, and size().

Referenced by real().

double GFitsHeader::real ( const std::string &  keyname) const

Return header card value as double precision value.

Parameters
[in]keynameHeader card key name.
Returns
Header card double precision value.
Exceptions
GException::invalid_argumentKey name not found.

Definition at line 353 of file GFitsHeader.cpp.

References G_REAL2, get_index(), m_cards, and real().

void GFitsHeader::remove ( const int &  cardno)
virtual

Remove card from header.

Parameters
[in]cardnoHeader card number [0,...,size()-1].
Exceptions
GException::out_of_rangeCard number out of range.

Remove header card of specified card number from container.

Implements GContainer.

Definition at line 541 of file GFitsHeader.cpp.

References contains(), G_REMOVE1, m_cards, size(), and update_keyname_map().

Referenced by GFitsTable::update_header().

void GFitsHeader::remove ( const std::string &  keyname)

Remove card from header.

Parameters
[in]keynameHeader card key name.
Exceptions
GException::invalid_argumentKey name not found.

Remove card with specified keyname from header.

Definition at line 571 of file GFitsHeader.cpp.

References G_REMOVE2, get_index(), m_cards, and update_keyname_map().

void GFitsHeader::reserve ( const int &  num)
inlinevirtual

Reserves space for cards in FITS header.

Parameters
[in]numNumber of cards

Reserves space for num cards in the FITS header.

Implements GContainer.

Definition at line 207 of file GFitsHeader.hpp.

References m_cards.

Referenced by extend(), and load().

void GFitsHeader::save ( void *  vptr) const

Save header to FITS file.

Parameters
[in]vptrFITS file void pointer.
Exceptions
GException::fits_errorFITS error occured.

Saves all header cards into HDU. This method does not write the following mandatory keywords to the HDU (those will be written by methods handling the data of the HDU): 'SIMPLE' 'BITPIX' 'NAXIS', 'NAXIS1', 'NAXIS2', etc. 'EXTEND' 'PCOUNT' 'GCOUNT'

Definition at line 689 of file GFitsHeader.cpp.

References FPTR, m_cards, and size().

Referenced by GFitsHDU::save().

int GFitsHeader::size ( void  ) const
inlinevirtual

Return number of cards in header.

Returns
Number of cards in header.

Returns the number of cards in the extension header.

Implements GContainer.

Definition at line 179 of file GFitsHeader.hpp.

References m_cards.

Referenced by append(), at(), GFitsHDU::cards(), contains(), extend(), insert(), integer(), print(), real(), remove(), save(), string(), GRmf::write(), GArf::write(), and GPha::write().

std::string GFitsHeader::string ( const int &  cardno) const

Return header card value as string value.

Parameters
[in]cardnoHeader card number [0,...,size()-1].
Returns
Header card string value.
Exceptions
GException::out_of_rangeCard number out of range.

Definition at line 282 of file GFitsHeader.cpp.

References contains(), G_STRING1, m_cards, and size().

Referenced by GFitsHDU::open().

std::string GFitsHeader::string ( const std::string &  keyname) const

Return header card value as string value.

Parameters
[in]keynameHeader card key name.
Returns
Header card string value.
Exceptions
GException::invalid_argumentKey name not found.

Definition at line 305 of file GFitsHeader.cpp.

References G_STRING2, get_index(), and m_cards.

void GFitsHeader::update_keyname_map ( void  )
private

Update the header card pointers.

Sets up a map between header card keywords and pointers to header cards. This enables fast access of header cards in a FITS header.

This method needs to be called whenever the list of header cards is modified.

Definition at line 828 of file GFitsHeader.cpp.

References m_cards, and m_keyname_map.

Referenced by append(), copy_members(), extend(), insert(), load(), and remove().

Member Data Documentation

std::vector<GFitsHeaderCard> GFitsHeader::m_cards
private
std::map<std::string, GFitsHeaderCard*> GFitsHeader::m_keyname_map
private

Header pointers.

Definition at line 103 of file GFitsHeader.hpp.

Referenced by append(), get_index(), init_members(), and update_keyname_map().


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