Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
27 class TArrayI;
28 class TArrayD;
29 class TH1;
30 class TImage;
31 class TImagePalette;
32 class TObjArray;
33 
34 class TFITSHDU : public TNamed {
35 
36 private:
37  void _release_resources();
38  void _initialize_me();
39 
40 public:
41  enum EHDUTypes { // HDU types
42  kImageHDU,
43  kTableHDU
44  };
45 
46  enum EColumnTypes { // Column data types
47  kRealNumber,
48  kString,
49  kRealVector
50  };
51 
52  struct HDURecord { // FITS HDU record
53  TString fKeyword;
54  TString fValue;
55  TString fComment;
56  };
57 
58  struct Column { //Information of a table column
59  TString fName; // Column's name
60  enum EColumnTypes fType; // Column's data type
61  Int_t fDim; // When cells contain real number vectors, this field indicates
62  // the dimension of this vector (number of components), being 1 for scalars.
63  };
64 
65  union Cell { //Table cell contents
66  Char_t *fString;
67  Double_t fRealNumber;
68  Double_t *fRealVector;
69  };
70 
71 protected:
72  TString fFilePath; ///< Path to HDU's file including filter
73  TString fBaseFilePath; ///< Path to HDU's file excluding filter
74  struct HDURecord *fRecords; ///< HDU metadata records
75  Int_t fNRecords; ///< Number of records
76  enum EHDUTypes fType; ///< HDU type
77  TString fExtensionName; ///< Extension Name
78  Int_t fNumber; ///< HDU number (1=PRIMARY)
79  TArrayI *fSizes; ///< Image sizes in each dimension (when fType == kImageHDU)
80  TArrayD *fPixels; ///< Image pixels (when fType == kImageHDU)
81  struct Column *fColumnsInfo; ///< Information about columns (when fType == kTableHDU)
82  Int_t fNColumns; ///< Number of columns (when fType == kTableHDU)
83  Int_t fNRows; ///< Number of rows (when fType == kTableHDU)
84  union Cell *fCells; ///< Table cells (when fType == kTableHDU). Cells are ordered in the following way:
85  ///< fCells[0..fNRows-1] -> cells of column 0
86  ///< fCells[fNRows..2*fNRows-1] -> cells of column 1
87  ///< fCells[2*fNRows..3*fNRows-1] -> cells of column 2
88  ///< fCells[(fNColumns-1)*fNRows..fNColumns*fNRows-1] -> cells of column fNColumns-1
89 
90 
91  Bool_t LoadHDU(TString& filepath_filter);
92  static void CleanFilePath(const char *filepath_with_filter, TString &dst);
93  void PrintHDUMetadata(const Option_t *opt="") const;
94  void PrintFileMetadata(const Option_t *opt="") const;
95  void PrintColumnInfo(const Option_t *) const;
96  void PrintFullTable(const Option_t *) const;
97 
98 public:
99  TFITSHDU(const char *filepath_with_filter);
100  TFITSHDU(const char *filepath, Int_t extension_number);
101  TFITSHDU(const char *filepath, const char *extension_name);
102  ~TFITSHDU();
103 
104  //Metadata access methods
105  Int_t GetRecordNumber() const { return fNRecords; }
106  struct HDURecord *GetRecord(const char *keyword);
107  TString& GetKeywordValue(const char *keyword);
108  void Print(const Option_t *opt="") const;
109 
110  //Image readers
111  TH1 *ReadAsHistogram();
112  TImage *ReadAsImage(Int_t layer = 0, TImagePalette *pal = 0);
113  TMatrixD *ReadAsMatrix(Int_t layer = 0, Option_t *opt="");
114  TVectorD *GetArrayRow(UInt_t row);
115  TVectorD *GetArrayColumn(UInt_t col);
116 
117  //Table readers
118  Int_t GetTabNColumns() const { return fNColumns; }
119  Int_t GetTabNRows() const { return fNRows; }
120  Int_t GetColumnNumber(const char *colname);
121  const TString& GetColumnName(Int_t colnum);
122  TObjArray *GetTabStringColumn(Int_t colnum);
123  TObjArray *GetTabStringColumn(const char *colname);
124  TVectorD *GetTabRealVectorColumn(Int_t colnum);
125  TVectorD *GetTabRealVectorColumn(const char *colname);
126  TVectorD *GetTabRealVectorCell(Int_t rownum, Int_t colnum);
127  TVectorD *GetTabRealVectorCell(Int_t rownum, const char *colname);
128  TObjArray *GetTabRealVectorCells(Int_t colnum);
129  TObjArray *GetTabRealVectorCells(const char *colname);
130 
131  //Misc
132  void Draw(Option_t *opt="");
133  Bool_t Change(const char *filter);
134  Bool_t Change(Int_t extension_number);
135 
136 
137  ClassDef(TFITSHDU,0) // Class interfacing FITS HDUs
138 };
139 
140 
141 #endif