mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
mx::fits::fitsHeader Class Reference

Class to manage a complete fits header.

Manages tasks such as insertion (avoiding duplicates), and keyword lookup. The cards are stored in a std::list to preserve order, but a std::unordered_multimap is used to provide fast keyword lookup.

Definition at line 51 of file fitsHeader.hpp.

#include <ioutils/fits/fitsHeader.hpp>

Public Types

typedef std::list< fitsHeaderCard >::iterator headerIterator
 The iterator type for the cards list. More...
 
typedef std::unordered_multimap< std::string, headerIterator >::iterator mapIterator
 The iterator type for the card map. More...
 

Public Member Functions

 fitsHeader ()
 Default c'tor. More...
 
 fitsHeader (const fitsHeader &head)
 Copy constructor. More...
 
 ~fitsHeader ()
 Destructor. More...
 
fitsHeaderoperator= (const fitsHeader &head)
 Assignment. More...
 
headerIterator begin ()
 Get iterator to the beginning of the cards list. More...
 
headerIterator end ()
 Get iterator to the end of the cards list. More...
 
headerIterator iterator (const std::string &keyword)
 Get iterator pointing to a specific element. More...
 
bool empty ()
 Test whether the header is empty. More...
 
size_t size ()
 Get number of cards currently stored in the header. More...
 
void clear ()
 Clear all cards from the header. More...
 
size_t count (const std::string &keyword)
 Get number of cards with a given keyword. More...
 
void erase (const std::string &keyword)
 Erase card by keyword. More...
 
void erase (headerIterator it)
 Erase card by iterator. More...
 
void eraseStandardTop ()
 Erase the standard entries at the top of the header. More...
 
void append (fitsHeaderCard card)
 Append a fitsHeaderCard to the end of the header. More...
 
template<typename typeT >
void append (const std::string &k, const typeT &v, const std::string &c)
 Append a card to the end of the header, from the three components of a card. More...
 
template<typename typeT >
void append (const std::string &k, const typeT &v)
 Append a card to the end of the header, from the components of a card with no comment. More...
 
void append (const std::string &k)
 Append a card to the end of the header, with just a keyword. More...
 
void append (fitsHeader &head)
 Append a fitsHeader to the end of the header. More...
 
void insert_before (headerIterator it, fitsHeaderCard card)
 Insert a card before another card. More...
 
template<typename typeT >
void insert_before (headerIterator it, const std::string &k, typeT v, const std::string &c)
 Insert a card before another card, specifying the card by its components. More...
 
template<typename typeT >
void insert_before (headerIterator it, const std::string &k, typeT v)
 Insert a card before another card, specifying the card by its components. More...
 
void insert_after (headerIterator it, fitsHeaderCard card)
 Insert a card after another card. More...
 
template<typename typeT >
void insert_after (headerIterator it, const std::string &k, typeT v, const std::string &c)
 Insert a card after another card, specifying the card by its components. More...
 
template<typename typeT >
void insert_after (headerIterator it, const std::string &k, typeT v)
 Insert a card after another card, specifying the card by its components. More...
 
fitsHeaderCardoperator[] (const std::string &keyword)
 Card access by keyword operator. More...
 
const fitsHeaderCardoperator[] (const std::string &keyword) const
 Card access by keyword operator (const version) More...
 

Protected Attributes

std::list< fitsHeaderCardcards
 The storage for the FITS header cards. More...
 
std::unordered_multimap< std::string, headerIteratorcardMap
 This multimap allows for fast lookup by keyword. More...
 

Member Typedef Documentation

◆ headerIterator

The iterator type for the cards list.

Definition at line 57 of file fitsHeader.hpp.

◆ mapIterator

typedef std::unordered_multimap<std::string, headerIterator>::iterator mx::fits::fitsHeader::mapIterator

The iterator type for the card map.

Definition at line 60 of file fitsHeader.hpp.

Constructor & Destructor Documentation

◆ fitsHeader() [1/2]

mx::fits::fitsHeader::fitsHeader ( )

Default c'tor.

Definition at line 34 of file fitsHeader.cpp.

◆ fitsHeader() [2/2]

mx::fits::fitsHeader::fitsHeader ( const fitsHeader head)

Copy constructor.

Must be explicitly defined to handle creation of new iterators in the cardMap

Parameters
headThe fitsHeader to copy

Definition at line 38 of file fitsHeader.cpp.

References operator=().

◆ ~fitsHeader()

mx::fits::fitsHeader::~fitsHeader ( )

Destructor.

Definition at line 44 of file fitsHeader.cpp.

References clear().

Member Function Documentation

◆ append() [1/5]

