Luiza  v03-01
Public Member Functions | Protected Attributes | List of all members
gloria::GloriaFitsTable Class Reference

Class for reading and processing fits tables in Luiza. More...

#include <GloriaFitsTable.h>

Inheritance diagram for gloria::GloriaFitsTable:
gloria::GloriaFitsHeader gloria::GloriaObjectList gloria::GloriaSkyCatalog

Public Member Functions

 GloriaFitsTable ()
 Default constructor. More...
 
 GloriaFitsTable (string FitsFileName)
 Constructor based on reading fits file.
 
 GloriaFitsTable (const GloriaFitsTable &sourceFitsTable)
 Copy constructor.
 
virtual ~GloriaFitsTable ()
 Destructor.
 
GloriaFitsTableoperator= (const GloriaFitsTable &tab)
 Assignment operator.
 
void ReadFitsFile (string FitsFileName)
 Read fits table from file. More...
 
void ReadTextFile (string TextFileName)
 Read table from text file. More...
 
void WriteFitsFile (string FitsFileName, bool binary_tbl=true)
 Write table to fits file. More...
 
void WriteTextFile (string TextFileName, int colWidth=10, char ColumnSeparator= ' ')
 Write table to text file. More...
 
void WriteTextStream (std::ostream &outF, int colWidth=10, char ColumnSeparator= ' ')
 Write table to output text stream. More...
 
int GetColumnNumber ()
 Returns number of defined columns.
 
int GetRowNumber ()
 Returns number of filled rows.
 
string GetColumnName (int iCol)
 Returns name of column.
 
int GetColumnId (string name)
 Returns column Id.
 
TableColumnType GetColumnType (int iCol)
 Returns type of column.
 
TableColumnType GetColumnType (string name)
 Returns type for given column name.
 
bool ColumnExists (string name)
 Check if given column exists.
 
GloriaTableColumnGetColumn (int iCol)
 Returns base class pointer for given column index.
 
GloriaTableColumnGetColumn (string name)
 Returns base class pointer for named column stored in the table.
 
template<class T >
GloriaTableColumnOf< T > * GetColumnOf (int iCol)
 Returns pointer to the column of given type, for given column index.
 
template<class T >
GloriaTableColumnOf< T > * GetColumnOf (string name)
 Returns pointer to the column of given type, for given column name.
 
template<class T >
vector< T > & GetVectorOf (int iCol)
 Returns data vector of given type, from given column index.
 
template<class T >
vector< T > & GetVectorOf (string name)
 Returns data vector of given type, from given column name.
 
template<class T >
T & GetValueOf (int iCol, int iRow)
 Returns value of given type, from given column index and row.
 
template<class T >
T & GetValueOf (string name, int iRow)
 Returns value of given type, from given column name and row.
 
void AddColumn (string Name, TableColumnType Type, string Unit="", string Comment="")
 Add column of given type to the table. More...
 
template<class T >
void AddColumn (string Name, T empty, string Unit="", string Comment="")
 Add column to the table. Type recognized by type of empty cell given. More...
 
void InsertColumn (GloriaTableColumn *source)
 Insert column in the table. More...
 
void InsertColumn (string NewName, GloriaTableColumn *source)
 Insert column in the table. More...
 
void AddRow ()
 Add new row in the table. More...
 
template<class T >
void AddRow (T val)
 Add new row and set value to the first column. More...
 
template<class T0 , class T1 >
void AddRow (T0 val0, T1 val1)
 Add new row and set value to the first two columns. More...
 
template<class T0 , class T1 , class T2 >
void AddRow (T0 val0, T1 val1, T2 val2)
 Add new row and set value to the first three columns. More...
 
template<class T0 , class T1 , class T2 , class T3 >
void AddRow (T0 val0, T1 val1, T2 val2, T3 val3)
 Add new row and set value to the first four columns. More...
 
template<class T0 , class T1 , class T2 , class T3 , class T4 >
void AddRow (T0 val0, T1 val1, T2 val2, T3 val3, T4 val4)
 Add new row and set value to the first five columns. More...
 
template<class T >
void SetValue (string Name, int iRow, T val)
 Set value of given cell.
 
template<class T >
void SetValue (int iCol, int iRow, T val)
 Set value of given cell.
 
