00001 // @(#)root/graf2d:$Id: TFITS.h 34692 2010-08-01 20:45:39Z brun $ 00002 // Author: Claudi Martinez, July 19th 2010 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2010, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TFITS 00013 #define ROOT_TFITS 00014 00015 ////////////////////////////////////////////////////////////////////////// 00016 // // 00017 // TFITS // 00018 // // 00019 // Interface to FITS astronomical files. // 00020 // Please, see TFITS.cxx for info about implementation // 00021 ////////////////////////////////////////////////////////////////////////// 00022 00023 #ifndef ROOT_TNamed 00024 #include "TNamed.h" 00025 #endif 00026 #ifndef ROOT_TMatrixDfwd 00027 #include "TMatrixDfwd.h" 00028 #endif 00029 #ifndef ROOT_TVectorDfwd 00030 #include "TVectorDfwd.h" 00031 #endif 00032 00033 class TArrayI; 00034 class TArrayD; 00035 class TH1; 00036 class TImage; 00037 class TImagePalette; 00038 class TObjArray; 00039 00040 class TFITSHDU : public TNamed { 00041 00042 private: 00043 void _release_resources(); 00044 void _initialize_me(); 00045 00046 public: 00047 enum EHDUTypes { // HDU types 00048 kImageHDU, 00049 kTableHDU 00050 }; 00051 00052 enum EColumnTypes { // Column data types 00053 kRealNumber, 00054 kString 00055 }; 00056 00057 struct HDURecord { // FITS HDU record 00058 TString fKeyword; 00059 TString fValue; 00060 TString fComment; 00061 }; 00062 00063 struct Column { //Information of a table column 00064 TString fName; // Column's name 00065 enum EColumnTypes fType; // Column's data type 00066 }; 00067 00068 union Cell { //Table cell contents 00069 Char_t *fString; 00070 Double_t fRealNumber; 00071 }; 00072 00073 protected: 00074 TString fFilePath; // Path to HDU's file including filter 00075 TString fBaseFilePath; // Path to HDU's file excluding filter 00076 struct HDURecord *fRecords; // HDU metadata records 00077 Int_t fNRecords; // Number of records 00078 enum EHDUTypes fType; // HDU type 00079 TString fExtensionName; // Extension Name 00080 Int_t fNumber; // HDU number (1=PRIMARY) 00081 TArrayI *fSizes; // Image sizes in each dimension (when fType == kImageHDU) 00082 TArrayD *fPixels; // Image pixels (when fType == kImageHDU) 00083 TString *fColumnNames; // Array of column names following the order within the FITS file (when fType == kTableHDU) 00084 enum EColumnTypes *fColumnTypes; // Array of column types following the order within the FITS file (when fType == kTableHDU) 00085 struct Column *fColumnsInfo; // Information about columns (when fType == kTableHDU) 00086 Int_t fNColumns; // Number of columns (when fType == kTableHDU) 00087 Int_t fNRows; // Number of rows (when fType == kTableHDU) 00088 union Cell *fCells; // Table cells (when fType == kTableHDU). Cells are ordered in the following way: 00089 // fCells[0..fNRows-1] -> cells of column 0 00090 // fCells[fNRows..2*fNRows-1] -> cells of column 1 00091 // fCells[2*fNRows..3*fNRows-1] -> cells of column 2 00092 // fCells[(fNColumns-1)*fNRows..fNColumns*fNRows-1] -> cells of column fNColumns-1 00093 00094 00095 Bool_t LoadHDU(TString& filepath_filter); 00096 static void CleanFilePath(const char *filepath_with_filter, TString &dst); 00097 void PrintHDUMetadata(const Option_t *opt="") const; 00098 void PrintFileMetadata(const Option_t *opt="") const; 00099 void PrintColumnInfo(const Option_t *) const; 00100 void PrintFullTable(const Option_t *) const; 00101 00102 public: 00103 TFITSHDU(const char *filepath_with_filter); 00104 TFITSHDU(const char *filepath, Int_t extension_number); 00105 TFITSHDU(const char *filepath, const char *extension_name); 00106 ~TFITSHDU(); 00107 00108 //Metadata access methods 00109 Int_t GetRecordNumber() const { return fNRecords; } 00110 struct HDURecord *GetRecord(const char *keyword); 00111 TString& GetKeywordValue(const char *keyword); 00112 void Print(const Option_t *opt="") const; 00113 00114 //Image readers 00115 TH1 *ReadAsHistogram(); 00116 TImage *ReadAsImage(Int_t layer = 0, TImagePalette *pal = 0); 00117 TMatrixD *ReadAsMatrix(Int_t layer = 0, Option_t *opt=""); 00118 TVectorD *GetArrayRow(UInt_t row); 00119 TVectorD *GetArrayColumn(UInt_t col); 00120 00121 //Table readers 00122 Int_t GetTabNColumns() const { return fNColumns; } 00123 Int_t GetTabNRows() const { return fNRows; } 00124 Int_t GetColumnNumber(const char *colname); 00125 TObjArray *GetTabStringColumn(Int_t colnum); 00126 TObjArray *GetTabStringColumn(const char *colname); 00127 TVectorD *GetTabRealVectorColumn(Int_t colnum); 00128 TVectorD *GetTabRealVectorColumn(const char *colname); 00129 00130 //Misc 00131 void Draw(Option_t *opt=""); 00132 Bool_t Change(const char *filter); 00133 Bool_t Change(Int_t extension_number); 00134 00135 00136 ClassDef(TFITSHDU,0) // Class interfacing FITS HDUs 00137 }; 00138 00139 00140 #endif