void mx::fits::fitsHeader::append ( const std::string &  k)

Append a card to the end of the header, with just a keyword.

Appens a headerCard with unknownType

Parameters
kis the keyword string

Definition at line 188 of file fitsHeader.cpp.

References append(), and mx::astro::constants::k().

◆ append() [2/5]

template<typename typeT >
void mx::fits::fitsHeader::append ( const std::string &  k,
const typeT &  v 
)

Append a card to the end of the header, from the components of a card with no comment.

Template Parameters
typeTis the data type of the value
Parameters
kis the keyword string
vis the value of typeT

Definition at line 280 of file fitsHeader.hpp.

References append(), and mx::astro::constants::k().

◆ append() [3/5]

template<typename typeT >
void mx::fits::fitsHeader::append ( const std::string &  k,
const typeT &  v,
const std::string &  c 
)

Append a card to the end of the header, from the three components of a card.

Template Parameters
typeTis the data type of the value
Parameters
kis the keyword string
vis the value of typeT
cis the comment string

Definition at line 270 of file fitsHeader.hpp.

References append(), mx::astro::constants::c(), and mx::astro::constants::k().

◆ append() [4/5]

void mx::fits::fitsHeader::append ( fitsHeader head)

Append a fitsHeader to the end of the header.

Parameters
headis a populated fitsHeader

Definition at line 178 of file fitsHeader.cpp.

References append(), begin(), and end().

◆ append() [5/5]

◆ begin()

fitsHeader::headerIterator mx::fits::fitsHeader::begin ( )

Get iterator to the beginning of the cards list.

Definition at line 66 of file fitsHeader.cpp.

References cards.

Referenced by append(), eraseStandardTop(), mx::fits::fitsFile< dataT >::readHeader(), and mx::fits::fitsFile< dataT >::write().

◆ clear()

void mx::fits::fitsHeader::clear ( )

Clear all cards from the header.

Definition at line 91 of file fitsHeader.cpp.

References cardMap, and cards.

Referenced by ~fitsHeader().

◆ count()

size_t mx::fits::fitsHeader::count ( const std::string &  keyword)

Get number of cards with a given keyword.

Reeturns the result of the count() method of the header map.

Return values
thenumber of cards with keyword.
Parameters
[in]keywordthe keyword to loop up

Definition at line 97 of file fitsHeader.cpp.

References cardMap.

Referenced by mx::improc::HCIobservation< _realT >::readFiles(), mx::improc::ADIobservation< _realT, _derotFunctObj >::readPSFSub(), and mx::improc::HCIobservation< _realT >::readPSFSub().

◆ empty()

bool mx::fits::fitsHeader::empty ( )

Test whether the header is empty.

Definition at line 81 of file fitsHeader.cpp.

References cards.

◆ end()

fitsHeader::headerIterator mx::fits::fitsHeader::end ( )

Get iterator to the end of the cards list.

Definition at line 71 of file fitsHeader.cpp.

References cards.

Referenced by append(), eraseStandardTop(), mx::fits::fitsFile< dataT >::readHeader(), and mx::fits::fitsFile< dataT >::write().

◆ erase() [1/2]

void mx::fits::fitsHeader::erase ( const std::string &  keyword)

Erase card by keyword.

This can not be used to erase COMMENT or HISTORY cards.

Parameters
keywordthe keyword of the card to delete

Definition at line 102 of file fitsHeader.cpp.

References cardMap, and cards.

Referenced by eraseStandardTop(), and mx::fits::fitsFile< dataT >::readHeader().

◆ erase() [2/2]

void mx::fits::fitsHeader::erase ( headerIterator  it)

Erase card by iterator.

This handles COMMENT and HISTORY cards, deleting only the one pointed to by it

Parameters
itis a headerIterator pointing to the card to delete.

Definition at line 114 of file fitsHeader.cpp.

References cardMap, and cards.

◆ eraseStandardTop()

void mx::fits::fitsHeader::eraseStandardTop ( )

Erase the standard entries at the top of the header.

Erases each entry down to BSCALE. This is useful for appending a header to a newly created file.

Definition at line 126 of file fitsHeader.cpp.

References begin(), end(), and erase().

◆ insert_after() [1/3]

template<typename typeT >
void mx::fits::fitsHeader::insert_after ( headerIterator  it,
const std::string &  k,
typeT  v 
)

Insert a card after another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
itpoints to the element after which to insert
kis the keyword
vis the value

Definition at line 319 of file fitsHeader.hpp.

References insert_after(), and mx::astro::constants::k().

◆ insert_after() [2/3]