template<class T >
void SetLast (int iCol, T val)
 Set value of last cell in given column.
 
template<class T >
void SetLast (string Name, T val)
 Set value of last cell in given column.
 
template<class T >
void GetValue (string Name, int iRow, T *val)
 Get value of given cell.
 
template<class T >
void GetValue (int iCol, int iRow, T *val)
 Get value of given cell.
 
void CopyTableRow (GloriaFitsTable *source, int isource, int itarget=-1)
 Copy row elements from other table (assuming types match!) More...
 
GloriaFitsTableEmptyClone ()
 Copy table structure and header information. Data is not copied.
 
void AdjustColumns ()
 Checks sizes of columns and adjust to the longest one if needed.
 
bool CheckTable ()
 Checks consistency of table structure.
 
long * CreateSortIndex (int iCol, bool reverse=false)
 Create an index array for accessing table rows in order of increasing column values.
 
long * CreateSortIndex (string name, bool reverse=false)
 Create an index array for accessing table rows in order of increasing column values.
 
void SortTable (int iCol, bool reverse=false)
 Sort table rows in order of increasing values of selected column.
 
void SortTable (string name, bool reverse=false)
 Sort table rows in order of increasing values of selected column.
 
bool IsSorted ()
 Check if table is sorted.
 
bool IsSortedBy (string name)
 Check if table is sorted by given column.
 
string SortName ()
 Return name of the column used for table sorting.
 
int SortColumn ()
 Return name of the column used for table sorting.
 
void DeleteRow (int iRow)
 Delete given row.
 
GloriaTableColumnRemoveColumn (int iCol)
 Return column pointer and remove it from the table structure.
 
GloriaTableColumnRemoveColumn (string name)
 Return column pointer and remove it from the table structure.
 
void DeleteColumn (int iCol)
 Delete given column.
 
void DeleteColumn (string name)
 Delete given column.
 
void ClearTable ()
 Clear the table (delete all rows, keep column definitions)
 
void EmptyTable ()
 Delete all columns in the table and clear table header.
 
void Print (std::ostream &os, int colWidth=10)
 Print table content to the stream.
 
- Public Member Functions inherited from gloria::GloriaFitsHeader
 GloriaFitsHeader ()
 Constructor.
 
virtual ~GloriaFitsHeader ()
 Destructor.
 
void ReadFitsHeader (fitsfile *fp)
 Read fits header from file. More...
 
void WriteFitsHeader (fitsfile *fp)
 Write header to fits file. More...
 
int GetKeywordNumber ()
 Number of records defined in the header.
 
HeaderRecordGetRecordAt (const int ikey)
 Access header record by record index.
 
std::string & GetKeywordAt (const int ikey)
 Access header keyword by record index.
 
std::string & GetValueAt (const int ikey)
 Access header value (string) by record index.
 
std::string & GetCommentAt (const int ikey)
 Access header comment by record index.
 
bool IsKeywordSet (const char *keyword)
 Check if given keyword is set in the header.
 
HeaderRecordGetKeywordRecord (const char *keyword)
 Access header record by record index.
 
std::string & GetKeywordValue (const char *keyword)
 Access header value (string) by keyword.
 
long GetKeywordValueInt (const char *keyword)
 Access header value (long int) by keyword.
 
double GetKeywordValueDouble (const char *keyword)
 Access header value (double) by keyword.
 
void AddKeyword (const char *keyword, std::string value, std::string comment)
 Add new keyword to the fits header.
 
void AddKeywordDouble (const char *keyword, double value, std::string comment)
 Add new keyword to the fits header, as double.
 
void AddKeywordInt (const char *keyword, int value, std::string comment)
 Add new keyword to the fits header, as int.
 
void AddKeyword (HeaderRecord record)
 Add new keyword record to the fits header.
 
void SetKeyword (const char *keyword, std::string value, std::string comment)
 Set new value for the existing keyword. Add it if not present.
 
void SetKeywordDouble (const char *keyword, double value, std::string comment)
 Set new value for the existing keyword as double. Add it if not present.
 
void SetKeywordInt (const char *keyword, int value, std::string comment)
 Set new value for the existing keyword as int. Add it if not present.
 
void AddComment (std::string comment)
 Add comment to the header.
 
