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