Logo ROOT  
Reference Guide
TFITS.h
Go to the documentation of this file.
1 // @(#)root/graf2d:$Id$
2 // Author: Claudi Martinez, July 19th 2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2010, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TFITS
13 #define ROOT_TFITS
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TFITS //
18 // //
19 // Interface to FITS astronomical files. //
20 // Please, see TFITS.cxx for info about implementation //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TNamed.h"
24 #include "TMatrixDfwd.h"
25 #include "TVectorDfwd.h"
26 #include <vector>
27 
28 class TArrayI;
29 class TArrayD;
30 class TH1;
31 class TImage;
32 class TImagePalette;
33 class TObjArray;
34 
35 class TFITSHDU : public TNamed {
36 
37 private:
38  void _release_resources();
39  void _initialize_me();
40 
41 public:
42  enum EHDUTypes { // HDU types
44  kTableHDU
45  };
46 
47  enum EColumnTypes { // Column data types
48  kString, // the column contains a string
49  kRealNumber, // the column contains a scalar
50  kRealArray, // the column contains a fixed-length array
51  kRealVector // the column contains a variable-length array
52  };
53 
54  struct HDURecord { // FITS HDU record
58  };
59 
60  struct Column { // Information of a table column
61  TString fName; // Column's name
62  enum EColumnTypes fType; // Column's data type
63  Int_t fDim; // When cells contain real number arrays, this field indicates
64  // the dimension of this vector (number of components), being 1 for scalars.
65  Bool_t fVariable; // kTRUE if the columns has variable-length arrays
66  std::vector<int> fRowStart; // starting index of each row
67  std::vector<int> fVarLengths; // sizes of the individual varaiable-length arrays
68  };
69 
70  union Cell { //Table cell contents
75  };
76 
77 protected:
78  TString fFilePath; ///< Path to HDU's file including filter
79  TString fBaseFilePath; ///< Path to HDU's file excluding filter
80  struct HDURecord *fRecords; ///< HDU metadata records
81  Int_t fNRecords; ///< Number of records
82  enum EHDUTypes fType; ///< HDU type
83  TString fExtensionName; ///< Extension Name
84  Int_t fNumber; ///< HDU number (1=PRIMARY)
85  TArrayI *fSizes; ///< Image sizes in each dimension (when fType == kImageHDU)
86  TArrayD *fPixels; ///< Image pixels (when fType == kImageHDU)
87  struct Column *fColumnsInfo; ///< Information about columns (when fType == kTableHDU)
88  Int_t fNColumns; ///< Number of columns (when fType == kTableHDU)
89  Int_t fNRows; ///< Number of rows (when fType == kTableHDU)
90  union Cell *fCells; ///< Table cells (when fType == kTableHDU). Cells are ordered in the following way:
91  ///< fCells[0..fNRows-1] -> cells of column 0
92  ///< fCells[fNRows..2*fNRows-1] -> cells of column 1
93  ///< fCells[2*fNRows..3*fNRows-1] -> cells of column 2
94  ///< fCells[(fNColumns-1)*fNRows..fNColumns*fNRows-1] -> cells of column fNColumns-1
95 
96 
97  Bool_t LoadHDU(TString& filepath_filter);
98  static void CleanFilePath(const char *filepath_with_filter, TString &dst);
99  void PrintHDUMetadata(const Option_t *opt="") const;
100  void PrintFileMetadata(const Option_t *opt="") const;
101  void PrintColumnInfo(const Option_t *) const;
102  void PrintFullTable(const Option_t *) const;
103 
104 public:
105  TFITSHDU(const char *filepath_with_filter);
106  TFITSHDU(const char *filepath, Int_t extension_number);
107  TFITSHDU(const char *filepath, const char *extension_name);
108  ~TFITSHDU();
109 
110  //Metadata access methods
111  Int_t GetRecordNumber() const { return fNRecords; }
112  struct HDURecord *GetRecord(const char *keyword);
113  TString& GetKeywordValue(const char *keyword);
114  void Print(const Option_t *opt="") const;
115 
116  //Image readers
117  TH1 *ReadAsHistogram();
118  TImage *ReadAsImage(Int_t layer = 0, TImagePalette *pal = 0);
119  TMatrixD *ReadAsMatrix(Int_t layer = 0, Option_t *opt="");
122 
123  //Table readers
124  Int_t GetTabNColumns() const { return fNColumns; }
125  Int_t GetTabNRows() const { return fNRows; }
126  Int_t GetColumnNumber(const char *colname);
127  const TString& GetColumnName(Int_t colnum);
129  TObjArray *GetTabStringColumn(const char *colname);
131  TVectorD *GetTabRealVectorColumn(const char *colname);
132  TVectorD *GetTabRealVectorCell(Int_t rownum, Int_t colnum);
133  TVectorD *GetTabRealVectorCell(Int_t rownum, const char *colname);
135  TObjArray *GetTabRealVectorCells(const char *colname);
136  TArrayD *GetTabVarLengthVectorCell(Int_t rownum, Int_t colnum);
137  TArrayD *GetTabVarLengthVectorCell(Int_t rownum, const char *colname);
138 
139  //Misc
140  void Draw(Option_t *opt="");
141  Bool_t Change(const char *filter);
142  Bool_t Change(Int_t extension_number);
143 
144 
145  ClassDef(TFITSHDU,0) // Class interfacing FITS HDUs
146 };
147 
148 
149 #endif
TFITSHDU::_initialize_me
void _initialize_me()
Do some initializations.
Definition: TFITS.cxx:222
TMatrixDfwd.h
TFITSHDU::Cell::fRealArray
Double_t * fRealArray
Definition: TFITS.h:73
TFITSHDU::_release_resources
void _release_resources()
Release internal resources.
Definition: TFITS.cxx:177
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
TFITSHDU::GetArrayColumn
TVectorD * GetArrayColumn(UInt_t col)
Get a column from the image HDU when it's a 2D array.
Definition: TFITS.cxx:1212
Option_t
const char Option_t
Definition: RtypesCore.h:66
TFITSHDU::Column
Definition: TFITS.h:60
TFITSHDU::fRecords
struct HDURecord * fRecords
HDU metadata records.
Definition: TFITS.h:80
TFITSHDU::ReadAsHistogram
TH1 * ReadAsHistogram()
Read image HDU as a histogram.
Definition: TFITS.cxx:1093
TNamed.h
TFITSHDU::fSizes
TArrayI * fSizes
Image sizes in each dimension (when fType == kImageHDU)
Definition: TFITS.h:85
TFITSHDU::PrintFullTable
void PrintFullTable(const Option_t *) const
Print full table contents.
Definition: TFITS.cxx:794
TFITSHDU::fExtensionName
TString fExtensionName
Extension Name.
Definition: TFITS.h:83
TFITSHDU::fNumber
Int_t fNumber
HDU number (1=PRIMARY)
Definition: TFITS.h:84
Int_t
int Int_t
Definition: RtypesCore.h:45
TFITSHDU::Column::fDim
Int_t fDim
Definition: TFITS.h:63
TFITSHDU::Print
void Print(const Option_t *opt="") const
Print metadata.
Definition: TFITS.cxx:858
TFITSHDU::Column::fVariable
Bool_t fVariable
Definition: TFITS.h:65
TFITSHDU::GetTabNRows
Int_t GetTabNRows() const
Definition: TFITS.h:125
TImage
An abstract interface to image processing library.
Definition: TImage.h:29
TFITSHDU::EColumnTypes
EColumnTypes
Definition: TFITS.h:47
TFITSHDU::GetRecordNumber
Int_t GetRecordNumber() const
Definition: TFITS.h:111
TFITSHDU::fCells
union Cell * fCells
Table cells (when fType == kTableHDU).
Definition: TFITS.h:90
TVectorDfwd.h
TFITSHDU::kTableHDU
@ kTableHDU
Definition: TFITS.h:44
TFITSHDU::Cell
Definition: TFITS.h:70
TString
Basic string class.
Definition: TString.h:136
TMatrixT< Double_t >
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFITSHDU::fType
enum EHDUTypes fType
HDU type.
Definition: TFITS.h:82
TFITSHDU::Column::fRowStart
std::vector< int > fRowStart
Definition: TFITS.h:66
TFITSHDU::GetTabNColumns
Int_t GetTabNColumns() const
Definition: TFITS.h:124
TFITSHDU::kRealVector
@ kRealVector
Definition: TFITS.h:51
TFITSHDU::PrintHDUMetadata
void PrintHDUMetadata(const Option_t *opt="") const
Print records.
Definition: TFITS.cxx:651
bool
TFITSHDU::PrintFileMetadata
void PrintFileMetadata(const Option_t *opt="") const
Print HDU's parent file's metadata.
Definition: TFITS.cxx:665
TFITSHDU::fNColumns
Int_t fNColumns
Number of columns (when fType == kTableHDU)
Definition: TFITS.h:88
TFITSHDU::GetTabVarLengthVectorCell
TArrayD * GetTabVarLengthVectorCell(Int_t rownum, Int_t colnum)
Get the variable-length array contained in a cell given by (row>=0, column name)
Definition: TFITS.cxx:1583
TFITSHDU::fNRecords
Int_t fNRecords
Number of records.
Definition: TFITS.h:81
TFITSHDU::kString
@ kString
Definition: TFITS.h:48
TFITSHDU::GetTabStringColumn
TObjArray * GetTabStringColumn(Int_t colnum)
Get a string-typed column from a table HDU given its column index (>=0).
Definition: TFITS.cxx:1266
TFITSHDU::PrintColumnInfo
void PrintColumnInfo(const Option_t *) const
Print column information.
Definition: TFITS.cxx:766
TFITSHDU::fBaseFilePath
TString fBaseFilePath
Path to HDU's file excluding filter.
Definition: TFITS.h:79
TFITSHDU::fNRows
Int_t fNRows
Number of rows (when fType == kTableHDU)
Definition: TFITS.h:89
TFITSHDU::GetColumnName
const TString & GetColumnName(Int_t colnum)
Get the name of a column given its index (column>=0).
Definition: TFITS.cxx:1565
TFITSHDU::GetArrayRow
TVectorD * GetArrayRow(UInt_t row)
Get a row from the image HDU when it's a 2D array.
Definition: TFITS.cxx:1172
TFITSHDU::Cell::fRealVector
TArrayD * fRealVector
Definition: TFITS.h:74
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TFITSHDU::GetTabRealVectorCell
TVectorD * GetTabRealVectorCell(Int_t rownum, Int_t colnum)
Get a real array (with fixed or variable-length) embedded in a cell given by (row>=0,...
Definition: TFITS.cxx:1513
TFITSHDU::HDURecord
Definition: TFITS.h:54
TFITSHDU::kImageHDU
@ kImageHDU
Definition: TFITS.h:43
TFITSHDU::HDURecord::fComment
TString fComment
Definition: TFITS.h:57
TFITSHDU::Change
Bool_t Change(const char *filter)
Change to another HDU given by "filter".
Definition: TFITS.cxx:1414
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TFITSHDU::ReadAsMatrix
TMatrixD * ReadAsMatrix(Int_t layer=0, Option_t *opt="")
Read image HDU as a matrix.
Definition: TFITS.cxx:1000
TFITSHDU::EHDUTypes
EHDUTypes
Definition: TFITS.h:42
TFITSHDU::HDURecord::fKeyword
TString fKeyword
Definition: TFITS.h:55
TFITSHDU::Column::fType
enum EColumnTypes fType
Definition: TFITS.h:62
TFITSHDU::GetTabRealVectorColumn
TVectorD * GetTabRealVectorColumn(Int_t colnum)
Get a real number-typed column from a table HDU given its column index (>=0).
Definition: TFITS.cxx:1329
TFITSHDU::Draw
void Draw(Option_t *opt="")
If the HDU is an image, draw the first layer of the primary array To set a title to the canvas,...
Definition: TFITS.cxx:973
TFITSHDU::Column::fVarLengths
std::vector< int > fVarLengths
Definition: TFITS.h:67
TFITSHDU::Cell::fString
Char_t * fString
Definition: TFITS.h:71
TVectorT< Double_t >
TFITSHDU::TFITSHDU
TFITSHDU(const char *filepath_with_filter)
TFITSHDU constructor from file path with HDU selection filter.
Definition: TFITS.cxx:118
TFITSHDU::CleanFilePath
static void CleanFilePath(const char *filepath_with_filter, TString &dst)
Clean path from possible filter and put the result in 'dst'.
Definition: TFITS.cxx:94
Double_t
double Double_t
Definition: RtypesCore.h:59
TFITSHDU::Column::fName
TString fName
Definition: TFITS.h:61
TFITSHDU::~TFITSHDU
~TFITSHDU()
TFITSHDU destructor.
Definition: TFITS.cxx:169
TFITSHDU::fColumnsInfo
struct Column * fColumnsInfo
Information about columns (when fType == kTableHDU)
Definition: TFITS.h:87
TFITSHDU
FITS file interface class.
Definition: TFITS.h:35
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TH1
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
TFITSHDU::fPixels
TArrayD * fPixels
Image pixels (when fType == kImageHDU)
Definition: TFITS.h:86
TFITSHDU::kRealArray
@ kRealArray
Definition: TFITS.h:50
TFITSHDU::GetTabRealVectorCells
TObjArray * GetTabRealVectorCells(Int_t colnum)
Get a collection of real vectors embedded in cells along a given column from a table HDU....
Definition: TFITS.cxx:1454
TFITSHDU::HDURecord::fValue
TString fValue
Definition: TFITS.h:56
TImagePalette
A class to define a conversion from pixel values to pixel color.
Definition: TAttImage.h:33
TFITSHDU::GetRecord
struct HDURecord * GetRecord(const char *keyword)
Get record by keyword.
Definition: TFITS.cxx:625
TFITSHDU::ReadAsImage
TImage * ReadAsImage(Int_t layer=0, TImagePalette *pal=0)
Read image HDU as a displayable image.
Definition: TFITS.cxx:880
TFITSHDU::LoadHDU
Bool_t LoadHDU(TString &filepath_filter)
Load HDU from fits file satisfying the specified filter.
Definition: TFITS.cxx:237
TFITSHDU::fFilePath
TString fFilePath
Path to HDU's file including filter.
Definition: TFITS.h:78
TArrayD
Array of doubles (64 bits per element).
Definition: TArrayD.h:27
TFITSHDU::kRealNumber
@ kRealNumber
Definition: TFITS.h:49
Char_t
char Char_t
Definition: RtypesCore.h:33
TFITSHDU::GetKeywordValue
TString & GetKeywordValue(const char *keyword)
Get the value of a given keyword. Return "" if not found.
Definition: TFITS.cxx:638
TArrayI
Array of integers (32 bits per element).
Definition: TArrayI.h:27
TFITSHDU::Cell::fRealNumber
Double_t fRealNumber
Definition: TFITS.h:72
int
TFITSHDU::GetColumnNumber
Int_t GetColumnNumber(const char *colname)
Get column number given its name.
Definition: TFITS.cxx:1252