void AddHistory (std::string history)
 Add history to the header.
 
void RemoveKeyword (const char *keyword)
 Remove given keyword from header. More...
 
void RemoveKeywords (const char *keyword)
 Remove given keyword from header. More...
 
void CopyHeader (GloriaFitsHeader *source)
 Copy full header from given data object (table or image);.
 
void PrintHeader (std::ostream &os, int maxRec=100)
 Print FITS header to output stream. Use maxRec=0 to print all records.
 
bool OK ()
 Method returning true if processing was successful.
 
bool Error ()
 Method returning true if there was an error in data processing.
 
std::string ErrorMessage ()
 Returns error message string.
 
void ClearError ()
 Method returning true if there was an error in data processing.
 
std::string InputFileName ()
 
void SetInputFileName (string name)
 
std::string OutputFileName ()
 

Protected Attributes

int _nRow
 Table size.
 
vector< GloriaTableColumn * > _columns
 Column vector.
 
multimap< string, int > _nameMap
 Column name map. Name is not always unique!
 
int _nSorted
 Number of sorted rows.
 
string _sortName
 Name of column used for sorting.
 
int _sortColumn
 ID of column used for sorting.
 

Detailed Description

Class for reading and processing fits tables in Luiza.

This class allows to read the fits table from file and store it in memory. Tables can be also created to store different kind of data or analysis results.

Structure
Table is defined as a collection of columns (gloria::GloriaTableColumn). Columns are stored in a vector, but each column is also given a name, so it can be accessed by its name. However, FITS standard allows for multiple columns with the same name. User is responsible for making sure that column names are unique if he wants to use them to address table contents. Only columns defined by gloria::TableColumnType are allowed in the table (see description of gloria::GloriaTableColumn for details). One also has to remember that rows and columns are numbered from 0 (as is the standard in C; FITS standard numbers columns and rows starting form 1).
Defining the table
Table can be created either as an empty table or a copy of existing table, or read from file. In any case user can then add and delete columns and rows in the table.
Accessing the table
There are few methods, which can be used to access (set or get) the content of the table
Utilities
User is allowed to access table columns, so it is possible that numbers of elements in different columns will be different (eg. when new values are added to selected columns). Following are defined to help dealing with this problem:
  • GloriaFitsTable::CheckTable can be used to check the consistency between the number of rows stored in the table header and numbers of elements in subsequent columns
  • GloriaFitsTable::AdjustColumns can be used to adjust column lengths - all columns are extended to match the size of the longest column.
  • GloriaFitsTable::CreateSortIndex can be used to create an index array for accessing table rows in order of increasing (or decreasing, if reverse flag set to true) values of selected column. Table contents is not affected.
  • GloriaFitsTable::SortTable can be used to sort table rows in order of increasing (or decreasing, if reverse flag set to true) values of selected column. Table contents is changed.
  • GloriaFitsTable::Print method can be used to generate readable output of the table contents
Author
A.F.Zarnecki, University of Warsaw, zarne.nosp@m.cki@.nosp@m.fuw.e.nosp@m.du.p.nosp@m.l

Constructor & Destructor Documentation

gloria::GloriaFitsTable::GloriaFitsTable ( )

Default constructor.

Default constructor cretes empty table

Member Function Documentation

void gloria::GloriaFitsTable::AddColumn ( string  Name,
TableColumnType  Type,
string  Unit = "",
string  Comment = "" 
)
template<class T >
void gloria::GloriaFitsTable::AddColumn ( string  Name,
empty,
string  Unit = "",
string  Comment = "" 
)

Add column to the table. Type recognized by type of empty cell given.

If any rows are already put in the table, new column is initialized to the current number of rows (with empty string or vector, or zero values, depending on type). Unit field is optional.

References gloria::GetValueType().

void gloria::GloriaFitsTable::AddRow ( )

Add new row in the table.

Adding a row means increasing length of all columns by 1 String values are set to empty string, numerical to zero, vectors to empty vectors.

References AddRow().

Referenced by AddRow(), gloria::GloriaValueMap::GetTable(), luiza::TestProcessor::processData(), luiza::ExampleProcessor::processData(), luiza::PiTableReader::processData(), luiza::SociSelect::processData(), luiza::CalculateGausPSF::processData(), luiza::ObjectLightCurve::processData(), and luiza::FindLineTrajectory::processData().

