casacore
Loading...
Searching...
No Matches
TiledDataStMan.h
Go to the documentation of this file.
1//# TiledDataStMan.h: Tiled Data Storage Manager
2//# Copyright (C) 1995,1996,1997,1999,2001
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_TILEDDATASTMAN_H
27#define TABLES_TILEDDATASTMAN_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#include <vector>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39
40
41// <summary>
42// Tiled Data Storage Manager.
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// <li> <linkto class=Record>Record</linkto>
57// </prerequisite>
58
59// <etymology>
60// TiledDataStMan is the Tiled Storage Manager for general
61// data arrays.
62// </etymology>
63
64// <synopsis>
65// TiledDataStMan is a derivation from TiledStMan, the abstract
66// tiled storage manager class. A description of the basics
67// of tiled storage managers is given in the
68// <linkto module=Tables:TiledStMan>Tables module</linkto> description.
69// <p>
70// TiledDataStMan allows the user explicit control over the
71// definition and extension of hypercubes by means of the accessor
72// class <linkto class=TiledDataStManAccessor>TiledDataStManAccessor</linkto>.
73// The user can determine which row should be put in which hypercube,
74// so it is possible to put row 0-9 in hypercube A, row 10-29 in B,
75// row 30-39 in A again, etc.. This makes it possible to use a tiled
76// storage manager for a data column containing data with
77// different shapes (e.g. line and continuum data). Actually,
78// this storage manager is developed for irregularly shaped
79// UV-data, but can be used for any purpose.
80// <br>
81// Each extensible hypercube uses a file of its own. This means that there
82// shouldn't be too many of them, otherwise the number of files may
83// get too high.
84// <p>
85// The TiledDataStMan has the following (extra) properties:
86// <ul>
87// <li> When multiple hypercubes are used, one or more id columns have
88// to be used to differentiate between them. The id values must
89// be defined when the hypercube gets added; they cannot be put
90// explicitly.
91// <li> A hypercube can be extensible in its last dimension by setting
92// its last dimension to zero. In that case extendHypercube can
93// be used to extend the hypercube when needed.
94// All fixed sized hypercubes are stored in one file, while there
95// is one file per extensible hypercube.
96// <li> The table must be large enough to accommodate the addition
97// or extension of a hypercube. This means that a sufficient
98// number of rows must be added to the table before a hypercube
99// can be added or extended. It is the responsibility of the user
100// to "synchronize" addition of rows and hypercubes.
101// <li> It is possible to define coordinates for the hypercube axes
102// in several ways:
103// <ul>
104// <li> Use the TiledDataStMan storage manager to hold their values
105// and define the coordinates when adding or extending the
106// hypercube. This is the preferred way.
107// <li> As above, but use explicit puts to write their values.
108// This has to be used when coordinates are defined after
109// the hypercube has been added or extended.
110// Note that several rows may share the same value, so
111// overwriting a value may affect multiple rows.
112// <li> Use another storage manager to hold their values.
113// This is useful when their values depend on other axes,
114// because that cannot be handled by TiledDataStMan.
115// </ul>
116// Note that it is possible to store one coordinate column with
117// TiledDataStMan and another with another storage manager.
118// </ul>
119// </synopsis>
120
121// <motivation>
122// This tiled storage manager allows one to create and extend hypercubes
123// as needed. One has complete control over which row is stored in which
124// hypercube.
125// </motivation>
126
127// <example>
128// The following example shows how to create a TiledDataStMan tiled
129// storage manager using the hypercolumn as defined in the table description.
130// Furthermore it shows how to use TiledDataStManAccessor
131// to add a hypercube, while defining its tile shape, coordinates,
132// and id-value.
133// The example shows that reading the data back does not require any knowledge
134// of the data manager. It's exactly the same if another data manager was used.
135// <br>
136// The table created contains the equally shaped data columns "Data" and
137// "Weight".
138// Each cell in those columns contains a 2D array with shape [12,20]. The
139// coordinates of those arrays are "Pol" and "Freq".
140// The tiled storage manager superimposes two more axes ("Baseline"and "Time")
141// on the data resulting in a 4D hypercube with shape [12,20,30,42].
142// The table contains 42*30 rows (which has to be equal to the number of
143// elements in the superimposed axes).
144// <br>
145// The tile shape of the hypercube is (arbitrarily) set to [4,5,6,7].
146// Of course, any tile shape could be chosen. This tile shape results
147// in a tile size of 6720 bytes (4*5*6*7 *(4+4) bytes), which is not
148// that large (32768 as tile size is very reasonable). The number of tiles
149// is integral in each dimension, so no space is wasted.
150// Finally it makes access along the various axes about equally efficient.
151// <br>
152// Although in this example only one hypercube is added, multiple hypercubes
153// are possible, because an id column has been defined.
154// <note role=caution>
155// The example uses the global Array function indgen to fill the data
156// and coordinate arrays with arbitrary values.
157// </note>
158// Note that the description of class
159// <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
160// contains a discussion about the effect of setting the maximum cache size.
161//
162// <srcblock>
163// // Define the table description and the columns in it.
164// TableDesc td ("", "1", TableDesc::Scratch);
165// td.addColumn (ScalarColumnDesc<float> ("Time"));
166// td.addColumn (ScalarColumnDesc<float> ("Baseline"));
167// td.addColumn (ArrayColumnDesc<float> ("Pol", 1));
168// td.addColumn (ArrayColumnDesc<float> ("Freq", 1));
169// td.addColumn (ScalarColumnDesc<String> ("Id"));
170// td.addColumn (ArrayColumnDesc<float> ("Data", 2));
171// td.addColumn (ArrayColumnDesc<float> ("Weight", 2));
172// // Define the 4-dim hypercolumn with its data, coordinate and id columns.
173// td.defineHypercolumn ("TSMExample",
174// 4,
175// stringToVector ("Data,Weight"),
176// stringToVector ("Pol,Freq,Baseline,Time"),
177// stringToVector ("Id"));
178//
179// // Now create a new table from the description.
180// SetupNewTable newtab("tTiledDataStMan_tmp.data", td, Table::New);
181// // Create a TiledDataStMan storage manager for the hypercolumn
182// // and bind the columns to it.
183// TiledDataStMan sm1 ("TSMExample");
184// newtab.bindAll (sm1);
185// // Create the table with 42*30 rows.
186// Table table(newtab, 42*30);
187// // Create the accessor to be able to add a hypercube to this
188// // storage manager.
189// TiledDataStManAccessor accessor(table, "TSMExample");
190// // Define the values for the coordinates of the hypercube
191// // and put them into the record.
192// Vector<float> timeValues(42);
193// Vector<float> baselineValues(30);
194// Vector<float> freqValues(20);
195// Vector<float> polValues(12);
196// indgen (timeValues);
197// indgen (baselineValues, float(100));
198// indgen (freqValues, float(200));
199// indgen (polValues, float(300));
200// Record hyperDef;
201// hyperDef.define ("Time", timeValues);
202// hyperDef.define ("Baseline", baselineValues);
203// hyperDef.define ("Freq", freqValues);
204// hyperDef.define ("Pol", polValues);
205// // Define the id value as well.
206// hyperDef.define ("Id", "");
207// // Now add the hypercube with the given shape, tile shape,
208// // and coordinate and id values.
209// accessor.addHypercube (IPosition(4,12,20,30,42),
210// IPosition(4,4,5,6,7), hyperDef);
211// ArrayColumn<float> data (table, "Data");
212// ArrayColumn<float> weight (table, "Weight");
213// Matrix<float> array(IPosition(2,12,20));
214// indgen (array);
215// // Write some data into the data columns.
216// for (uInt i=0; i<30*42; i++) {
217// data.put (i, array);
218// weight.put (i, array+float(100));
219// array += float(200);
220// }
221// // Prepare for reading the data back.
222// // Note that time and baseline are in fact scalar columns. They are
223// // superimposed dimensions on the hypercube.
224// ScalarColumn<float> time (table, "Time");
225// ScalarColumn<float> baseline (table, "Baseline");
226// ArrayColumn<float> freq (table, "Freq");
227// ArrayColumn<float> pol (table, "Pol");
228// ScalarColumn<String> id (table, "Id");
229// float fValue;
230// String sValue;
231// for (rownr_t i=0; i<table.nrow(); i++) {
232// data.get (i, array);
233// weight.get (i, array);
234// pol.get (i, polValues);
235// freq.get (i, freqValues);
236// baseline.get (i, fValue);
237// time.get (i, fValue);
238// id.get (i, sValue);
239// }
240// </srcblock>
241// Note that in this example an id column was not necessary, because
242// there is only one hypercube.
243// <p>
244// The following example is more advanced. Two (extensible) hypercubes
245// are used for line and continuum data. Writing such a data set
246// could be done as shown. Reading it back is the same as above.
247// <br>
248// In this example the data columns contain line and continuum data.
249// So there are two types of data, each with their own shape and
250// stored in their own (extensible) hypercube. Note that the last
251// dimension of the hypercube shape is set to zero (to make extensible),
252// but the last tile shape dimension has been filled in,
253// because the exact tile shape must be known.
254// <br>
255// Before each put of the data the appropriate hypercube is extended.
256// Also the time has to be put, which is done (as an example) in
257// two different ways (using an explicit put and using the extendHypercube).
258//
259// <srcblock>
260// // Defining TableDesc and storage manager is same as in first example.
261// // Create the table.
262// Table table(newtab);
263// // Create the accessor to be able to add the hypercubes to this
264// // storage manager.
265// TiledDataStManAccessor accessor(table, "TSMExample");
266// // Fill the coordinate values.
267// // Note that the time axis of the hypercube will have length 0 to
268// // make it extensible. Therefore the time coordinate can only be
269// // filled in when the hypercube is extended.
270// Vector<float> baselineValues(30);
271// Vector<float> freqValuesCont(1);
272// Vector<float> freqValuesLine(20);
273// Vector<float> polValues(4);
274// indgen (baselineValues, float(100));
275// indgen (freqValuesLine, float(200));
276// indgen (freqValuesCont, float(200));
277// indgen (polValues, float(300));
278// Record hyperDefLine;
279// hyperDefLine.define ("Baseline", baselineValues);
280// hyperDefLine.define ("Pol", polValues);
281// // Make similar record for line data.
282// // Fill the correct id and frequency values for each type.
283// // Add the 2 hypercubes.
284// Record hyperDefCont (hyperDefLine);
285// hyperDefLine.define ("Id", "L");
286// hyperDefLine.define ("Freq", freqValuesLine);
287// hyperDefCont.define ("Id", "C");
288// hyperDefCont.define ("Freq", freqValuesCont);
289// // Add the hypercubes.
290// // Define their last dimension as zero to make them extensible.
291// accessor.addHypercube (IPosition(4,4,20,30,0),
292// IPosition(4,4,5,6,7), hyperDefLine);
293// accessor.addHypercube (IPosition(4,4,1,30,0),
294// IPosition(4,4,1,6,7), hyperDefCont);
295// ScalarColumn<float> time (table, "Time");
296// ScalarColumn<float> baseline (table, "Baseline");
297// ArrayColumn<float> freq (table, "Freq");
298// ArrayColumn<float> pol (table, "Pol");
299// ArrayColumn<float> data (table, "Data");
300// ArrayColumn<float> weight (table, "Weight");
301// Matrix<float> arrayLine(IPosition(2,4,20));
302// Matrix<float> arrayCont(IPosition(2,4,1));
303// indgen (arrayLine);
304// indgen (arrayCont);
305// // Write some data into the data columns.
306// // Alternately line and continuum is written.
307// // Each hypercube requires 30 rows to be added (i.e. nr of baselines).
308// // The last dimension of each hypercube is extended with 1.
309// rownr_t rownr = 0;
310// for (uInt i=0; i<42; i++) {
311// if (i%2 == 0) {
312// table.addRow (30);
313// accessor.extendHypercube (1, hyperDefLine);
314// time.put (rownr, float(i));
315// for (uInt j=0; j<30; j++) {
316// data.put (rownr, arrayLine);
317// weight.put (rownr, arrayLine);
318// rownr++;
319// }
320// }else{
321// table.addRow (30);
322// Vector<float> timeValue(1);
323// timeValue(0) = float(i);
324// hyperDefCont.define ("Time", timeValue);
325// accessor.extendHypercube (1, hyperDefCont);
326// time.put (rownr, float(i));
327// for (uInt j=0; j<30; j++) {
328// data.put (rownr, arrayCont);
329// weight.put (rownr, arrayCont);
330// rownr++;
331// }
332// }
333// }
334// </srcblock>
335// Note that in this example the time is defined in 2 different ways.
336// The first one by an explicit put, the second one as a record in
337// the extendHypercube call. The second way if the preferred one,
338// although it requires a bit more coding.
339// </example>
340
341//# <todo asof="$DATE:$">
342//# A List of bugs, limitations, extensions or planned refinements.
343//# </todo>
344
345
347{
349
350public:
351 // Create a TiledDataStMan storage manager for the hypercolumn
352 // with the given name.
353 // The hypercolumn name is also the name of the storage manager.
354 // The given maximum cache size (default is unlimited) is persistent,
355 // thus will be reused when the table is read back. Note that the class
356 // <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
357 // allows one to overwrite the maximum cache size temporarily.
358 // <br>The constructor taking a Record expects fields in the record with
359 // the name of the arguments in uppercase. If not defined, their
360 // default value is used.
361 // <group>
362 TiledDataStMan (const String& hypercolumnName,
364 TiledDataStMan (const String& hypercolumnName,
365 const Record& spec);
366 // </group>
367
369
370 // Forbid copy constructor.
372
373 // Forbid assignment.
375
376 // Clone this object.
377 // It does not clone TSMColumn objects possibly used.
379
380 // Get the type name of the data manager (i.e. TiledDataStMan).
382
383 // Make the object from the type name string.
384 // This function gets registered in the DataManager "constructor" map.
386 const Record& spec);
387
388private:
389 // Create a TiledDataStMan.
390 // This constructor is private, because it should only be used
391 // by makeObject.
393
394 // Add rows to the storage manager.
395 // This will only increase the number of rows. When a hypercube is
396 // added or extended, it will be checked whether the number of rows
397 // is sufficient.
398 void addRow64 (rownr_t nrrow);
399
400 // Add a hypercube.
401 // The number of rows in the table must be large enough to
402 // accommodate this hypercube.
403 // The possible id values must be given in the record, while
404 // coordinate values are optional. The field names in the record
405 // should match the coordinate and id column names.
406 // The last dimension in the cube shape can be zero, indicating that
407 // the hypercube is extensible.
408 void addHypercube (const IPosition& cubeShape,
409 const IPosition& tileShape,
410 const Record& values);
411
412 // Extend the hypercube with the given number of elements in
413 // the last dimension.
414 // The record should contain the id values (to get the correct
415 // hypercube) and optionally coordinate values for the elements added.
416 void extendHypercube (uInt64 incrInLastDim, const Record& values);
417
418 // Get the hypercube in which the given row is stored.
419 virtual TSMCube* getHypercube (rownr_t rownr);
420
421 // Get the hypercube in which the given row is stored.
422 // It also returns the position of the row in that hypercube.
423 virtual TSMCube* getHypercube (rownr_t rownr, IPosition& position);
424
425 // Flush and optionally fsync the data.
426 // It returns a True status if it had to flush (i.e. if data have changed).
427 virtual Bool flush (AipsIO&, Bool fsync);
428
429 // Let the storage manager create files as needed for a new table.
430 // This allows a column with an indirect array to create its file.
431 virtual void create64 (rownr_t nrrow);
432
433 // Read the header info.
434 virtual void readHeader (rownr_t nrrow, Bool firstTime);
435
436 // Update the map of row numbers to cube number plus offset.
437 void updateRowMap (uInt cubeNr, uInt64 incrInLastDim);
438
439 // Check if the table is large enough to hold this
440 // hypercube extension.
441 void checkNrrow (const IPosition& cubeShape,
442 uInt64 incrInLastDim) const;
443
444
445 //# Declare the data members.
446 // The map of row number to cube and position in cube.
447 std::vector<rownr_t> rowMap_p;
448 std::vector<uInt> cubeMap_p;
449 std::vector<uInt> posMap_p;
450 // The row number since the last hypercube extension.
452};
453
454
455
456
457} //# NAMESPACE CASACORE - END
458
459#endif
Abstract base class for a data manager.
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual TSMCube * getHypercube(rownr_t rownr, IPosition &position)
Get the hypercube in which the given row is stored.
std::vector< uInt > cubeMap_p
TiledDataStMan(const String &hypercolumnName, uInt64 maximumCacheSize=0)
Create a TiledDataStMan storage manager for the hypercolumn with the given name.
TiledDataStMan()
Create a TiledDataStMan.
void checkNrrow(const IPosition &cubeShape, uInt64 incrInLastDim) const
Check if the table is large enough to hold this hypercube extension.
DataManager * clone() const
Clone this object.
virtual void readHeader(rownr_t nrrow, Bool firstTime)
Read the header info.
static DataManager * makeObject(const String &dataManagerType, const Record &spec)
Make the object from the type name string.
std::vector< rownr_t > rowMap_p
The map of row number to cube and position in cube.
std::vector< uInt > posMap_p
virtual TSMCube * getHypercube(rownr_t rownr)
Get the hypercube in which the given row is stored.
virtual Bool flush(AipsIO &, Bool fsync)
Flush and optionally fsync the data.
void addHypercube(const IPosition &cubeShape, const IPosition &tileShape, const Record &values)
Add a hypercube.
String dataManagerType() const
Get the type name of the data manager (i.e.
void updateRowMap(uInt cubeNr, uInt64 incrInLastDim)
Update the map of row numbers to cube number plus offset.
TiledDataStMan(const TiledDataStMan &)=delete
Forbid copy constructor.
TiledDataStMan & operator=(const TiledDataStMan &)=delete
Forbid assignment.
TiledDataStMan(const String &hypercolumnName, const Record &spec)
void addRow64(rownr_t nrrow)
Add rows to the storage manager.
void extendHypercube(uInt64 incrInLastDim, const Record &values)
Extend the hypercube with the given number of elements in the last dimension.
virtual void create64(rownr_t nrrow)
Let the storage manager create files as needed for a new table.
rownr_t nrrowLast_p
The row number since the last hypercube extension.
const IPosition & tileShape(rownr_t rownr) const
Get the tile shape of the data in the given row.
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
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