FrameID.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef FRAMEID_H
00008 #define FRAMEID_H
00009
00010 #include <string>
00011
00012 #include "DataMethod.hxx"
00013 #include "DataOps.h"
00014 #include "FitsFile.h"
00015 #include "Logger.h"
00016
00018 template<typename DataType>
00019 class DirectFrameID : public DataMethod<DataType>
00020 {
00021 public:
00024 DirectFrameID(const FitsFile& aFile)
00025 {
00026 DataMethod<DataType>::methodName = "DirectFrameID";
00027 mFrameID = DataOps::makeFrameID(aFile);
00028 }
00029
00031 ~DirectFrameID() { }
00032
00034 void setSource(IntMap& tbls, IntMap& cols, StringMap units) { }
00035
00037 void setTarget(IntMap& cols, StringMap units) { colNo = cols[0]; }
00038
00041 void doit(TableData<DataType>& data, int row1, int row2)
00042 {
00043 for (int rowNo = row1; rowNo < row2; ++rowNo)
00044 {
00045 data.assign(colNo, rowNo, mFrameID);
00046 }
00047 }
00048
00049
00050
00051 void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) { }
00052
00053 private:
00054 int colNo;
00055 std::string mFrameID;
00056 };
00057
00060 template<typename DataType>
00061 class IndirectFrameID : public DataMethod<DataType>
00062 {
00063 public:
00065 IndirectFrameID(const std::string& aFilePath)
00066 : mFilePath(aFilePath)
00067 { DataMethod<DataType>::methodName = "IndirectFrameID"; }
00068
00070 virtual ~IndirectFrameID() { }
00071
00073 void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00074 {
00075 fileColno = cols[0];
00076 if (fileColno < 0)
00077 {
00078 throw DataMethodException("IndirectFrameID method. Couldn't source");
00079 }
00080 }
00081
00083 void setTarget(IntMap& cols, StringMap units) { fidColno = cols[0]; }
00084
00086 void doit(TableData<DataType>& data, int row1, int row2)
00087 {
00088 Logger log;
00089
00090 for (int rowNo = row1; rowNo < row2; ++rowNo)
00091 {
00092 std::string fileName;
00093 data.value(fileColno, rowNo, fileName);
00094
00095 if (fileName.length() > 0)
00096 {
00097 int posb = fileName.rfind(".fit")+4;
00098 int posa = 0;
00099 if (fileName.rfind(" ") != std::string::npos)
00100 {
00101 posa = (int) fileName.rfind(" ",posb)+1;
00102 }
00103
00104 fileName = mFilePath + fileName.substr(posa,posb-posa);
00105
00106 log.addMessage("Calculate frame ID from this file name: '"
00107 + fileName + "'");
00108 }
00109 else
00110 {
00111 log.addMessage("No file name available.");
00112 }
00113
00114
00115
00116 try
00117 {
00118 FitsFile fitsFile(fileName);
00119 std::string frameID = DataOps::makeFrameID(fitsFile);
00120 fitsFile.closeFile();
00121
00122
00123 if (frameID == "0")
00124 {
00125 data.setundef(fidColno, rowNo);
00126 }
00127 else
00128 {
00129 data.assign(fidColno, rowNo, frameID);
00130 }
00131 }
00132 catch (FitsIOException)
00133 {
00134
00135
00136
00137 data.setundef(fidColno, rowNo);
00138 log.addWarning("Could not open FITS file object for " + fileName);
00139 }
00140 }
00141 }
00142
00143
00144 void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) { }
00145
00146 private:
00147 int fidColno;
00148 int fileColno;
00149 std::string mFilePath;
00150 };
00151
00152 #endif
00153
00154
00155
00156
00157
00158
00159
00160