template<class T >
void gloria::GloriaFitsTable::AddRow ( val)
inline

Add new row and set value to the first column.

Be careful to respect column type. Otherwise value will not be added.

References AddRow().

Referenced by AddRow().

template<class T0 , class T1 >
void gloria::GloriaFitsTable::AddRow ( T0  val0,
T1  val1 
)
inline

Add new row and set value to the first two columns.

Be careful to respect column order and types. Otherwise value will not be added.

References AddRow().

Referenced by AddRow().

template<class T0 , class T1 , class T2 >
void gloria::GloriaFitsTable::AddRow ( T0  val0,
T1  val1,
T2  val2 
)
inline

Add new row and set value to the first three columns.

Be careful to respect column order and types. Otherwise value will not be added.

References AddRow().

Referenced by AddRow().

template<class T0 , class T1 , class T2 , class T3 >
void gloria::GloriaFitsTable::AddRow ( T0  val0,
T1  val1,
T2  val2,
T3  val3 
)
inline

Add new row and set value to the first four columns.

Be careful to respect column order and types. Otherwise value will not be added.

template<class T0 , class T1 , class T2 , class T3 , class T4 >
void gloria::GloriaFitsTable::AddRow ( T0  val0,
T1  val1,
T2  val2,
T3  val3,
T4  val4 
)
inline

Add new row and set value to the first five columns.

Be careful to respect column order and types. Otherwise value will not be added.

void gloria::GloriaFitsTable::CopyTableRow ( GloriaFitsTable source,
int  isource,
int  itarget = -1 
)

Copy row elements from other table (assuming types match!)

New row is added if itarget is negative or beyond table length

References GetColumn(), GetColumnNumber(), and GetRowNumber().

Referenced by luiza::SelectTableData::processData(), luiza::SelectNewObjects::processData(), and luiza::FindLineTrajectory::processData().

void gloria::GloriaFitsTable::InsertColumn ( GloriaTableColumn source)

Insert column in the table.

Source column is inserted as a new column in the table. Pointer to the column is stored so the data is not copied. GloriaTableColumn::Clone() method should be used to avoid problems.

References gloria::GloriaTableColumn::Name().

Referenced by luiza::FitsTableWriter::concludeAnalysis(), luiza::TableTextWriter::concludeAnalysis(), gloria::GloriaSkyCatalog::MatchObjectTable(), gloria::GloriaSkyCatalog::MatchObjectVector(), luiza::SelectTableData::processData(), and luiza::SelectNewObjects::processData().

void gloria::GloriaFitsTable::InsertColumn ( string  NewName,
GloriaTableColumn source 
)

Insert column in the table.

Source column is inserted as a new column in the table, with new name (!). Pointer to the column is stored so the data is not copied. GloriaTableColumn::Clone() method should be used to avoid problems.

References gloria::GloriaTableColumn::Name().

void gloria::GloriaFitsTable::ReadFitsFile ( string  FitsFileName)

Read fits table from file.

Header and content are read from file and put into existing table. Old header and all data are lost.

Referenced by luiza::FitsTableReader::processData().

void gloria::GloriaFitsTable::ReadTextFile ( string  TextFileName)

Read table from text file.

Content is read from text file and put into existing table. Header remains unchanged.

Referenced by luiza::TableTextReader::processData().

void gloria::GloriaFitsTable::WriteFitsFile ( string  FitsFileName,
bool  binary_tbl = true 
)

Write table to fits file.

Header compliant to with FITS standard is created

Referenced by luiza::FitsTableWriter::concludeAnalysis().

void gloria::GloriaFitsTable::WriteTextFile ( string  TextFileName,
int  colWidth = 10,
char  ColumnSeparator = ' ' 
)

Write table to text file.

Can be used to store data for direct analysis

Referenced by luiza::ExampleProcessor::concludeAnalysis(), and luiza::SatelliteSearching::concludeAnalysis().

void gloria::GloriaFitsTable::WriteTextStream ( std::ostream &  outF,
int  colWidth = 10,
char  ColumnSeparator = ' ' 
)

Write table to output text stream.

Can be used to store multiple tables to one stream

Referenced by luiza::TableTextWriter::concludeAnalysis().


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