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