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_TABLETRACE_H
29 #define TABLES_TABLETRACE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Utilities/Regex.h>
35 
36 #include <fstream>
37 #include <mutex>
38 #include <ostream>
39 #include <vector>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 //# Forward Declarations.
44 class ColumnDesc;
45 class RefRows;
46 class IPosition;
47 
48 
49 // <summary>
50 // Class with static functions for tracing column IO
51 // </summary>
52 
53 // <use visibility=local>
54 
55 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
56 // </reviewed>
57 
58 // <synopsis>
59 // This class contains some static functions to enable table and column tracing.
60 // It maintains a map of table name to table-id.
61 // <br>
62 // The following aipsrc variables variables determine if tracing will be done,
63 // and if so, which columns and operations will be traced.
64 // <ul>
65 // <li> <src>table.trace.filename</src> gives the name of the file in which
66 // the trace will be written. If empty (default), no tracing will be done.
67 // If 'stdout' is given, tracing is done to stdout.
68 // If 'stderr' is given, tracing is done to stderr.
69 // <li> <src>table.trace.operation</src> gives the operation to trace.
70 // be traced. It can be one or more of:
71 // <br>s: creation of RefTable (selection/sort/iter)
72 // <br>r: reads
73 // <br>w: writes
74 // <br>The default is ''. Note that opening and closing a PlainTable
75 // are always traced.
76 // <li> <src>table.trace.columntype</src> gives the types of columns to trace
77 // for read and/or write.
78 // It can be one or more of:
79 // <br> s: scalar columns
80 // <br> a: array columns
81 // <br> r: record columns
82 // <br>The default is ''.
83 // <li> <src>table.trace.column</src> gives names of additional columns to
84 // trace for read and/or write.
85 // The names are separated by commas without any whitespace.
86 // Each name can be a glob-like pattern.
87 // <br>The default is ''.
88 // </ul>
89 // If both <src>table.trace.columntype</src> and <src>table.trace.column</src>
90 // have an empty value, all array columns are traced.
91 
93 {
94 public:
95  enum ColType {
96  SCALAR = 1,
97  ARRAY = 2,
98  RECORD = 4
99  };
100  enum Oper {
101  READ = 1,
102  WRITE = 2
103  };
104 
105  // Does the given column have to be traced for read and/or write?
106  // bit 0 set means read tracing; bit 1 write tracing.
107  static int traceColumn (const ColumnDesc&);
108 
109  // If needed, write a trace message for table open or create.
110  // It adds the table to the map and returns the table-id.
111  static int traceTable (const String& tableName, char oper);
112 
113  // If needed, trace closing a table.
114  // It removes the table from the map.
115  static void traceClose (const String& tableName);
116 
117  // If needed, trace an operation on a table.
118  static void traceFile (int tabid, const String& oper);
119 
120  // If needed, write a trace message for reftable open, create, or close.
121  static void traceRefTable (const String& parentName, char oper);
122 
123  // If needed, write a trace message
124  // Write a trace message for a scalar column.
125  static void trace (int tabid, const String& columnName, char oper);
126  // Write a trace message for a scalar row.
127  static void trace (int tabid, const String& columnName, char oper,
128  Int64 row);
129  // Write a trace message for ranges of scalar rows.
130  static void trace (int tabid, const String& columnName, char oper,
131  const RefRows& rownrs);
132  // Write a trace message for an array column.
133  static void trace (int tabid, const String& columnName, char oper,
134  const IPosition& shape);
135  // Write a trace message for an array row.
136  static void trace (int tabid, const String& columnName, char oper,
137  Int64 row, const IPosition& shape);
138  // Write a trace message for ranges of array rows.
139  static void trace (int tabid, const String& columnName, char oper,
140  const RefRows& rownrs, const IPosition& shape);
141  // Write a trace message for an array column slice.
142  static void trace (int tabid, const String& columnName, char oper,
143  const IPosition& shape,
144  const IPosition& blc, const IPosition& trc,
145  const IPosition& inc);
146  // Write a trace message for an array row slice.
147  static void trace (int tabid, const String& columnName, char oper,
148  Int64 row, const IPosition& shape,
149  const IPosition& blc, const IPosition& trc,
150  const IPosition& inc);
151  // Write a trace message for ranges of array rows slice.
152  static void trace (int tabid, const String& columnName, char oper,
153  const RefRows& rownrs, const IPosition& shape,
154  const IPosition& blc, const IPosition& trc,
155  const IPosition& inc);
156 
157 private:
158  // Initialize the tracing mechanism which should be done only once.
159  static void initTracing(); // always called using theirCallOnce
160  static void initOper();
161  static void initColumn();
162 
163  // Find the table name in the vector. -1 is returned if not found.
164  static int findTable (const String& name);
165 
166  // Write the first part of the trace message.
167  static void writeTraceFirst (int tabid, const String& name, char oper);
168 
169  // Write the RefRows as vector of rows or slices.
170  static void writeRefRows (const RefRows& rownrs);
171 
172  // Write the blc, trc, and inc of an array slice.
173  static void writeSlice (const IPosition& blc,
174  const IPosition& trc,
175  const IPosition& inc);
176 
177  //# Data members
178  static std::once_flag theirCallOnceFlag; //# for thread-safe lazy init
179  static std::mutex theirMutex;
180  static std::ofstream theirTraceFile;
181  static std::ostream* theirStream;
182  static int theirDoTrace; //# 0=init -1=no 1=yes 2=reftable
183  static int theirOper; //# 1=rtrace 2=wtrace
184  static int theirColType; //# 1=scalar 2=array 4=record
185  static std::vector<Regex> theirColumns;
186  static std::vector<String> theirTables;
187 };
188 
189 
190 
191 
192 } //# NAMESPACE CASACORE - END
193 
194 #endif
String: the storage and methods of handling collections of characters.
Definition: String.h:225
static void trace(int tabid, const String &columnName, char oper, const RefRows &rownrs)
Write a trace message for ranges of scalar rows.
static void trace(int tabid, const String &columnName, char oper, const IPosition &shape)
Write a trace message for an array column.
static void trace(int tabid, const String &columnName, char oper, Int64 row)
Write a trace message for a scalar row.
static std::vector< String > theirTables
Definition: TableTrace.h:186
static std::mutex theirMutex
Definition: TableTrace.h:179
static std::ostream * theirStream
Definition: TableTrace.h:181
static void traceClose(const String &tableName)
If needed, trace closing a table.
static void initOper()
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 int findTable(const String &name)
Find the table name in the vector.
static std::vector< Regex > theirColumns
Definition: TableTrace.h:185
static void initTracing()
Initialize the tracing mechanism which should be done only once.
static void writeSlice(const IPosition &blc, const IPosition &trc, const IPosition &inc)
Write the blc, trc, and inc of an array slice.
static int traceTable(const String &tableName, char oper)
If needed, write a trace message for table open or create.
static void trace(int tabid, const String &columnName, char oper)
If needed, write a trace message Write a trace message for a scalar column.
static std::once_flag theirCallOnceFlag
Definition: TableTrace.h:178
static void traceRefTable(const String &parentName, char oper)
If needed, write a trace message for reftable open, create, or close.
static void trace(int tabid, const String &columnName, char oper, const IPosition &shape, const IPosition &blc, const IPosition &trc, const IPosition &inc)
Write a trace message for an array column slice.
static void trace(int tabid, const String &columnName, char oper, const RefRows &rownrs, const IPosition &shape, const IPosition &blc, const IPosition &trc, const IPosition &inc)
Write a trace message for ranges of array rows slice.
static void writeTraceFirst(int tabid, const String &name, char oper)
Write the first part of the trace message.
static void initColumn()
static void traceFile(int tabid, const String &oper)
If needed, trace an operation on a table.
static void trace(int tabid, const String &columnName, char oper, const RefRows &rownrs, const IPosition &shape)
Write a trace message for ranges of array rows.
static void trace(int tabid, const String &columnName, char oper, Int64 row, const IPosition &shape)
Write a trace message for an array row.
static void trace(int tabid, const String &columnName, char oper, Int64 row, const IPosition &shape, const IPosition &blc, const IPosition &trc, const IPosition &inc)
Write a trace message for an array row slice.
static int theirColType
Definition: TableTrace.h:184
static std::ofstream theirTraceFile
Definition: TableTrace.h:180
static void writeRefRows(const RefRows &rownrs)
Write the RefRows as vector of rows or slices.
static int theirDoTrace
Definition: TableTrace.h:182
static int theirOper
Definition: TableTrace.h:183
this file contains all the compiler specific defines
Definition: mainpage.dox:28
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38