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// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Utilities/Regex.h>
32
33#include <fstream>
34#include <mutex>
35#include <ostream>
36#include <vector>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations.
41class ColumnDesc;
42class RefRows;
43class IPosition;
44
45// <summary>
46// Class with static functions for tracing column IO
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
52// </reviewed>
53
54// <synopsis>
55// This class contains some static functions to enable table and column tracing.
56// It maintains a map of table name to table-id.
57// <br>
58// The following aipsrc variables variables determine if tracing will be done,
59// and if so, which columns and operations will be traced.
60// <ul>
61// <li> <src>table.trace.filename</src> gives the name of the file in which
62// the trace will be written. If empty (default), no tracing will be done.
63// If 'stdout' is given, tracing is done to stdout.
64// If 'stderr' is given, tracing is done to stderr.
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 public:
90 enum ColType { SCALAR = 1, ARRAY = 2, RECORD = 4 };
91 enum Oper { READ = 1, WRITE = 2 };
92
93 // Does the given column have to be traced for read and/or write?
94 // bit 0 set means read tracing; bit 1 write tracing.
95 static int traceColumn(const ColumnDesc&);
96
97 // If needed, write a trace message for table open or create.
98 // It adds the table to the map and returns the table-id.
99 static int traceTable(const String& tableName, char oper);
100
101 // If needed, trace closing a table.
102 // It removes the table from the map.
103 static void traceClose(const String& tableName);
104
105 // If needed, trace an operation on a table.
106 static void traceFile(int tabid, const String& oper);
107
108 // If needed, write a trace message for reftable open, create, or close.
109 static void traceRefTable(const String& parentName, char oper);
110
111 // If needed, write a trace message
112 // Write a trace message for a scalar column.
113 static void trace(int tabid, const String& columnName, char oper);
114 // Write a trace message for a scalar row.
115 static void trace(int tabid, const String& columnName, char oper, Int64 row);
116 // Write a trace message for ranges of scalar rows.
117 static void trace(int tabid, const String& columnName, char oper, const RefRows& rownrs);
118 // Write a trace message for an array column.
119 static void trace(int tabid, const String& columnName, char oper, const IPosition& shape);
120 // Write a trace message for an array row.
121 static void trace(int tabid, const String& columnName, char oper, Int64 row,
122 const IPosition& shape);
123 // Write a trace message for ranges of array rows.
124 static void trace(int tabid, const String& columnName, char oper, const RefRows& rownrs,
125 const IPosition& shape);
126 // Write a trace message for an array column slice.
127 static void trace(int tabid, const String& columnName, char oper, const IPosition& shape,
128 const IPosition& blc, const IPosition& trc, const IPosition& inc);
129 // Write a trace message for an array row slice.
130 static void trace(int tabid, const String& columnName, char oper, Int64 row,
131 const IPosition& shape, const IPosition& blc, const IPosition& trc,
132 const IPosition& inc);
133 // Write a trace message for ranges of array rows slice.
134 static void trace(int tabid, const String& columnName, char oper, const RefRows& rownrs,
135 const IPosition& shape, const IPosition& blc, const IPosition& trc,
136 const IPosition& inc);
137
138 private:
139 // Initialize the tracing mechanism which should be done only once.
140 static void initTracing(); // always called using theirCallOnce
141 static void initOper();
142 static void initColumn();
143
144 // Find the table name in the vector. -1 is returned if not found.
145 static int findTable(const String& name);
146
147 // Write the first part of the trace message.
148 static void writeTraceFirst(int tabid, const String& name, char oper);
149
150 // Write the RefRows as vector of rows or slices.
151 static void writeRefRows(const RefRows& rownrs);
152
153 // Write the blc, trc, and inc of an array slice.
154 static void writeSlice(const IPosition& blc, const IPosition& trc, const IPosition& inc);
155
156 // # Data members
157 static std::once_flag theirCallOnceFlag; // # for thread-safe lazy init
158 static std::mutex theirMutex;
159 static std::ofstream theirTraceFile;
160 static std::ostream* theirStream;
161 static int theirDoTrace; // # 0=init -1=no 1=yes 2=reftable
162 static int theirOper; // # 1=rtrace 2=wtrace
163 static int theirColType; // # 1=scalar 2=array 4=record
164 static std::vector<Regex> theirColumns;
165 static std::vector<String> theirTables;
166};
167
168} // namespace casacore
169
170#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
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:165
static std::mutex theirMutex
Definition TableTrace.h:158
static std::ostream * theirStream
Definition TableTrace.h:160
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?
static int findTable(const String &name)
Find the table name in the vector.
static std::vector< Regex > theirColumns
Definition TableTrace.h:164
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:157
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:163
static std::ofstream theirTraceFile
Definition TableTrace.h:159
static void writeRefRows(const RefRows &rownrs)
Write the RefRows as vector of rows or slices.
static int theirDoTrace
Definition TableTrace.h:161
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
String name() const
Return the name of the field.