casacore
TableTrace.h
Go to the documentation of this file.
1 //# TableTrace.h: Class with static functions for tracing column IO
2 //# Copyright (C) 2014
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: BaseColumn.h 21130 2011-10-18 07:39:05Z gervandiepen $
27 
28 #ifndef TABLES_COLUMNTRACE_H
29 #define TABLES_COLUMNTRACE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Utilities/Regex.h>
35 #include <ostream>
36 #include <fstream>
37 #include <vector>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward Declarations.
42 class ColumnDesc;
43 class RefRows;
44 class IPosition;
45 
46 
47 // <summary>
48 // Class with static functions for tracing column IO
49 // </summary>
50 
51 // <use visibility=local>
52 
53 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
54 // </reviewed>
55 
56 // <synopsis>
57 // This class contains some static functions to enable table and column tracing.
58 // It maintains a map of table name to table-id.
59 // <br>
60 // The following aipsrc variables variables determine if tracing will be done,
61 // and if so, which columns and operations will be traced.
62 // <ul>
63 // <li> <src>table.trace.filename</src> gives the name of the file in which
64 // the trace will be written. If empty (default), no tracing will be done.
65 // <li> <src>table.trace.operation</src> gives the operation to trace.
66 // be traced. It can be one or more of:
67 // <br>s: creation of RefTable (selection/sort/iter)
68 // <br>r: reads
69 // <br>w: writes
70 // <br>The default is ''. Note that opening and closing a PlainTable
71 // are always traced.
72 // <li> <src>table.trace.columntype</src> gives the types of columns to trace
73 // for read and/or write.
74 // It can be one or more of:
75 // <br> s: scalar columns
76 // <br> a: array columns
77 // <br> r: record columns
78 // <br>The default is ''.
79 // <li> <src>table.trace.column</src> gives names of additional columns to
80 // trace for read and/or write.
81 // The names are separated by commas without any whitespace.
82 // Each name can be a glob-like pattern.
83 // <br>The default is ''.
84 // </ul>
85 // If both <src>table.trace.columntype</src> and <src>table.trace.column</src>
86 // have an empty value, all array columns are traced.
87 
89 {
90 public:
91  enum ColType {
92  SCALAR = 1,
93  ARRAY = 2,
94  RECORD = 4
95  };
96  enum Oper {
97  READ = 1,
98  WRITE = 2
99  };
100 
101  // Does the given column have to be traced for read and/or write?
102  // bit 0 set means read tracing; bit 1 write tracing.
103  static int traceColumn (const ColumnDesc&);
104 
105  // If needed, write a trace message for table open or create.
106  // It adds the table to the map and returns the table-id.
107  static int traceTable (const String& tableName, char oper);
108 
109  // If needed, trace closing a table.
110  // It removes the table from the map.
111  static void traceClose (const String& tableName);
112 
113  // If needed, trace an operation on a table.
114  static void traceFile (int tabid, const String& oper);
115 
116  // If needed, write a trace message for reftable open, create, or close.
117  static void traceRefTable (const String& parentName, char oper);
118 
119  // If needed, write a trace message
120  // Write a trace message for a scalar column.
121  static void trace (int tabid, const String& columnName, char oper);
122  // Write a trace message for a scalar row.
123  static void trace (int tabid, const String& columnName, char oper,
124  Int64 row);
125  // Write a trace message for ranges of scalar rows.
126  static void trace (int tabid, const String& columnName, char oper,
127  const RefRows& rownrs);
128  // Write a trace message for an array column.
129  static void trace (int tabid, const String& columnName, char oper,
130  const IPosition& shape);
131  // Write a trace message for an array row.
132  static void trace (int tabid, const String& columnName, char oper,
133  Int64 row, const IPosition& shape);
134  // Write a trace message for ranges of array rows.
135  static void trace (int tabid, const String& columnName, char oper,
136  const RefRows& rownrs, const IPosition& shape);
137  // Write a trace message for an array column slice.
138  static void trace (int tabid, const String& columnName, char oper,
139  const IPosition& shape,
140  const IPosition& blc, const IPosition& trc,
141  const IPosition& inc);
142  // Write a trace message for an array row slice.
143  static void trace (int tabid, const String& columnName, char oper,
144  Int64 row, const IPosition& shape,
145  const IPosition& blc, const IPosition& trc,
146  const IPosition& inc);
147  // Write a trace message for ranges of array rows slice.
148  static void trace (int tabid, const String& columnName, char oper,
149  const RefRows& rownrs, const IPosition& shape,
150  const IPosition& blc, const IPosition& trc,
151  const IPosition& inc);
152 
153 private:
154  // Initialize the tracing mechanism which should be done only once.
155  static void initTracing();
156  static void initOper();
157  static void initColumn();
158 
159  // Find the table name in the vector. -1 is returned if not found.
160  static int findTable (const String& name);
161 
162  // Write the first part of the trace message.
163  static void writeTraceFirst (int tabid, const String& name, char oper);
164 
165  // Write the RefRows as vector of rows or slices.
166  static void writeRefRows (const RefRows& rownrs);
167 
168  // Write the blc, trc, and inc of an array slice.
169  static void writeSlice (const IPosition& blc,
170  const IPosition& trc,
171  const IPosition& inc);
172 
173  //# Data members
174  static std::ofstream theirTraceFile;
175  static int theirDoTrace; //# 0=init -1=no 1=yes 2=reftable
176  static int theirOper; //# 1=rtrace 2=wtrace
177  static int theirColType; //# 1=scalar 2=array 4=record
178  static std::vector<Regex> theirColumns;
179  static std::vector<String> theirTables;
180 };
181 
182 
183 
184 
185 } //# NAMESPACE CASACORE - END
186 
187 #endif
static void writeRefRows(const RefRows &rownrs)
Write the RefRows as vector of rows or slices.
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
static void initColumn()
static int theirDoTrace
Definition: TableTrace.h:175
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
static std::vector< Regex > theirColumns
Definition: TableTrace.h:178
static int theirColType
Definition: TableTrace.h:177
Class with static functions for tracing column IO.
Definition: TableTrace.h:88
static int findTable(const String &name)
Find the table name in the vector.
Envelope class for the description of a table column.
Definition: ColumnDesc.h:131
static int traceTable(const String &tableName, char oper)
If needed, write a trace message for table open or create.
static void traceRefTable(const String &parentName, char oper)
If needed, write a trace message for reftable open, create, or close.
static void writeSlice(const IPosition &blc, const IPosition &trc, const IPosition &inc)
Write the blc, trc, and inc of an array slice.
static int theirOper
Definition: TableTrace.h:176
static std::ofstream theirTraceFile
Definition: TableTrace.h:174
static void writeTraceFirst(int tabid, const String &name, char oper)
Write the first part of the trace message.
static void traceClose(const String &tableName)
If needed, trace closing a table.
static void initOper()
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
static void trace(int tabid, const String &columnName, char oper)
If needed, write a trace message Write a trace message for a scalar column.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:2015
static std::vector< String > theirTables
Definition: TableTrace.h:179
static void traceFile(int tabid, const String &oper)
If needed, trace an operation on a table.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static int traceColumn(const ColumnDesc &)
Does the given column have to be traced for read and/or write? bit 0 set means read tracing; bit 1 wr...
static void initTracing()
Initialize the tracing mechanism which should be done only once.
this file contains all the compiler specific defines
Definition: mainpage.dox:28