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
139 public:
140 // Construct the object with the given file offset.
141 // A zero file offset means that no array has been defined yet.
142 // That may be filled in later by setShape.
144
145 // Copy constructor.
147
148 // Assignment.
150
152
153 // Get the shape.
154 const IPosition& shape() const { return shape_p; }
155
156 // Get the file offset.
157 Int64 fileOffset() const { return fileOffset_p; }
158
159 // Set the shape and allocate the array in the file.
160 // This will define the array and fill in the file offset.
161 // If the shape is already defined and does not change,
162 // nothing is done and a False value is returned.
163 // If the shape changes, the old file space is lost.
165
166 // Read the shape if not read yet.
168
169 // Get the reference count.
171
172 // Increment the reference count.
174
175 // Decrement the reference count.
177
178 // Copy the data from another array.
179 // An exception if thrown if the shapes do not match.
180 void copyData(StManArrayFile& ios, int dataType, const StIndArray& other);
181
182 // Get an array value from the file at the offset held in this object.
183 // The buffer pointed to by dataPtr has to have the correct length
184 // (which is guaranteed by the ArrayColumn get function).
185 void getArrayV(StManArrayFile& ios, ArrayBase& arr, DataType dtype);
186
187 // Put an array value into the file at the offset held in this object.
188 // The buffer pointed to by dataPtr has to have the correct length
189 // (which is guaranteed by the ArrayColumn put function).
190 void putArrayV(StManArrayFile& ios, const ArrayBase& arr, DataType dtype);
191
192 // Get a section of the array from the file at the offset held in
193 // this object.
194 // The buffer pointed to by dataPtr has to have the correct length
195 // (which is guaranteed by the ArrayColumn getSlice function).
196 void getSliceV(StManArrayFile&, const Slicer&, ArrayBase& dataPtr, DataType dtype);
197
198 // Put a section of the array into 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 putSlice function).
202 void putSliceV(StManArrayFile&, const Slicer&, const ArrayBase& dataPtr, DataType dtype);
203
204 private:
205 Int64 fileOffset_p; // # offset of shape in StManArrayFile
206 uInt arrOffset_p; // # extra offset to the array
207 // # 0 = arrOffset and shape not known yet
208 IPosition shape_p; // # shape of the array
209
210 // Get sliced data, i.e. get a section of an array.
211 // This function is used by getSliceXXXV to have common functionality
212 // in one function. It calls the given getVec function for each
213 // chunk of data. In this way the bulk of type-independent code
214 // is concentrated in getSliceData resulting in small
215 // type-dependent functions.
216 void getSliceData(StManArrayFile&, const Slicer& ns, void* value, const IPosition& userArrayShape,
217 void (*getVec)(StManArrayFile&, Int64, uInt64, uInt64, uInt64, uInt64,
218 void* dataPtr));
219
220 // Get a (type-dependent) vector part of a slice.
221 // This function is called for each chunk by putSliceData.
222 // <group>
224 uInt64 increment, uInt64 valueIndex, void* value) {
225 GetVectorGeneric<Bool>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
226 }
228 uInt64 increment, uInt64 valueIndex, void* value) {
229 GetVectorGeneric<uChar>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
230 }
232 uInt64 increment, uInt64 valueIndex, void* value) {
233 GetVectorGeneric<Short>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
234 }
236 uInt64 increment, uInt64 valueIndex, void* value) {
237 GetVectorGeneric<uShort>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
238 }
240 uInt64 increment, uInt64 valueIndex, void* value) {
241 GetVectorGeneric<Int>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
242 }
244 uInt64 increment, uInt64 valueIndex, void* value) {
245 GetVectorGeneric<uInt>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
246 }
248 uInt64 increment, uInt64 valueIndex, void* value) {
249 GetVectorGeneric<Int64>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
250 }
252 uInt64 increment, uInt64 valueIndex, void* value) {
253 GetVectorGeneric<Float>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
254 }
256 uInt64 increment, uInt64 valueIndex, void* value) {
257 GetVectorGeneric<Double>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
258 }
259 static void getVecComplexV(StManArrayFile& ios, Int64 fileOffset, uInt64 arrayStart,
260 uInt64 length, uInt64 increment, uInt64 valueIndex, void* value) {
261 GetVectorGeneric<Complex>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
262 }
263 static void getVecDComplexV(StManArrayFile& ios, Int64 fileOffset, uInt64 arrayStart,
264 uInt64 length, uInt64 increment, uInt64 valueIndex, void* value) {
265 GetVectorGeneric<DComplex>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
266 }
268 uInt64 increment, uInt64 valueIndex, void* value) {
269 GetVectorGeneric<String>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
270 }
271 template <typename T>
273 uInt64 inc, uInt64 valInx, void* value) {
274 T* valp = (T*)value + valInx;
275 if (inc == 1) {
276 ios.get(fileOffset, start, leng, valp);
277 } else {
278 while (leng-- > 0) {
279 ios.get(fileOffset, start, 1, valp++);
280 start += inc;
281 }
282 }
283 }
284 // </group>
285
286 // Put sliced data, i.e. put a section of an array.
287 // This function is used by putSlice to have common functionality
288 // in one function. It calls the given in putVec function for
289 // chunk of data. In this way the bulk of type-independent code
290 // is concentrated in putSliceData resulting in small
291 // type-dependent functions.
292 void putSliceData(StManArrayFile&, const Slicer& ns, const void* value,
293 const IPosition& userArrayShape,
294 void (*putVec)(StManArrayFile&, Int64, uInt64, uInt64, uInt64, uInt64,
295 const void* dataPtr));
296
297 // Put a (type-dependent) vector part of a slice.
298 // This function is called for each chunk by putSliceData.
299 // <group>
301 uInt64 increment, uInt64 valueIndex, const void* value) {
302 PutVectorGeneric<Bool>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
303 }
305 uInt64 increment, uInt64 valueIndex, const void* value) {
306 PutVectorGeneric<uChar>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
307 }
309 uInt64 increment, uInt64 valueIndex, const void* value) {
310 PutVectorGeneric<Short>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
311 }
313 uInt64 increment, uInt64 valueIndex, const void* value) {
314 PutVectorGeneric<uShort>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
315 }
317 uInt64 increment, uInt64 valueIndex, const void* value) {
318 PutVectorGeneric<Int>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
319 }
321 uInt64 increment, uInt64 valueIndex, const void* value) {
322 PutVectorGeneric<uInt>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
323 }
325 uInt64 increment, uInt64 valueIndex, const void* value) {
326 PutVectorGeneric<Int64>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
327 }
329 uInt64 increment, uInt64 valueIndex, const void* value) {
330 PutVectorGeneric<float>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
331 }
333 uInt64 increment, uInt64 valueIndex, const void* value) {
334 PutVectorGeneric<double>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
335 }
336 static void putVecComplexV(StManArrayFile& ios, Int64 fileOffset, uInt64 arrayStart,
337 uInt64 length, uInt64 increment, uInt64 valueIndex,
338 const void* value) {
339 PutVectorGeneric<Complex>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
340 }
341 static void putVecDComplexV(StManArrayFile& ios, Int64 fileOffset, uInt64 arrayStart,
342 uInt64 length, uInt64 increment, uInt64 valueIndex,
343 const void* value) {
344 PutVectorGeneric<DComplex>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
345 }
347 uInt64 increment, uInt64 valueIndex, const void* value) {
348 PutVectorGeneric<String>(ios, fileOffset, arrayStart, length, increment, valueIndex, value);
349 }
350 template <typename T>
352 uInt64 inc, uInt64 valInx, const void* value) {
353 T* valp = (T*)value + valInx;
354 if (inc == 1) {
355 ios.put(fileOffset, start, leng, valp);
356 } else {
357 while (leng-- > 0) {
358 ios.put(fileOffset, start, 1, valp++);
359 start += inc;
360 }
361 }
362 }
363
364 // </group>
365
366 // Throw an exception if the shape of the given array and the table
367 // array (slice) are not equal.
368 void checkShape(const IPosition& userArrayShape, const IPosition& tableArrayShape) const;
369};
370
371} // namespace casacore
372
373#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:69
static void getVecComplexV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:259
static void putVecComplexV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:336
StIndArray(Int64 fileOffset)
Construct the object with the given file offset.
static void getVecInt64V(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:247
static void putVecInt64V(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:324
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.
uInt refCount(StManArrayFile &ios)
Get the reference count.
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 putVecStringV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:346
StIndArray(const StIndArray &)
Copy constructor.
static void GetVectorGeneric(StManArrayFile &ios, Int64 fileOffset, uInt64 start, uInt64 leng, uInt64 inc, uInt64 valInx, void *value)
Definition StIndArray.h:272
static void getVecdoubleV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:255
static void getVecuIntV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:243
void getShape(StManArrayFile &ios)
Read the shape if not read yet.
static void getVecIntV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:239
void decrementRefCount(StManArrayFile &ios)
Decrement the reference count.
static void getVecDComplexV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:263
static void putVecBoolV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Put a (type-dependent) vector part of a slice.
Definition StIndArray.h:300
const IPosition & shape() const
Get the shape.
Definition StIndArray.h:154
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 putVecShortV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:308
static void getVecuCharV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:227
static void getVecfloatV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:251
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 &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:312
static void getVecuShortV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:235
static void getVecBoolV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Get a (type-dependent) vector part of a slice.
Definition StIndArray.h:223
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 putVecfloatV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:328
static void putVecDComplexV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:341
static void PutVectorGeneric(StManArrayFile &ios, Int64 fileOffset, uInt64 start, uInt64 leng, uInt64 inc, uInt64 valInx, const void *value)
Definition StIndArray.h:351
void incrementRefCount(StManArrayFile &ios)
Increment the reference count.
static void putVecuCharV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:304
static void getVecStringV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:267
StIndArray & operator=(const StIndArray &)
Assignment.
static void putVecIntV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:316
static void putVecuIntV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:320
Bool setShape(StManArrayFile &, int dataType, const IPosition &shape)
Set the shape and allocate the array in the file.
static void putVecdoubleV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, const void *value)
Definition StIndArray.h:332
Int64 fileOffset() const
Get the file offset.
Definition StIndArray.h:157
static void getVecShortV(StManArrayFile &ios, Int64 fileOffset, uInt64 arrayStart, uInt64 length, uInt64 increment, uInt64 valueIndex, void *value)
Definition StIndArray.h:231
void put(Int64 fileOffset, Int64 arrayOffset, uInt64 nr, const Bool *)
Put nr elements at the given file offset and array offset.
void get(Int64 fileOffset, Int64 arrayOffset, uInt64 nr, Bool *)
Get nr elements at the given file offset and array offset.
For temporary backward namespace compatibility, use casa as alias for casacore.
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
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
DataType dataType(const RecordFieldId &) const
unsigned long long uInt64
Definition aipsxtype.h:37