template<typename typeT >
void mx::fits::fitsHeader::insert_after ( headerIterator  it,
const std::string &  k,
typeT  v,
const std::string &  c 
)

Insert a card after another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
itpoints to the element after which to insert
kis the keyword
vis the value
cis the comment

Definition at line 308 of file fitsHeader.hpp.

References mx::astro::constants::c(), insert_after(), and mx::astro::constants::k().

◆ insert_after() [3/3]

void mx::fits::fitsHeader::insert_after ( headerIterator  it,
fitsHeaderCard  card 
)

Insert a card after another card.

Parameters
itpoints to the element after which to insert
cardcontains the card to insert

Definition at line 215 of file fitsHeader.cpp.

References cardMap, mx::fits::fitsHeaderCard::keyword(), and mx::fits::fitsHeaderCard::type().

Referenced by insert_after().

◆ insert_before() [1/3]

template<typename typeT >
void mx::fits::fitsHeader::insert_before ( headerIterator  it,
const std::string &  k,
typeT  v 
)

Insert a card before another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
itpoints to the element before which to insert
kis the keyword
vis the value

Definition at line 299 of file fitsHeader.hpp.

References insert_before(), and mx::astro::constants::k().

◆ insert_before() [2/3]

template<typename typeT >
void mx::fits::fitsHeader::insert_before ( headerIterator  it,
const std::string &  k,
typeT  v,
const std::string &  c 
)

Insert a card before another card, specifying the card by its components.

Template Parameters
typeTis the type of the value, which is converted to string for insertion
Parameters
itpoints to the element before which to insert
kis the keyword
vis the value
cis the comment

Definition at line 288 of file fitsHeader.hpp.

References mx::astro::constants::c(), insert_before(), and mx::astro::constants::k().

◆ insert_before() [3/3]

void mx::fits::fitsHeader::insert_before ( headerIterator  it,
fitsHeaderCard  card 
)

Insert a card before another card.

Parameters
itpoints to the element before which to insert
cardcontains the card to insert

Definition at line 193 of file fitsHeader.cpp.

References cardMap, mx::fits::fitsHeaderCard::keyword(), and mx::fits::fitsHeaderCard::type().

Referenced by insert_before().

◆ iterator()

fitsHeader::headerIterator mx::fits::fitsHeader::iterator ( const std::string &  keyword)

Get iterator pointing to a specific element.

Parameters
keywordThe keyword to look up

Definition at line 76 of file fitsHeader.cpp.

References cardMap.

◆ operator=()

fitsHeader & mx::fits::fitsHeader::operator= ( const fitsHeader head)

Assignment.

Must be explicitly defined to handle creation of new iterators in the cardMap

Parameters
headThe fitsHeader to copy

Definition at line 49 of file fitsHeader.cpp.

References cardMap, and cards.

Referenced by fitsHeader().

◆ operator[]() [1/2]

fitsHeaderCard & mx::fits::fitsHeader::operator[] ( const std::string &  keyword)

Card access by keyword operator.

Looks up the card by its keyword, and returns a reference to it.

Parameters
keywordis the header keyword to look up
Return values
fitsHeaderCard&reference to the fitsHeaderCard

Definition at line 238 of file fitsHeader.cpp.

References append(), and cardMap.

◆ operator[]() [2/2]

const fitsHeaderCard & mx::fits::fitsHeader::operator[] ( const std::string &  keyword) const

Card access by keyword operator (const version)

Looks up the card by its keyword, and returns a reference to it.

Parameters
keywordis the header keyword to look up
Return values
fitsHeaderCard&const reference to the fitsHeaderCard

Definition at line 254 of file fitsHeader.cpp.

References cardMap.

◆ size()

size_t mx::fits::fitsHeader::size ( )

Get number of cards currently stored in the header.

Definition at line 86 of file fitsHeader.cpp.

References cards.

Referenced by mx::fits::fitsFile< dataT >::readHeader().

Member Data Documentation

◆ cardMap

std::unordered_multimap<std::string, headerIterator> mx::fits::fitsHeader::cardMap
protected

This multimap allows for fast lookup by keyword.

Use unordered_multimap to handle HISTORY and COMMENT properly, and be as efficient as possible.

Definition at line 73 of file fitsHeader.hpp.

Referenced by append(), clear(), count(), erase(), insert_after(), insert_before(), iterator(), operator=(), and operator[]().

◆ cards

std::list<fitsHeaderCard> mx::fits::fitsHeader::cards
protected

The storage for the FITS header cards.

We use a list, rather than forward_list, so that append (insert at end) is constant time.

Definition at line 68 of file fitsHeader.hpp.

Referenced by begin(), clear(), empty(), end(), erase(), operator=(), and size().


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