ExtHDU.h
// Astrophysics Science Division,
// NASA/ Goddard Space Flight Center
// HEASARC
// http://heasarc.gsfc.nasa.gov
// e-mail: ccfits@legacy.gsfc.nasa.gov
//
// Original author: Ben Dorman
#ifndef EXTHDU_H
#define EXTHDU_H 1
// CCfitsHeader
#include "CCfits.h"
// HDU
#include "HDU.h"
// FitsError
#include "FitsError.h"
namespace CCfits {
class Column;
} // namespace CCfits
namespace CCfits {
class ExtHDU : public HDU //## Inherits: <unnamed>%38048213E7A8
{
public:
class WrongExtensionType : public FitsException //## Inherits: <unnamed>%39E61E630349
{
public:
WrongExtensionType (const String& msg, bool silent = true);
protected:
private:
private: //## implementation
};
ExtHDU(const ExtHDU &right);
virtual ~ExtHDU();
friend bool operator<(const ExtHDU &left,const ExtHDU &right);
friend bool operator>(const ExtHDU &left,const ExtHDU &right);
friend bool operator<=(const ExtHDU &left,const ExtHDU &right);
friend bool operator>=(const ExtHDU &left,const ExtHDU &right);
static void readHduName (const fitsfile* fptr, int hduIndex, String& hduName, int& hduVersion);
virtual void readData (bool readFlag = false, const std::vector<String>& keys = std::vector<String>()) = 0;
const String& name () const;
virtual HDU * clone (FITS* p) const = 0;
// By all means necessary, set the fitsfile pointer so that
// this HDU is the current HDU.
//
// This would appear to be a good candidate for the public
// interface.
virtual void makeThisCurrent () const;
virtual Column& column (const String& colName, bool caseSensitive = true) const;
virtual Column& column (int colIndex) const;
virtual long rows () const;
virtual void addColumn (ValueType type, const String& columnName, long repeatWidth, const String& colUnit = String(""), long decimals = -1, size_t columnNumber = 0);
virtual void copyColumn(const Column& inColumn, int colIndx, bool insertNewCol=true);
virtual void deleteColumn (const String& columnName);
virtual long getRowsize () const;
virtual int numCols () const;
virtual const ColMap& column () const;
bool isCompressed () const;
int version () const;
void version (int value);
static const String& missHDU ();
static void setMissHDU (const String& value);
public:
// Additional Public Declarations
// interface is virtually identical to PHDU. The implementation is
// similar apart from a check for wrong extension type.
template <typename S>
void write(const std::vector<long>& first,
long nElements,
const std::valarray<S>& data,
S* nullValue);
template <typename S>
void write(long first,
long nElements,
const std::valarray<S>& data,
S* nullValue);
template <typename S>
void write(const std::vector<long>& first,
long nElements,
const std::valarray<S>& data);
template <typename S>
void write(long first,
long nElements,
const std::valarray<S>& data);
template <typename S>
void write(const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::valarray<S>& data);
// read image data & return the array. Can't return a reference because type
// conversion in general requires allocating a new object.
// note semantics of reading column data are easily distinguished: they require
// the user to perform the operation EXT.column({name,index}).read(...)
template <typename S>
void read (std::valarray<S>& image) ;
template<typename S>
void read (std::valarray<S>& image,
long first,
long nElements,
S* nullValue) ;
template<typename S>
void read (std::valarray<S>& image,
const std::vector<long>& first,
long nElements,
S* nullValue) ;
template<typename S>
void read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride) ;
template<typename S>
void read (std::valarray<S>& image,
long first,
long nElements) ;
template<typename S>
void read (std::valarray<S>& image,
const std::vector<long>& first,
long nElements) ;
template<typename S>
void read (std::valarray<S>& image,
const std::vector<long>& firstVertex,
const std::vector<long>& lastVertex,
const std::vector<long>& stride,
S* nullValue) ;
protected:
// ExtHDU needs a default constructor. This is it.
ExtHDU (FITS* p, HduType xtype, const String &hduName, int version);
// The writing constructor. Forces the user to supply a name
// for the HDU
ExtHDU (FITS* p, HduType xtype, const String &hduName, int bitpix, int naxis, const std::vector<long>& axes, int version);
// ExtHDU constructor for getting ExtHDUs by number.
// Necessary since EXTNAME is a reserved not required
// keyword.
ExtHDU (FITS* p, HduType xtype, int number);
virtual std::ostream & put (std::ostream &s) const = 0;
virtual void setColumn (const String& colname, Column* value);
virtual void checkExtensionType () const;
int getVersion ();
long pcount () const;
void pcount (long value);
long gcount () const;
void gcount (long value);
HduType xtension () const;
void xtension (HduType value);
// Additional Protected Declarations
private:
virtual void initRead () = 0;
void checkXtension ();
// Additional Private Declarations
private: //## implementation
// Data Members for Class Attributes
long m_pcount;
long m_gcount;
int m_version;
HduType m_xtension;
static String s_missHDU;
// Data Members for Associations
String m_name;
// Additional Implementation Declarations
};
// Class CCfits::ExtHDU::WrongExtensionType
// Class CCfits::ExtHDU
inline bool operator<(const ExtHDU &left,const ExtHDU &right)
{
if (left.m_name < right.m_name) return true;
if (left.m_name > right.m_name) return false;
if (left.m_name == right.m_name)
{
if (left.m_version < right.m_version) return true;
}
return false;
}
inline bool operator>(const ExtHDU &left,const ExtHDU &right)
{
return !operator<=(left,right);
}
inline bool operator<=(const ExtHDU &left,const ExtHDU &right)
{
if (left.m_name <= right.m_name)
{
if (left.m_version <= right.m_version) return true;
}
return false;
}
inline bool operator>=(const ExtHDU &left,const ExtHDU &right)
{
return !operator<(left,right);
}
inline const String& ExtHDU::name () const
{
return m_name;
}
inline long ExtHDU::pcount () const
{
return m_pcount;
}
inline void ExtHDU::pcount (long value)
{
m_pcount = value;
}
inline long ExtHDU::gcount () const
{
return m_gcount;
}
inline void ExtHDU::gcount (long value)
{
m_gcount = value;
}
inline int ExtHDU::version () const
{
return m_version;
}
inline void ExtHDU::version (int value)
{
m_version = value;
}
inline HduType ExtHDU::xtension () const
{
return m_xtension;
}
inline void ExtHDU::xtension (HduType value)
{
m_xtension = value;
}
inline const String& ExtHDU::missHDU ()
{
return s_missHDU;
}
inline void ExtHDU::setMissHDU (const String& value)
{
s_missHDU = value;
}
} // namespace CCfits
#endif
CCfits::ExtHDU::column
virtual const ColMap & column() const
return a reference to the multimap containing the columns.
Definition: ExtHDU.cxx:306
CCfits::ExtHDU::write
void write(const std::vector< long > &first, long nElements, const std::valarray< S > &data, S *nullValue)
Write a set of pixels to an image extension with the first pixel specified by an n-tuple, processing undefined data.
Definition: ExtHDUT.h:426
CCfits::ExtHDU::~ExtHDU
virtual ~ExtHDU()
destructor
Definition: ExtHDU.cxx:131
CCfits::ExtHDU::read
void read(std::valarray< S > &image)
Read image data into container.
Definition: ExtHDUT.h:18
CCfits::ExtHDU::readData
virtual void readData(bool readFlag=false, const std::vector< String > &keys=std::vector< String >())=0
read data from HDU depending on readFlag and keys.
CCfits::ExtHDU::xtension
HduType xtension() const
return the extension type
Definition: ExtHDU.h:687
CCfits::ExtHDU::getRowsize
virtual long getRowsize() const
return the optimal number of rows to read or write at a time
Definition: ExtHDU.cxx:290
CCfits::ExtHDU::WrongExtensionType
Exception to be thrown on unmatched extension types.
Definition: ExtHDU.h:445
CCfits::ExtHDU::version
int version() const
return the extension version number.
Definition: ExtHDU.h:677
CCfits::ExtHDU::clone
virtual HDU * clone(FITS *p) const =0
virtual copy constructor
CCfits::ExtHDU::WrongExtensionType::WrongExtensionType
WrongExtensionType(const String &msg, bool silent=true)
Exception ctor, prefixes the string &quot;Fits Error: wrong extension type&quot; before the specific message...
Definition: ExtHDU.cxx:42
CCfits::ExtHDU::rows
virtual long rows() const
return the number of rows in the extension.
Definition: ExtHDU.cxx:235
CCfits::HDU::bitpix
long bitpix() const
return the data type keyword.
Definition: HDU.h:998
CCfits::ExtHDU::addColumn
virtual void addColumn(ValueType type, const String &columnName, long repeatWidth, const String &colUnit=String(""), long decimals=-1, size_t columnNumber=0)
add a new column to an existing table HDU.
Definition: ExtHDU.cxx:248
CCfits::ExtHDU::makeThisCurrent
virtual void makeThisCurrent() const
move the fitsfile pointer to this current HDU.
Definition: ExtHDU.cxx:208
CCfits::HDU
Base class for all HDU [Header-Data Unit] objects.
Definition: HDU.h:673
CCfits::ExtHDU::pcount
long pcount() const
return required pcount keyword value
Definition: ExtHDU.h:657
CCfits::FITS
Memory object representation of a disk FITS file.
Definition: FITS.h:628
CCfits::FitsException
FitsException is the base class for all exceptions thrown by this library.
Definition: FitsError.h:93
CCfits::ExtHDU
base class for all FITS extension HDUs, i.e. Image Extensions and Tables.
Definition: ExtHDU.h:438
CCfits::ValueType
ValueType
CCfits value types and their CFITSIO equivalents (in caps)
Definition: CCfits.h:81
CCfits::ColMap
std::multimap< std::string, CCfits::Column * > ColMap
Type definition for a table&#39;s column container.
Definition: CCfits.h:142
CCfits::ExtHDU::name
const String & name() const
return the name of the extension.
Definition: ExtHDU.h:651
CCfits::ExtHDU::isCompressed
bool isCompressed() const
return true if image is stored using compression.
Definition: ExtHDU.cxx:312
CCfits::ExtHDU::gcount
long gcount() const
return required gcount keyword value
Definition: ExtHDU.h:667
CCfits::ExtHDU::ExtHDU
ExtHDU(const ExtHDU &right)
copy constructor
Definition: ExtHDU.cxx:53
CCfits::HDU::axes
long axes() const
return the number of axes in the HDU data section (always 2 for tables).
Definition: HDU.h:978
CCfits::ExtHDU::copyColumn
virtual void copyColumn(const Column &inColumn, int colIndx, bool insertNewCol=true)
copy a column (from different or same HDU and file) into an existing table HDU.
Definition: ExtHDU.cxx:255
CCfits::ExtHDU::readHduName
static void readHduName(const fitsfile *fptr, int hduIndex, String &hduName, int &hduVersion)
read extension name.
Definition: ExtHDU.cxx:148
CCfits::Column
Abstract base class for Column objects.
Definition: Column.h:841
CCfits::ExtHDU::numCols
virtual int numCols() const
return the number of Columns in the Table (the TFIELDS keyword).
Definition: ExtHDU.cxx:298
CCfits::ExtHDU::deleteColumn
virtual void deleteColumn(const String &columnName)
delete a column in a Table extension by name.
Definition: ExtHDU.cxx:260