casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
35 #include <casacore/casa/OS/Mutex.h>
36 #include <ostream>
37 #include <fstream>
38 #include <vector>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward Declarations.
43 class ColumnDesc;
44 class RefRows;
45 class IPosition;
46 
47 
48 // <summary>
49 // Class with static functions for tracing column IO
50 // </summary>
51 
52 // <use visibility=local>
53 
54 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
55 // </reviewed>
56 
57 // <synopsis>
58 // This class contains some static functions to enable table and column tracing.
59 // It maintains a map of table name to table-id.
60 // <br>
61 // The following aipsrc variables variables determine if tracing will be done,
62 // and if so, which columns and operations will be traced.
63 // <ul>
64 // <li> <src>table.trace.filename</src> gives the name of the file in which
65 // the trace will be written. If empty (default), no tracing will be done.
66 // If 'stdout' is given, tracing is done to stdout.
67 // If 'stderr' is given, tracing is done to stderr.
68 // <li> <src>table.trace.operation</src> gives the operation to trace.
69 // be traced. It can be one or more of:
70 // <br>s: creation of RefTable (selection/sort/iter)
71 // <br>r: reads
72 // <br>w: writes
73 // <br>The default is ''. Note that opening and closing a PlainTable
74 // are always traced.
75 // <li> <src>table.trace.columntype</src> gives the types of columns to trace
76 // for read and/or write.
77 // It can be one or more of:
78 // <br> s: scalar columns
79 // <br> a: array columns
80 // <br> r: record columns
81 // <br>The default is ''.
82 // <li> <src>table.trace.column</src> gives names of additional columns to
83 // trace for read and/or write.
84 // The names are separated by commas without any whitespace.
85 // Each name can be a glob-like pattern.
86 // <br>The default is ''.
87 // </ul>
88 // If both <src>table.trace.columntype</src> and <src>table.trace.column</src>
89 // have an empty value, all array columns are traced.
90 
92 {
93 public:
94  enum ColType {
95  SCALAR = 1,
96  ARRAY = 2,
97  RECORD = 4
98  };
99  enum Oper {
100  READ = 1,
101  WRITE = 2
102  };
103 
104  // Does the given column have to be traced for read and/or write?
105  // bit 0 set means read tracing; bit 1 write tracing.
106  static int traceColumn (const ColumnDesc&);
107 
108  // If needed, write a trace message for table open or create.
109  // It adds the table to the map and returns the table-id.
110  static int traceTable (const String& tableName, char oper);
111 
112  // If needed, trace closing a table.
113  // It removes the table from the map.
114  static void traceClose (const String& tableName);
115 
116  // If needed, trace an operation on a table.
117  static void traceFile (int tabid, const String& oper);
118 
119  // If needed, write a trace message for reftable open, create, or close.
120  static void traceRefTable (const String& parentName, char oper);
121 
122  // If needed, write a trace message
123  // Write a trace message for a scalar column.
124  static void trace (int tabid, const String& columnName, char oper);
125  // Write a trace message for a scalar row.
126  static void trace (int tabid, const String& columnName, char oper,
127  Int64 row);
128  // Write a trace message for ranges of scalar rows.
129  static void trace (int tabid, const String& columnName, char oper,
130  const RefRows& rownrs);
131  // Write a trace message for an array column.
132  static void trace (int tabid, const String& columnName, char oper,
133  const IPosition& shape);
134  // Write a trace message for an array row.
135  static void trace (int tabid, const String& columnName, char oper,
136  Int64 row, const IPosition& shape);
137  // Write a trace message for ranges of array rows.
138  static void trace (int tabid, const String& columnName, char oper,
139  const RefRows& rownrs, const IPosition& shape);
140  // Write a trace message for an array column slice.
141  static void trace (int tabid, const String& columnName, char oper,
142  const IPosition& shape,
143  const IPosition& blc, const IPosition& trc,
144  const IPosition& inc);
145  // Write a trace message for an array row slice.
146  static void trace (int tabid, const String& columnName, char oper,
147  Int64 row, const IPosition& shape,
148  const IPosition& blc, const IPosition& trc,
149  const IPosition& inc);
150  // Write a trace message for ranges of array rows slice.
151  static void trace (int tabid, const String& columnName, char oper,
152  const RefRows& rownrs, const IPosition& shape,
153  const IPosition& blc, const IPosition& trc,
154  const IPosition& inc);
155 
156 private:
157  // Initialize the tracing mechanism which should be done only once.
158  static void initTracing(); // always called using theirCallOnce
159  static void initOper();
160  static void initColumn();
161 
162  // Find the table name in the vector. -1 is returned if not found.
163  static int findTable (const String& name);
164 
165  // Write the first part of the trace message.
166  static void writeTraceFirst (int tabid, const String& name, char oper);
167 
168  // Write the RefRows as vector of rows or slices.
169  static void writeRefRows (const RefRows& rownrs);
170 
171  // Write the blc, trc, and inc of an array slice.
172  static void writeSlice (const IPosition& blc,
173  const IPosition& trc,
174  const IPosition& inc);
175 
176  //# Data members
177  static CallOnce0 theirCallOnce; //# for thread-safe lazy init
179  static std::ofstream theirTraceFile;
180  static std::ostream* theirStream;
181  static int theirDoTrace; //# 0=init -1=no 1=yes 2=reftable
182  static int theirOper; //# 1=rtrace 2=wtrace
183  static int theirColType; //# 1=scalar 2=array 4=record
184  static std::vector<Regex> theirColumns;
185  static std::vector<String> theirTables;
186 };
187 
188 
189 
190 
191 } //# NAMESPACE CASACORE - END
192 
193 #endif
Wrapper around std::call_once.
Definition: Mutex.h:214
static void writeRefRows(const RefRows &rownrs)
Write the RefRows as vector of rows or slices.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
static void initColumn()
static int theirDoTrace
Definition: TableTrace.h:181
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:184
static int theirColType
Definition: TableTrace.h:183
Class with static functions for tracing column IO.
Definition: TableTrace.h:91
static Mutex theirMutex
Definition: TableTrace.h:178
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:182
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
static std::ofstream theirTraceFile
Definition: TableTrace.h:179
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:1944
static std::vector< String > theirTables
Definition: TableTrace.h:185
Wrapper around a pthreads mutex.
Definition: Mutex.h:58
static void traceFile(int tabid, const String &oper)
If needed, trace an operation on a table.
static std::ostream * theirStream
Definition: TableTrace.h:180
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.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
static CallOnce0 theirCallOnce
Definition: TableTrace.h:177