Provenance.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 PROVENANCE_H
00008 #define PROVENANCE_H
00009 
00010 #include "Constants.h"
00011 #include "DataBuilder.hxx"
00012 #include "Logger.h"
00013 #include "TableInfo.h"
00014 //-----------------------------------------------------------------------------
00018 template<typename DataType>
00019 class Provenance : public DataBuilder<DataType>
00020 {
00021 public:
00023   Provenance(const TableInfo& aInfo)
00024     : mInfo(aInfo)
00025     { DataBuilder<DataType>::builderName = "Provenance"; }
00026 
00028   virtual ~Provenance() {}
00029 
00032   TableData<DataType>* build(FitsFile& fpix, FitsFile& fcat, int fileNo)
00033   {
00034     // Number of columns in the data table is the number of attributes
00035     // in the schema
00036     int numCols = mInfo.getNumAttributes();
00037 
00038     // Number of rows is the number of PROV#### keywords in the schema
00039     int numRows = 0;
00040 
00041     // Look at cards in the first extension HDU
00042     fpix.movabsHdu(2);
00043 
00044     StringMap prov;
00045 
00046     // Check keynames for all cards in this HDU
00047     int numCards = fpix.getNumCards();
00048     for (int n = 0; n < numCards; ++n) {
00049 
00050       string keyname = fpix.readKeyname(n);
00051 
00052       // If keyname starts with "PROV", then this is a row in the
00053       // table and its number is not 0000
00054       if (keyname.find("PROV", 0) == 0) {
00055 
00056         if (keyname != "PROV0000"){
00057             string value;
00058             fpix.readKey(keyname, value);
00059             prov[numRows] = value;
00060             ++numRows;
00061         }
00062       }
00063     }
00064 
00065     // Create correctly dimensioned table
00066     TableData<DataType> *data = new TableData<DataType>(numCols, numRows);
00067 
00068     if (numRows >= 0)
00069     {
00070       // Put in the values for the PROV keywords in the column whos
00071       // attribute name is multiframeID
00072       int colNo = mInfo.getAttNo(ExpectNames::multiframeID);
00073       if (colNo != TableInfo::ColNotFound)
00074       {
00075         for (int rowNo = 0; rowNo < numRows; ++rowNo)
00076         {
00077           data->assign(colNo, rowNo, prov[rowNo]);
00078         }
00079       }
00080       else
00081       {
00082         Logger log;
00083         log.addMessage("Warning!: Cannot find attribute " +
00084                        ExpectNames::multiframeID + " in schema table " +
00085                        mInfo.getTableName());
00086       }
00087     }
00088 
00089     return data;
00090   }
00091 
00092 private:
00093   TableInfo mInfo;
00094 };
00095 //-----------------------------------------------------------------------------
00096 #endif
00097 //-----------------------------------------------------------------------------
00098 // Change log:
00099 //
00100 // 27-May-2004,  IAB: Original version.
Generated on Mon Oct 4 10:38:34 2010 for WfcamSrc by  doxygen 1.6.3