casacore
Loading...
Searching...
No Matches
StIndArray.h
Go to the documentation of this file.
1//# StIndArray.h: Read/write indirect arrays
2//# Copyright (C) 1994,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_STINDARRAY_H
27#define TABLES_STINDARRAY_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/StArrayFile.h>
32#include <casacore/casa/Utilities/DataType.h>
33#include <casacore/casa/Arrays/ArrayFwd.h>
34#include <casacore/casa/Arrays/IPosition.h>
35#include <casacore/casa/BasicSL/Complex.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39//# Forward Declarations
40class Slicer;
41class ArrayBase;
42
43// <summary>
44// Read/write indirect arrays
45// </summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// <li> StManArrayFile
55// </prerequisite>
56
57// <etymology>
58// StIndArray stores indirect arrays on behalf of a storage manager.
59// </etymology>
60
61// <synopsis>
62// StIndArray is a helper class for accessing indirect table arrays.
63// It is the interface between a storage manager like StManAipsIO
64// (in particular its indirect array column class
65// <linkto class="StManColumnIndArrayAipsIO:description">
66// StManColumnIndArrayAipsIO</linkto>)
67// and the data storage class
68// <linkto class="StManArrayFile:description">StManArrayFile</linkto>
69// which represents the file holding the shapes and data of the arrays.
70// This file holds the data in canonical format.
71//
72// StIndArray holds information about an array in the file.
73// <ol>
74// <li> Offset of the array in the file. This points to the array shape.
75// This is stored by storage managers and serves as the mapping between
76// row number and array.
77// <li> Array data offset, i.e. the length of the shape in the file.
78// Because the data is stored in canonical format, the length of the
79// shape in the file is not directly known but has to be supplied this way.
80// <li> The actual shape of the array
81// </ol>
82// The storage manager creates an StIndArray object for each row.
83// When an array is accessed for the first time,
84// the array data offset and the shape will be filled in by StIndArray.
85// In this way it serves as a cache for the array shape.
86//
87// StIndArray implements all necessary functions to get/put an array or
88// an array slice from/into file supplied by the given StManArrayFile object.
89// The StManArrayFile object itself has to be created by the storage manager
90// and given to the StIndArray functions.
91// </synopsis>
92
93// <motivation>
94// This helper class makes it possible to share equal functionality
95// between various storage managers handling indirect arrays.
96// At the moment it is used by the StManAipsIO, IncrementalStMan, and
97// StandardStMan storage managers, but it is not limited to them. It can
98// equally well be used by any other storage manager storing (indirect) arrays
99// via an StManArrayFile object.
100// </motivation>
101
102// <example>
103// Note that the following example is not really useful.
104// StIndArray is an internal class and should not be used by a casual user.
105// The example may however give a bit of insight.
106// <srcblock>
107// Array<Float> array(...);
108// // Create an StManArrayFile object to hold the arrays.
109// StManArrayFile stmanFile ("some.name", ByteIO::New);
110// // Create a still empty StIndArray object for an array.
111// StIndArray arrayRef(0);
112// // Define the shape and allocate a Float array.
113// // Put the array data.
114// arrayRef.setShape (stmanFile, TpFloat, array.shape());
115// arrayRef.putArrayfloatV (stmanFile, &array);
116// // Get the file offset of the array (for later use).
117// Int64 offset = arrayRef.fileOffset();
118// // Create an StIndArray object to read the array back.
119// // Of course, the same object could have been used for that purpose,
120// // but this shows how to create one for an existing file.
121// StIndArray arrayRef2(offset);
122// arrayRef2.getShape (stmanFile); // read shape
123// Array<float> array2(arrayRef2.shape()); // create with correct size
124// arrayRef2.getArrayfloatV (stmanFile, &array2);
125// </srcblock>
126// </example>
127
128// <todo asof="$DATE:$">
129//# A List of bugs, limitations, extensions or planned refinements.
130// <li> Reuse file storage when an array gets reshaped.
131// This could be done if the array does not grow.
132// It also requires a change in StManArrayFile.
133// <li> Be smarter when accessing slices by not accessing a vector
134// at a time, but by determining and accessing the largest
135// possible consecutive area.
136// </todo>
137
138
140{
141public:
142 // Construct the object with the given file offset.
143 // A zero file offset means that no array has been defined yet.
144 // That may be filled in later by setShape.
146
147 // Copy constructor.
149
150 // Assignment.
152
154
155 // Get the shape.
156 const IPosition& shape() const
157 {return shape_p;}
158
159 // Get the file offset.
161 {return fileOffset_p;}
162
163 // Set the shape and allocate the array in the file.
164 // This will define the array and fill in the file offset.
165 // If the shape is already defined and does not change,
166 // nothing is done and a False value is returned.
167 // If the shape changes, the old file space is lost.
168 Bool setShape (StManArrayFile&, int dataType, const IPosition& shape);
169
170 // Read the shape if not read yet.
172
173 // Get the reference count.
175
176 // Increment the reference count.
178
179 // Decrement the reference count.
181
182 // Copy the data from another array.
183 // An exception if thrown if the shapes do not match.
184 void copyData (StManArrayFile& ios, int dataType, const StIndArray& other);
185
186 // Get an array value from the file at the offset held in this object.
187 // The buffer pointed to by dataPtr has to have the correct length
188 // (which is guaranteed by the ArrayColumn get function).
190 DataType dtype);
191
192 // Put an array value into the file at the offset held in this object.
193 // The buffer pointed to by dataPtr has to have the correct length
194 // (which is guaranteed by the ArrayColumn put function).
195 void putArrayV (StManArrayFile& ios, const ArrayBase& arr,
196 DataType dtype);
197
198 // Get a section of the array from the file at the offset held in
199 // this object.
200 // The buffer pointed to by dataPtr has to have the correct length
201 // (which is guaranteed by the ArrayColumn getSlice function).
203 ArrayBase& dataPtr, DataType dtype);
204
205 // Put a section of the array into the file at the offset held in
206 // this object.
207 // The buffer pointed to by dataPtr has to have the correct length
208 // (which is guaranteed by the ArrayColumn putSlice function).
210 const ArrayBase& dataPtr, DataType dtype);
211
212private:
213 Int64 fileOffset_p; //# offset of shape in StManArrayFile
214 uInt arrOffset_p; //# extra offset to the array
215 //# 0 = arrOffset and shape not known yet
216 IPosition shape_p; //# shape of the array
217
218 // Get sliced data, i.e. get a section of an array.
219 // This function is used by getSliceXXXV to have common functionality
220 // in one function. It calls the given getVec function for each
221 // chunk of data. In this way the bulk of type-independent code
222 // is concentrated in getSliceData resulting in small
223 // type-dependent functions.
224 void getSliceData (StManArrayFile&, const Slicer& ns, void* value,
225 const IPosition& userArrayShape,
226 void (*getVec) (StManArrayFile&,
228 void* dataPtr));
229
230 // Get a (type-dependent) vector part of a slice.
231 // This function is called for each chunk by putSliceData.
232 // <group>
234 Int64 fileOffset, uInt64 arrayStart,
235 uInt64 length, uInt64 increment,
236 uInt64 valueIndex, void* value);
238 Int64 fileOffset, uInt64 arrayStart,
239 uInt64 length, uInt64 increment,
240 uInt64 valueIndex, void* value);
242 Int64 fileOffset, uInt64 arrayStart,
243 uInt64 length, uInt64 increment,
244 uInt64 valueIndex, void* value);
246 Int64 fileOffset, uInt64 arrayStart,
247 uInt64 length, uInt64 increment,
248 uInt64 valueIndex, void* value);
250 Int64 fileOffset, uInt64 arrayStart,
251 uInt64 length, uInt64 increment,
252 uInt64 valueIndex, void* value);
254 Int64 fileOffset, uInt64 arrayStart,
255 uInt64 length, uInt64 increment,
256 uInt64 valueIndex, void* value);
258 Int64 fileOffset, uInt64 arrayStart,
259 uInt64 length, uInt64 increment,
260 uInt64 valueIndex, void* value);
262 Int64 fileOffset, uInt64 arrayStart,
263 uInt64 length, uInt64 increment,
264 uInt64 valueIndex, void* value);
266 Int64 fileOffset, uInt64 arrayStart,
267 uInt64 length, uInt64 increment,
268 uInt64 valueIndex, void* value);
270 Int64 fileOffset, uInt64 arrayStart,
271 uInt64 length, uInt64 increment,
272 uInt64 valueIndex, void* value);
274 Int64 fileOffset, uInt64 arrayStart,
275 uInt64 length, uInt64 increment,
276 uInt64 valueIndex, void* value);
278 Int64 fileOffset, uInt64 arrayStart,
279 uInt64 length, uInt64 increment,
280 uInt64 valueIndex, void* value);
281 // </group>
282
283 // Put sliced data, i.e. put a section of an array.
284 // This function is used by putSlice to have common functionality
285 // in one function. It calls the given in putVec function for
286 // chunk of data. In this way the bulk of type-independent code
287 // is concentrated in putSliceData resulting in small
288 // type-dependent functions.
289 void putSliceData (StManArrayFile&, const Slicer& ns, const void* value,
290 const IPosition& userArrayShape,
291 void (*putVec) (StManArrayFile&,
293 const void* dataPtr));
294
295 // Put a (type-dependent) vector part of a slice.
296 // This function is called for each chunk by putSliceData.
297 // <group>
299 Int64 fileOffset, uInt64 arrayStart,
300 uInt64 length, uInt64 increment,
301 uInt64 valueIndex, const void* value);
303 Int64 fileOffset, uInt64 arrayStart,
304 uInt64 length, uInt64 increment,
305 uInt64 valueIndex, const void* value);
307 Int64 fileOffset, uInt64 arrayStart,
308 uInt64 length, uInt64 increment,
309 uInt64 valueIndex, const void* value);
311 Int64 fileOffset, uInt64 arrayStart,
312 uInt64 length, uInt64 increment,
313 uInt64 valueIndex, const void* value);
315 Int64 fileOffset, uInt64 arrayStart,
316 uInt64 length, uInt64 increment,
317 uInt64 valueIndex, const void* value);
319 Int64 fileOffset, uInt64 arrayStart,
320 uInt64 length, uInt64 increment,
321 uInt64 valueIndex, const void* value);
323 Int64 fileOffset, uInt64 arrayStart,
324 uInt64 length, uInt64 increment,
325 uInt64 valueIndex, const void* value);
327 Int64 fileOffset, uInt64 arrayStart,
328 uInt64 length, uInt64 increment,
329 uInt64 valueIndex, const void* value);
331 Int64 fileOffset, uInt64 arrayStart,
332 uInt64 length, uInt64 increment,
333 uInt64 valueIndex, const void* value);
335 Int64 fileOffset, uInt64 arrayStart,
336 uInt64 length, uInt64 increment,
337 uInt64 valueIndex, const void* value);
339 Int64 fileOffset, uInt64 arrayStart,
340 uInt64 length, uInt64 increment,
341 uInt64 valueIndex, const void* value);
343 Int64 fileOffset, uInt64 arrayStart,
344 uInt64 length, uInt64 increment,
345 uInt64 valueIndex, const void* value);
346 // </group>
347
348 // Throw an exception if the shape of the given array and the table
349 // array (slice) are not equal.
350 void checkShape (const IPosition& userArrayShape,
351 const IPosition& tableArrayShape) const;
352};
353
354
355
356
357} //# NAMESPACE CASACORE - END
358
359#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
StIndArray(Int64 fileOffset)
Construct the object with the given file offset.
static void putVecuCharV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
void putSliceV(StManArrayFile &, const Slicer &, const ArrayBase &dataPtr, DataType dtype)
Put a section of the array into the file at the offset held in this object.
void getSliceV(StManArrayFile &, const Slicer &, ArrayBase &dataPtr, DataType dtype)
Get a section of the array from the file at the offset held in this object.
void checkShape(const IPosition &userArrayShape, const IPosition &tableArrayShape) const
Throw an exception if the shape of the given array and the table array (slice) are not equal.
static void getVecBoolV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Get a (type-dependent) vector part of a slice.
static void putVecIntV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
uInt refCount(StManArrayFile &ios)
Get the reference count.
static void putVecfloatV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
static void putVecInt64V(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
static void getVecComplexV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
void putArrayV(StManArrayFile &ios, const ArrayBase &arr, DataType dtype)
Put an array value into the file at the offset held in this object.
static void getVecuShortV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void getVecDComplexV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void getVecdoubleV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void putVecComplexV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
static void putVecBoolV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Put a (type-dependent) vector part of a slice.
static void putVecStringV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
StIndArray(const StIndArray &)
Copy constructor.
static void getVecStringV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void getVecInt64V(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
void getShape(StManArrayFile &ios)
Read the shape if not read yet.
void decrementRefCount(StManArrayFile &ios)
Decrement the reference count.
const IPosition & shape() const
Get the shape.
Definition StIndArray.h:156
static void getVecuIntV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
void getSliceData(StManArrayFile &, const Slicer &ns, void *value, const IPosition &userArrayShape, void(*getVec)(StManArrayFile &, Int64, uInt64, uInt64, uInt64, uInt64, void *dataPtr))
Get sliced data, i.e.
static void getVecfloatV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void putVecdoubleV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
void getArrayV(StManArrayFile &ios, ArrayBase &arr, DataType dtype)
Get an array value from the file at the offset held in this object.
static void putVecuShortV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
void putSliceData(StManArrayFile &, const Slicer &ns, const void *value, const IPosition &userArrayShape, void(*putVec)(StManArrayFile &, Int64, uInt64, uInt64, uInt64, uInt64, const void *dataPtr))
Put sliced data, i.e.
void copyData(StManArrayFile &ios, int dataType, const StIndArray &other)
Copy the data from another array.
static void getVecShortV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void getVecuCharV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
static void putVecuIntV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
void incrementRefCount(StManArrayFile &ios)
Increment the reference count.
static void putVecShortV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
StIndArray & operator=(const StIndArray &)
Assignment.
static void getVecIntV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Bool setShape(StManArrayFile &, int dataType, const IPosition &shape)
Set the shape and allocate the array in the file.
static void putVecDComplexV(StManArrayFile &, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Int64 fileOffset() const
Get the file offset.
Definition StIndArray.h:160
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned long long uInt64
Definition aipsxtype.h:37