casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FlagVersion.h
Go to the documentation of this file.
00001 //# FlagVersions.h: Maintain and manage different flag versions.
00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have receied a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 //#
00028 //# ----------------------------------------------------------------------------
00029 //# Change Log
00030 //# ----------------------------------------------------------------------------
00031 //# Date         Name             Comments
00032 //# 
00033 
00034 
00035 #ifndef FLAGVERSION_H
00036 #define FLAGVERSION_H
00037 
00038 //# Includes
00039 
00040 #include <casa/aips.h>
00041 #include <casa/iostream.h>
00042 #include <casa/OS/Timer.h>
00043 #include <casa/OS/File.h>
00044 
00045 #include <casa/Arrays/Vector.h>
00046 #include <casa/Arrays/Array.h>
00047 #include <casa/Arrays/Matrix.h>
00048 #include <casa/Arrays/Slicer.h>
00049 
00050 #include <tables/Tables/Table.h>
00051 #include <tables/Tables/ArrayColumn.h>
00052 #include <tables/Tables/ScalarColumn.h>
00053 #include <tables/Tables/TableColumn.h>
00054 
00055 #include <flagging/Flagging/SLog.h>
00056 
00057 //# FlagVersion Change Log
00058 //# =======================
00059 //# Date              Name      Description
00060 //# April 20 2007    Urvashi R.V.       Created this class.
00061 //# Aug 23 2007      Urvashi R.V.       Added Documentation.
00062 //# Oct 29 2007      Shannon J.         Switched how msg logging was done.
00063 
00064 namespace casa { //# NAMESPACE CASA - BEGIN
00065 
00066 // <summary>
00067 // Class to generate and manage flag versions for Tables containing flag columns. 
00068 // </summary>
00069 
00070 // <reviewed reviewer="" date="" tests="">
00071 // </reviewed>
00072 
00073 // <prerequisite>
00074 //   <li> Table 
00075 // </prerequisite>
00076 
00077 // <etymology>
00078 // Manages Flag Versions.
00079 // </etymology>
00080 
00081 // <synopsis>
00082 // This class creates and manages flag versions. A flag version as defined in this
00083 // class has the following structure.
00084 //
00085 //    xxxx.ms
00086 //    xxxx.ms.flagversions
00087 //
00088 // When first opened, a flagversions directory is created parallel to the original Table.
00089 // This directory contains a text file : FLAG_VERSION_LIST that holds a list of string pairs
00090 //      version name  :  comment for this version.
00091 //
00092 // The FLAG and FLAG_ROW columns of the main table are copied into new Tables with only two
00093 // columns, whenever a new flag version is created.  Flag versions can be merged using
00094 // logical 'and', logical 'or', and 'replace' semantics. Flag versions can be restored to
00095 // the main table of the MS.
00096 //
00097 // At the end of a "save" or "restore" operation, the latest flags are always also in
00098 // the main table.
00099 // 
00100 // </synopsis>
00101 
00102 // <motivation>
00103 //  
00104 // </motivation>
00105 
00106 // <thrown>
00107 //    <li>
00108 //    <li>
00109 // </thrown>
00110 
00111 
00112 // <todo asof="$DATE:$">
00113 //   <li> 
00114 // </todo>
00115 
00116        
00117 class FlagVersion 
00118 {
00119    public:
00120       // Constructor
00121       FlagVersion(String intab, String dataflagcolname, String rowflagcolname);  
00122 
00123       // Destructor
00124       virtual ~FlagVersion();
00125 
00126       // Operator=
00127       // Equate by reference.
00128       FlagVersion& operator=(const FlagVersion&){return *this;}
00129       
00130       // Get a list of entries from the version-list file for this table 
00131       Vector<String> getVersionList();
00132 
00133       // Specify the Table column names to use as flag columns.
00134       // For example, for a MS, they are "FLAG" and "FLAG_ROW". 
00135       Bool attachFlagColumns(String version, ScalarColumn<Bool> &rowflag, 
00136                  ArrayColumn<Bool> &flags, Table &subtab);
00137 
00138       // Save current main table flags into a separate version 
00139       // These keeps a copy in the main table too. 
00140       // "merge" can be one of 'or','and','replace'
00141       Bool saveFlagVersion( String versionname, String comment, 
00142                   String merge=String("replace") );
00143 
00144       // Copy flags from a flag version, into the main table 
00145       Bool restoreFlagVersion(String versionname, 
00146                      String merge=String("replace") );
00147 
00148       // Delete a version. This does not touch or update the main table 
00149       Bool deleteFlagVersion( String versionname );
00150 
00151       // Clear all main table flags 
00152       Bool clearAllFlags();
00153 
00154    private:
00155       void FlagVersionError( String msg );
00156       
00157       Bool readVersionList();
00158       Bool saveFlagsInto(Table &fromFTab, Table &toFTab, 
00159                 String merge = String("replace"));
00160       Bool doesVersionExist( String versionname );
00161 
00162       /* Variables to be maintained for the root Table */
00163       String verlistfile_p;
00164       String flagtablename_p;
00165       String dataflagcolname_p;
00166       String rowflagcolname_p;
00167 
00168       Table tab_p;
00169       String tabname_p;
00170       Vector<String> versionlist_p;
00171       Vector<String> commentlist_p;
00172       Bool fcol_p, frcol_p;
00173       unsigned nrows_p;
00174 
00175       Table subflagtable_p;
00176 
00177       File file_p;
00178       
00179       SLog* log;
00180       static String clname;
00181 };
00182 
00183 } //# NAMESPACE CASA - END 
00184 
00185 //#ifndef AIPS_NO_TEMPLATE_SRC
00186 //#include <tableplot/TablePlot/FlagVersion.tcc>
00187 //#endif //# AIPS_NO_TEMPLATE_SRC
00188 #endif
00189