source: trunk/src/Detection/columns.hh @ 1044

Last change on this file since 1044 was 1044, checked in by MatthewWhiting, 12 years ago

Incorporating the UCD, datatype, ref (as "extraInfo") and colID into the Column::Col structure. This allows the definition of a VOField directly from the Col, streamlining the code somewhat. Use default arrays to define most of these things - some UCDs are set in Cubes/VOTable.cc for now.

File size: 11.7 KB
Line 
1// -----------------------------------------------------------------------
2// columns.hh: Define the column class that formats Duchamp output.
3// -----------------------------------------------------------------------
4// Copyright (C) 2006, Matthew Whiting, ATNF
5//
6// This program is free software; you can redistribute it and/or modify it
7// under the terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2 of the License, or (at your
9// option) any later version.
10//
11// Duchamp is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Duchamp; if not, write to the Free Software Foundation,
18// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19//
20// Correspondence concerning Duchamp may be directed to:
21//    Internet email: Matthew.Whiting [at] atnf.csiro.au
22//    Postal address: Dr. Matthew Whiting
23//                    Australia Telescope National Facility, CSIRO
24//                    PO Box 76
25//                    Epping NSW 1710
26//                    AUSTRALIA
27// -----------------------------------------------------------------------
28#ifndef COLUMNS_H
29#define COLUMNS_H
30
31#include <iostream>
32#include <iomanip>
33#include <string>
34#include <vector>
35
36namespace duchamp
37{
38
39  class Detection;
40  class FitsHeader;
41
42  /// A namespace controlling the formatting of columns of output for Duchamp.
43
44  namespace Column
45  {
46    // First, define some basic quantities.
47    // The default values for the columns, and default values for
48    //  the precision of different types of columns.
49
50    /// @brief Total number of columns being considered.
51    const int numColumns=38;   
52    /// @brief Enumerated column titles
53    enum COLNAME {NUM=0, NAME, X, Y, Z,
54                  RA, DEC, RAJD, DECJD, VEL,
55                  WRA, WDEC, W50, W20, WVEL,
56                  FINT, FTOT, FPEAK, SNRPEAK,
57                  X1, X2, Y1, Y2, Z1, Z2, NPIX, FLAG,
58                  XAV, YAV, ZAV, XCENT, YCENT, ZCENT,
59                  XPEAK, YPEAK, ZPEAK,
60                  NUMCH, SPATSIZE,
61                  UNKNOWN};  // the last is for unclassified columns
62
63    /// @brief Guide for which columns are used for the results file
64    const bool isFile[numColumns+1]=
65      {true,true,true,true,true,
66       true,true,false,false,true,
67       true,true,true,true,true,
68       true,true,true,true,
69       true,true,true,true,true,true,true,true,
70       true,true,true,true,true,true,
71       true,true,true,
72       false,false,
73       false};
74
75    /// @brief Guide for which columns are used for the results printed to screen
76    const bool isScreen[numColumns+1]=
77      {true,true,true,true,true,
78       true,true,false,false,true,
79       true,true,true,false,false,
80       true,true,true,true,
81       true,true,true,true,true,true,true,true,
82       false,false,false,false,false,false,
83       false,false,false,
84       false,false,
85       false};
86
87    /// @brief Guide for which columns are used for the log file
88    const bool isLog[numColumns+1]=
89      {true,false,true,true,true,
90       false,false,false,false,false,
91       false,false,false,false,false,
92       false,true,true,true,
93       true,true,true,true,true,true,true,false,
94       false,false,false,false,false,false,
95       false,false,false,
96       true,true,
97       false};
98
99     /// @brief Guide for which columns are used for the VOTable file
100    const bool isVOTable[numColumns+1]=
101      {true,true,false,false,false,
102       false,false,true,true,true,
103       true,true,true,true,true,
104       true,true,true,true,
105       false,false,false,false,false,false,false,true,
106       true,true,true,true,true,true,
107       true,true,true,
108       false,false,
109       false};
110
111    /// @brief Total number of columns used in logfile (no WCS ones).
112    const int numColumnsLog=16;
113    /// @brief Enumerated column titles for logfile
114    enum LOGNAME {lNUM=0, lX, lY, lZ,
115                  lFTOT, lFPEAK, lSNRPEAK,
116                  lX1, lX2, lY1, lY2, lZ1, lZ2, lNPIX,
117                  lNUMCH, lSPATSIZE};
118
119    /// @brief Number of types of precision.
120    const int numPrec=6;       
121    /// @brief Enumerated precision categories
122    enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2};
123
124    /// @brief Default widths of all columns.
125    const int defaultWidth[numColumns+1]=
126      {5, 8, 6, 6, 6,
127       11, 10, 11, 11, 7,
128       9, 9, 7, 7, 7,
129       10, 10, 9, 7,
130       4, 4, 4, 4, 4, 4, 6, 5,
131       6, 6, 6, 7, 7, 7,
132       7, 7, 7,
133       6, 8,
134       1};
135
136    /// @brief Default precisions for all columns.
137    const int defaultPrec[numColumns+1]=
138      {0, 0, prXYZ, prXYZ, prXYZ,
139       0, 0, prPOS, prPOS, prVEL,
140       prWPOS, prWPOS, prVEL, prVEL, prVEL,
141       prFLUX, prFLUX, prFLUX,
142       prSNR, 0, 0, 0, 0, 0, 0, 0, 0,
143       prXYZ, prXYZ, prXYZ, prXYZ, prXYZ, prXYZ,
144       prXYZ, prXYZ, prXYZ,
145       0, 0,
146       0};
147
148    /// @brief Default Titles of all columns.
149    const std::string defaultName[numColumns+1]=
150      {"Obj#","Name","X","Y","Z",
151       "RA","DEC","RAJD","DECJD","VEL",
152       "w_RA","w_DEC","w_50","w_20","w_VEL",
153       "F_int","F_tot","F_peak", "S/Nmax",
154       "X1","X2","Y1","Y2","Z1","Z2","Npix","Flag",
155       "X_av", "Y_av", "Z_av", "X_cent", "Y_cent", "Z_cent",
156       "X_peak", "Y_peak", "Z_peak",
157       "Nch", "Sp_size",
158       " "};
159
160    /// @brief The column ID (for use in a VOTable)
161    const std::string defaultColID[numColumns+1]=
162      {"col_objnum","col_name","col_x","col_y","col_z",
163       "col_ra","col_dec","col_rajd","col_decjd","col_vel",
164       "col_wra","col_wdec","col_w50","col_w20","col_wvel",
165       "col_fint","col_ftot","col_fpeak", "col_snrmax",
166       "col_x1","col_x2","col_y1","col_y2","col_z1","col_z2","col_npix","col_flag",
167       "col_xav", "col_yav", "col_zav", "col_xcent", "col_ycent", "col_zcent",
168       "col_xpeak", "col_ypeak", "col_zpeak",
169       "col_nch", "col_spsize",
170       ""};
171
172    /// @brief Default units of all columns.
173    const std::string defaultUnits[numColumns+1]=
174      {"","","","","",
175       "","","[deg]","[deg]","",
176       "[arcmin]","[arcmin]","","","",
177       "","","", "",
178       "","","","","","","[pix]","",
179       "","","","","","","","","",
180       "","",
181       ""};
182
183    /// @brief Default UCDs for all columns
184    const std::string defaultUCDs[numColumns+1] =
185      {"meta.id", "meta.id;meta.main", "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
186       "", "", "", "", "",
187       "", "", "", "", "",
188       "phot.flux;spect.line.intensity", "phot.flux;spect.line.intensity", "phot.flux;spect.line.intensity", "phot.flux;stat.snr",
189       "pos.cartesian.x;stat.min", "pos.cartesian.y;stat.min", "pos.cartesian.z;stat.min", "pos.cartesian.x;stat.max", "pos.cartesian.y;stat.max", "pos.cartesian.z;stat.max", "", "meta.code.qual",
190       "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z", "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
191       "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
192       "",""
193       ""};
194
195    ///@brief The datatype of each column
196    const std::string defaultDatatype[numColumns+1] =
197      {"int", "char", "float", "float", "float",
198       "char", "char", "float", "float", "float",
199       "float", "float", "float", "float", "float",
200       "float", "float", "float", "float",
201       "int", "int", "int", "int", "int", "int", "int", "char",
202       "float", "float", "float", "float", "float", "float",
203       "int", "int", "int",
204       "int", "int",
205       ""};
206
207    const std::string coordRef="J2000";
208    /// @brief Default values for the VOTable reference string
209    const std::string defaultExtraInfo[numColumns+1] =
210      {"", "", "", "", "",
211       coordRef, coordRef, coordRef, coordRef, "",
212       coordRef, coordRef, "", "", "",
213       "", "", "", "",
214       "", "", "", "", "", "", "", "",
215       "", "", "", "", "", "",
216       "", "", "",
217       "", "",
218       ""};
219
220    ///  @brief Class to store information about a single column.
221    ///
222    ///  @details This contains information about a given column --
223    ///  its width, the precision associated with it, its title and
224    ///  the units.  Plus the usual array of accessor functions and so
225    ///  on.
226
227    class Col{
228    public:
229      Col();          ///< Basic constructor
230      Col(int num, int prec=-1);   ///< Specific constructor
231      Col(std::string name, std::string units, int width, int prec, std::string ucd="", std::string datatype="", std::string extraInfo=""); ///< Generic constructor
232      Col(const Col& c);///< Assignment constructor
233      Col& operator=(const Col& c); ///< Copy constructor
234      virtual ~Col(); ///< Default destructor;
235      //--------------
236      // basic accessor functions
237      //
238      int    getWidth(){return width;};         
239      void   setWidth(int i){width=i;};   
240      int    getPrecision(){return precision;};     
241      void   setPrecision(int i){precision=i;};
242      std::string getName(){return name;};         
243      void   setName(std::string s){name=s;}; 
244      std::string getUnits(){return units;};         
245      void   setUnits(std::string s){units=s;};
246      COLNAME getType(){return type;};
247      void   setType(COLNAME coltype){type=coltype;};
248      std::string getUCD(){return UCD;};
249      void        setUCD(std::string s){UCD=s;};
250      std::string getDatatype(){return datatype;};
251      void        setDatatype(std::string s){datatype=s;};
252      std::string getColID(){return colID;};
253      void        setColID(std::string s){colID=s;};
254      std::string getExtraInfo(){return extraInfo;};
255      void        setExtraInfo(std::string s){extraInfo=s;};
256
257      //--------------
258      // other functions
259      //
260      /// @brief Make the column one space wider.
261      void   widen(){width++;};
262
263      /// @brief Increase the precision by one, widening the column if necessary.
264      void   upPrec(){precision++; width++;};
265
266      void   changePrec(int p);
267
268      //--------------
269      // Outputting functions -- all in columns.cc
270      //
271      /// @brief write the title of the column to the stream
272      void   printTitle(std::ostream &stream);
273
274      /// @brief write the units of the column to the stream
275      void   printUnits(std::ostream &stream);
276
277      /// @brief write dashes the full width of the column to the stream
278      void   printDash (std::ostream &stream);
279
280      /// @brief write blanks the full width of the column to the stream
281      void   printBlank(std::ostream &stream);
282
283      /// @brief Print a given value in a column with correct width & precision.
284      template <class T> void printEntry(std::ostream &stream, T value);
285
286      /// @brief Decides whether the column is used for a given table type
287      bool   doCol(std::string type, bool flagFint=true);
288
289
290    private:
291      int width;          ///< How wide is the column (in ascii spaces)
292      int precision;      ///< What precision should be used to print the values? (If 0, the setprecision command is not used.)
293      std::string name;   ///< The title of the column
294      std::string units;  ///< The units that the values in the column are expressed in.
295      std::string UCD;    ///< The UCD associated with the value
296      std::string datatype; ///< What datatype do the values take?
297      std::string extraInfo; ///< Any other info? This can be the 'ref' entry for a VOTable field.
298      std::string colID;  ///< The column ID
299      COLNAME type;       ///< The type of the column
300    };
301
302 
303    /// @brief Returns a vector of Col for results file output.
304    std::vector<Column::Col> getFullColSet(std::vector<Detection> &objectList,
305                                           FitsHeader &head);
306
307    /// @brief Returns a vector of Col for logfile output.
308    std::vector<Column::Col> getLogColSet(std::vector<Detection> &objectList,
309                                          FitsHeader &head);
310
311  }
312
313}
314
315#endif
316
Note: See TracBrowser for help on using the repository browser.