casacore
Loading...
Searching...
No Matches
TiledShapeStMan.h
Go to the documentation of this file.
1//# TiledShapeStMan.h: Tiled Data Storage Manager using the shape as id
2//# Copyright (C) 1998,2000,2001,2002
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_TILEDSHAPESTMAN_H
27#define TABLES_TILEDSHAPESTMAN_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/TiledStMan.h>
33#include <casacore/casa/Containers/Block.h>
34#include <casacore/casa/BasicSL/String.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39
40
41// <summary>
42// Tiled Data Storage Manager using the shape as id.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48// </reviewed>
49
50// <prerequisite>
51//# Classes you should understand before using this one.
52// <li> <linkto class=TiledStMan>TiledStMan</linkto>
53// <li> <linkto class=TSMCube>TSMCube</linkto>
54// <li> <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
55// for a discussion of the maximum cache size
56// </prerequisite>
57
58// <etymology>
59// TiledShapeStMan is the Tiled Storage Manager where the shape is used as id
60// to support variable shaped arrays.
61// </etymology>
62
63// <synopsis>
64// TiledShapeStMan is a derivation from TiledStMan, the abstract
65// tiled storage manager class. A description of the basics
66// of tiled storage managers is given in the
67// <linkto module=Tables:TiledStMan>Tables module</linkto> description.
68// <p>
69// TiledShapeStMan creates a hypercube for each different shape of
70// the data arrays. For example, if a table contains line and continuum
71// data of an observation, it results in 2 hypercubes.
72// TiledShapeStMan does it all automatically, so it is much easier to use
73// than class <linkto class=TiledDataStMan>TiledDataStMan</linkto>.
74// <br>TiledShapeStMan is meant for columns with not too many different
75// shapes, otherwise looking for a matching hypercube may take too long.
76// When many different shapes are used, class
77// <linkto class=TiledCellStMan>TiledCellStMan</linkto>
78// should be used instead.
79//
80// TiledShapeStMan has the following (extra) properties:
81// <ul>
82// <li> It can only handle columns containing arrays, thus not scalars.
83// <li> Addition of a row sets the appropriate data arrays
84// in that row temporarily to an empty hypercube.
85// However, if the data arrays have a fixed shape, the
86// shape is known and the hypercube can be generated immediately.
87// Note that for a fixed shape column, one can as well use class
88// <linkto class=TiledColumnStMan>TiledColumnStMan</linkto>.
89// <li> When the shape of the data array in a row is set for the
90// first time, it is known which hypercube should be used or
91// if a new hypercube has to be created.
92// <br>Note that is is not possible to change the shape of an array.
93// If that is needed, TiledCellStMan should be used instead.
94// <br>Note that a hypercolumn has a given dimensionality, so each
95// data cell in the hypercolumn has to match that dimensionality.
96// <li> Although there are multiple hypercubes, an id value is not needed.
97// The shape serves as the id value.
98// <li> Coordinates for the hypercubes can be defined and (of course)
99// their shapes have to match the hypercube shape.
100// Their values have to be put explicitly (so it is not possible
101// to define them via an addHypercube call like in
102// <linkto class=TiledDataStMan>TiledDataStMan</linkto>).
103// It is possible to put the coordinate values before or after
104// the shape of the data array in that row is defined.
105// <li> It is possible to define a (default) tile shape in the
106// TiledShapeStMan constructor. When setting the shape of the
107// array in a row (using <linkto class=ArrayColumn>
108// ArrayColumn::setShape</linkto>), it is possible to override
109// that default for the hypercube in this particular row.
110// However, since the tile shape is only used when creating
111// a hypercube, using an overriding tile shape makes only
112// sense when a given array shape is used for the first time.
113// Note that the dimensionality of the hypercube is one higher
114// than the dimensionality of the data arrays (since the hypercube
115// contains multiple rows). It means that the number of values in
116// tile shape can be one more than the number of axes in the data
117// array. The last tile shape value defaults to 1; the other
118// tile shape values have to be defined.
119// </ul>
120// </synopsis>
121
122// <motivation>
123// TiledDataStMan proved to be very powerful, but also a bit cumbersome
124// to use because a few special functions need to be called.
125// TiledShapeStMan alleviates that problem.
126// </motivation>
127
128// <example>
129// <srcblock>
130// // Define the table description and the columns in it.
131// TableDesc td ("", "1", TableDesc::Scratch);
132// td.addColumn (ArrayColumnDesc<float> ("RA", 1));
133// td.addColumn (ArrayColumnDesc<float> ("Dec", 1));
134// td.addColumn (ScalarColumnDesc<float> ("Velocity"));
135// td.addColumn (ArrayColumnDesc<float> ("Image", 2));
136// // Define the 3-dim hypercolumn with its data and coordinate columns.
137// // Note that its dimensionality must be one higher than the dimensionality
138// // of the data cells.
139// td.defineHypercolumn ("TSMExample",
140// 3,
141// stringToVector ("Image"),
142// stringToVector ("RA,Dec,Velocity"));
143// // Now create a new table from the description.
144// SetupNewTable newtab("tTiledShapeStMan_tmp.data", td, Table::New);
145// // Create a TiledShapeStMan storage manager for the hypercolumn
146// // and bind the columns to it.
147// // The (default) tile shape has to be specified for the storage manager.
148// TiledShapeStMan sm1 ("TSMExample", IPosition(3,16,32,32));
149// newtab.bindAll (sm1);
150// // Create the table.
151// Table table(newtab);
152// // Define the values for the coordinates of the hypercube.
153// Vector<float> raValues(512);
154// Vector<float> DecValues(512);
155// indgen (raValues);
156// indgen (decValues, float(100));
157// ArrayColumn<float> ra (table, "RA");
158// ArrayColumn<float> dec (table, "Dec");
159// ScalarColumn<float> velocity (table, "Velocity");
160// ArrayColumn<float> image (table, "Image");
161// Cube<float> imageValues(IPosition(2,512,512));
162// indgen (imageValues);
163// // Write some data into the data columns.
164// for (uInt i=0; i<64; i++) {
165// table.addRow();
166// image.put (i, imageValues);
167// ra.put (i, raValues);
168// dec.put (i, decValues);
169// velocity.put (i, float(i));
170// }
171// </srcblock>
172// Note that in this example the same shape is used for each row,
173// but it could have been different.
174// </example>
175
176//# <todo asof="$DATE:$">
177//# A List of bugs, limitations, extensions or planned refinements.
178//# </todo>
179
180
182{
183public:
184 // Create a TiledShapeStMan storage manager for the hypercolumn
185 // with the given name.
186 // The hypercolumn name is also the name of the storage manager.
187 // The given maximum cache size (default is unlimited) is persistent,
188 // thus will be reused when the table is read back. Note that the class
189 // <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
190 // allows one to overwrite the maximum cache size temporarily.
191 // <br>The constructor taking a Record expects fields in the record with
192 // the name of the arguments in uppercase. If not defined, their
193 // default value is used.
194 // <group>
195 TiledShapeStMan (const String& hypercolumnName,
198 TiledShapeStMan (const String& hypercolumnName,
199 const Record& spec);
200 // </group>
201
203
204 // Forbid copy constructor.
206
207 // Forbid assignment.
209
210 // Clone this object.
211 // It does not clone TSMColumn objects possibly used.
212 virtual DataManager* clone() const;
213
214 // Get the type name of the data manager (i.e. TiledShapeStMan).
215 virtual String dataManagerType() const;
216
217 // Return a record containing data manager specifications and info.
218 virtual Record dataManagerSpec() const;
219
220 // TiledShapeStMan can access a column if there are 2 hypercubes
221 // and the first one is empty.
222 virtual Bool canAccessColumn() const;
223
224 // Test if only one hypercube is used by this storage manager.
225 // If not, throw an exception. Otherwise return the hypercube.
227
228 // Set the shape and tile shape of the given hypercube.
229 // It is used when the first row in a new hypercube is written.
230 // If needed it adds a dimension to the shape, which reflects the
231 // row dimension. The tile shape in that dimension is by default 1.
232 virtual void setShape (rownr_t rownr, TSMCube* hypercube,
233 const IPosition& shape,
234 const IPosition& tileShape);
235
236 // Make the object from the type name string.
237 // This function gets registered in the DataManager "constructor" map.
239 const Record& spec);
240
241private:
242 // Create a TiledShapeStMan.
243 // This constructor is private, because it should only be used
244 // by makeObject.
246
247 // Get the default tile shape.
249
250 // Add rows to the storage manager.
251 void addRow64 (rownr_t nrrow);
252
253 // Find the hypercube for the given shape.
254 // It returns -1 when not found.
256
257 // Add a hypercube.
258 // The number of rows in the table must be large enough to
259 // accommodate this hypercube.
260 // The possible id values must be given in the record, while
261 // coordinate values are optional. The field names in the record
262 // should match the coordinate and id column names.
263 // The last dimension in the cube shape can be zero, indicating that
264 // the hypercube is extensible.
266 const IPosition& cubeShape,
267 const IPosition& tileShape);
268
269 // Extend the hypercube with the given number of elements in
270 // the last dimension.
271 // The record should contain the id values (to get the correct
272 // hypercube) and optionally coordinate values for the elements added.
273 void extendHypercube (rownr_t rownr, uInt cubeNr);
274
275 // Get the hypercube in which the given row is stored.
276 virtual TSMCube* getHypercube (rownr_t rownr);
277
278 // Get the hypercube in which the given row is stored.
279 // It also returns the position of the row in that hypercube.
280 virtual TSMCube* getHypercube (rownr_t rownr, IPosition& position);
281
282 // Check if the hypercolumn definition fits this storage manager.
283 virtual void setupCheck (const TableDesc& tableDesc,
284 const Vector<String>& dataNames) const;
285
286 // Flush and optionally fsync the data.
287 // It returns a True status if it had to flush (i.e. if data have changed).
288 virtual Bool flush (AipsIO&, Bool fsync);
289
290 // Let the storage manager create files as needed for a new table.
291 // This allows a column with an indirect array to create its file.
292 virtual void create64 (rownr_t nrrow);
293
294 // Read the header info.
295 virtual void readHeader (rownr_t nrrow, Bool firstTime);
296
297 // Update the map of row numbers to cube number plus offset.
298 void updateRowMap (uInt cubeNr, uInt pos, rownr_t rownr);
299
300 // Extend the map of row numbers to cube number plus offset
301 // will new empty entries.
303
304
305 //# Declare the data members.
306 // The default tile shape.
308 // The map of row number to cube and position in cube.
312 // The nr of elements used in the map blocks.
314 // The last hypercube found.
316};
317
318
319
320
321} //# NAMESPACE CASACORE - END
322
323#endif
simple 1-D array
Definition Block.h:198
Abstract base class for a data manager.
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual String dataManagerType() const
Get the type name of the data manager (i.e.
virtual Record dataManagerSpec() const
Return a record containing data manager specifications and info.
void addHypercube(rownr_t rownr, const IPosition &cubeShape, const IPosition &tileShape)
Add a hypercube.
void extendHypercube(rownr_t rownr, uInt cubeNr)
Extend the hypercube with the given number of elements in the last dimension.
TiledShapeStMan & operator=(const TiledShapeStMan &)=delete
Forbid assignment.
virtual TSMCube * getHypercube(rownr_t rownr)
Get the hypercube in which the given row is stored.
virtual DataManager * clone() const
Clone this object.
virtual void setShape(rownr_t rownr, TSMCube *hypercube, const IPosition &shape, const IPosition &tileShape)
Set the shape and tile shape of the given hypercube.
uInt nrUsedRowMap_p
The nr of elements used in the map blocks.
Int lastHC_p
The last hypercube found.
Block< uInt > rowMap_p
The map of row number to cube and position in cube.
virtual Bool canAccessColumn() const
TiledShapeStMan can access a column if there are 2 hypercubes and the first one is empty.
static DataManager * makeObject(const String &dataManagerType, const Record &spec)
Make the object from the type name string.
Int findHypercube(const IPosition &shape)
Find the hypercube for the given shape.
TiledShapeStMan(const String &hypercolumnName, const Record &spec)
virtual TSMCube * getHypercube(rownr_t rownr, IPosition &position)
Get the hypercube in which the given row is stored.
IPosition defaultTileShape_p
The default tile shape.
TiledShapeStMan(const String &hypercolumnName, const IPosition &defaultTileShape, uInt64 maximumCacheSize=0)
Create a TiledShapeStMan storage manager for the hypercolumn with the given name.
virtual void readHeader(rownr_t nrrow, Bool firstTime)
Read the header info.
void addRow64(rownr_t nrrow)
Add rows to the storage manager.
void extendRowMap(rownr_t nrow)
Extend the map of row numbers to cube number plus offset will new empty entries.
TiledShapeStMan(const TiledShapeStMan &)=delete
Forbid copy constructor.
void updateRowMap(uInt cubeNr, uInt pos, rownr_t rownr)
Update the map of row numbers to cube number plus offset.
TiledShapeStMan()
Create a TiledShapeStMan.
virtual void setupCheck(const TableDesc &tableDesc, const Vector< String > &dataNames) const
Check if the hypercolumn definition fits this storage manager.
virtual Bool flush(AipsIO &, Bool fsync)
Flush and optionally fsync the data.
virtual IPosition defaultTileShape() const
Get the default tile shape.
virtual TSMCube * singleHypercube()
Test if only one hypercube is used by this storage manager.
virtual void create64(rownr_t nrrow)
Let the storage manager create files as needed for a new table.
const IPosition & tileShape(rownr_t rownr) const
Get the tile shape of the data in the given row.
rownr_t nrow() const
Get the nr of rows in this storage manager.
Definition TiledStMan.h:535
uInt maximumCacheSize() const
Get the current maximum cache size (in MiB (MibiByte)).
Definition TiledStMan.h:529
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44
unsigned long long uInt64
Definition aipsxtype.h:37