Extension.hxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 //-----------------------------------------------------------------------------
00005 // CVS: $Revision: 2099 $, $Date: 2006-04-17 17:48:43 +0100 (Mon, 17 Apr 2006) $, $Author: rsc $
00006 //-----------------------------------------------------------------------------
00007 #ifndef EXTENSION_H
00008 #define EXTENSION_H
00009 
00010 #include "Constants.h"
00011 #include "DataBuilder.hxx"
00012 #include "InsertData.hxx"
00013 #include "Logger.h"
00014 #include "TableInfo.h"
00015 //-----------------------------------------------------------------------------
00016 // One row per extension HDU
00017 
00021 template<typename DataType>
00022 class Extension : public DataBuilder<DataType>
00023 {
00024 public:
00026   Extension(const TableInfo& aInfo)
00027     : mInfo(aInfo)
00028     { DataBuilder<DataType>::builderName = "Extension"; }
00029 
00031   virtual ~Extension() {}
00032 
00034   TableData<DataType>* build(FitsFile& fpix,
00035                              FitsFile& fcat,
00036                              int fileNo)
00037   {
00038     Logger log;
00039     // Number of rows is number extension HDUs
00040     int numRows = fpix.getNumHdus() - 1;
00041     TableData<DataType>* data;
00042 
00043     // This must match the number of extensions in the
00044     // (not empty) catalog file
00045     bool useEmptyCat = fcat.getFileName().find(DefaultValues::emptycatname)
00046                           != string::npos;
00047 
00048     if (numRows != fcat.getNumHdus()-1 and useEmptyCat == false)
00049     {
00050       //throw DataBuilderException("Pixel and catalog file mismatch!");
00051       log.addSysInfo("in " + fpix.getFileName() + "," + fcat.getFileName() +
00052                      " (pix and cat mismatch)");
00053       data = new TableData<DataType>(0, 0);
00054     }
00055     else
00056     {
00057       int numCols = mInfo.getNumAttributes();
00058       data = new TableData<DataType>(numCols, numRows);
00059 
00060       // Insert values from primary HDU if any
00061       for (int rowNo = 0; rowNo < numRows; ++rowNo)
00062       {
00063         insertFitsPrimaryHeader(rowNo, fpix, mInfo, *data);
00064       }
00065 
00066       // Loop over all extension HDUs
00067       for (int rowNo = 0; rowNo < numRows; ++rowNo)
00068       {
00069         int hduNo = rowNo + 2;
00070         fpix.movabsHdu(hduNo);
00071         insertFitsExtensionHeader(rowNo, fpix, mInfo, *data);
00072 
00073         if (useEmptyCat == false)
00074         {
00075           fcat.movabsHdu(hduNo);
00076           insertFitsExtensionHeader(rowNo, fcat, mInfo, *data);
00077         }
00078       }
00079       insertExtNum(fpix, mInfo, *data);
00080     }
00081     return data;
00082   }
00083 
00084 private:
00085   TableInfo mInfo;
00086 };
00087 //-----------------------------------------------------------------------------
00088 #endif
00089 //-----------------------------------------------------------------------------
00090 // Change log:
00091 //
00092 // 27-May-2004,  IAB: Original version.
Generated on Mon Oct 4 10:38:34 2010 for WfcamSrc by  doxygen 1.6.3