TableTrace.h

Go to the documentation of this file.
00001 //# TableTrace.h: Class with static functions for tracing column IO
00002 //# Copyright (C) 2014
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 received 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: BaseColumn.h 21130 2011-10-18 07:39:05Z gervandiepen $
00027 
00028 #ifndef TABLES_TABLETRACE_H
00029 #define TABLES_TABLETRACE_H
00030 
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/casa/Utilities/Regex.h>
00035 #include <casacore/casa/OS/Mutex.h>
00036 #include <ostream>
00037 #include <fstream>
00038 #include <vector>
00039 
00040 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00041 
00042 //# Forward Declarations.
00043 class ColumnDesc;
00044 class RefRows;
00045 class IPosition;
00046 
00047 
00048 // <summary>
00049 // Class with static functions for tracing column IO
00050 // </summary>
00051 
00052 // <use visibility=local>
00053 
00054 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00055 // </reviewed>
00056 
00057 // <synopsis> 
00058 // This class contains some static functions to enable table and column tracing.
00059 // It maintains a map of table name to table-id.
00060 // <br>
00061 // The following aipsrc variables variables determine if tracing will be done,
00062 // and if so, which columns and operations will be traced.
00063 // <ul>
00064 //  <li> <src>table.trace.filename</src> gives the name of the file in which
00065 //       the trace will be written. If empty (default), no tracing will be done.
00066 //       If 'stdout' is given, tracing is done to stdout.
00067 //       If 'stderr' is given, tracing is done to stderr.
00068 //  <li> <src>table.trace.operation</src> gives the operation to trace.
00069 //       be traced. It can be one or more of:
00070 //       <br>s: creation of RefTable (selection/sort/iter)
00071 //       <br>r: reads
00072 //       <br>w: writes
00073 //       <br>The default is ''. Note that opening and closing a PlainTable
00074 //       are always traced.
00075 //  <li> <src>table.trace.columntype</src> gives the types of columns to trace
00076 //       for read and/or write.
00077 //       It can be one or more of:
00078 //       <br> s: scalar columns
00079 //       <br> a: array columns
00080 //       <br> r: record columns
00081 //       <br>The default is ''.
00082 //  <li> <src>table.trace.column</src> gives names of additional columns to
00083 //       trace for read and/or write.
00084 //       The names are separated by commas without any whitespace.
00085 //       Each name can be a glob-like pattern.
00086 //       <br>The default is ''.
00087 // </ul>
00088 // If both <src>table.trace.columntype</src> and <src>table.trace.column</src>
00089 // have an empty value, all array columns are traced.
00090 
00091 class TableTrace
00092 {
00093 public:
00094   enum ColType {
00095     SCALAR = 1,
00096     ARRAY  = 2,
00097     RECORD = 4
00098   };
00099   enum Oper {
00100     READ  = 1,
00101     WRITE = 2
00102   };
00103 
00104   // Does the given column have to be traced for read and/or write?
00105   // bit 0 set means read tracing; bit 1 write tracing.
00106   static int traceColumn (const ColumnDesc&);
00107 
00108   // If needed, write a trace message for table open or create.
00109   // It adds the table to the map and returns the table-id.
00110   static int traceTable (const String& tableName, char oper);
00111 
00112   // If needed, trace closing a table.
00113   // It removes the table from the map.
00114   static void traceClose (const String& tableName);
00115 
00116   // If needed, trace an operation on a table.
00117   static void traceFile (int tabid, const String& oper);
00118 
00119   // If needed, write a trace message for reftable open, create, or close.
00120   static void traceRefTable (const String& parentName, char oper);
00121 
00122   // If needed, write a trace message 
00123   // Write a trace message for a scalar column.
00124   static void trace (int tabid, const String& columnName, char oper);
00125   // Write a trace message for a scalar row.
00126   static void trace (int tabid, const String& columnName, char oper,
00127                      Int64 row);
00128   // Write a trace message for ranges of scalar rows.
00129   static void trace (int tabid, const String& columnName, char oper,
00130                      const RefRows& rownrs);
00131   // Write a trace message for an array column.
00132   static void trace (int tabid, const String& columnName, char oper,
00133                      const IPosition& shape);
00134   // Write a trace message for an array row.
00135   static void trace (int tabid, const String& columnName, char oper,
00136                      Int64 row, const IPosition& shape);
00137   // Write a trace message for ranges of array rows.
00138   static void trace (int tabid, const String& columnName, char oper,
00139                      const RefRows& rownrs, const IPosition& shape);
00140   // Write a trace message for an array column slice.
00141   static void trace (int tabid, const String& columnName, char oper,
00142                      const IPosition& shape,
00143                      const IPosition& blc, const IPosition& trc,
00144                      const IPosition& inc);
00145   // Write a trace message for an array row slice.
00146   static void trace (int tabid, const String& columnName, char oper,
00147                      Int64 row, const IPosition& shape,
00148                      const IPosition& blc, const IPosition& trc,
00149                      const IPosition& inc);
00150   // Write a trace message for ranges of array rows slice.
00151   static void trace (int tabid, const String& columnName, char oper,
00152                      const RefRows& rownrs, const IPosition& shape,
00153                      const IPosition& blc, const IPosition& trc,
00154                      const IPosition& inc);
00155 
00156 private:
00157   // Initialize the tracing mechanism which should be done only once.
00158   static void initTracing();
00159   static void initOper();
00160   static void initColumn();
00161 
00162   // Find the table name in the vector. -1 is returned if not found.
00163   static int findTable (const String& name);
00164 
00165   // Write the first part of the trace message.
00166   static void writeTraceFirst (int tabid, const String& name, char oper);
00167 
00168   // Write the RefRows as vector of rows or slices.
00169   static void writeRefRows (const RefRows& rownrs);
00170 
00171   // Write the blc, trc, and inc of an array slice.
00172   static void writeSlice (const IPosition& blc,
00173                           const IPosition& trc,
00174                           const IPosition& inc);
00175 
00176   //# Data members
00177   static Mutex               theirMutex;
00178   static std::ofstream       theirTraceFile;
00179   static std::ostream*       theirStream;
00180   static int                 theirDoTrace;   //# 0=init -1=no 1=yes 2=reftable
00181   static int                 theirOper;      //# 1=rtrace 2=wtrace
00182   static int                 theirColType;   //# 1=scalar 2=array 4=record
00183   static std::vector<Regex>  theirColumns;
00184   static std::vector<String> theirTables;
00185 };
00186 
00187 
00188 
00189 
00190 } //# NAMESPACE CASACORE - END
00191 
00192 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1