casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Adios2StManColumn.h
Go to the documentation of this file.
1 //# Adios2StManColumn.h: A Column in the ADIOS2 Storage Manager
2 //# Copyright (C) 2018
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: aips2-request@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 //# $Id$
27 
28 #ifndef ADIOS2STMANCOLUMN_H
29 #define ADIOS2STMANCOLUMN_H
30 
31 #include <unordered_map>
32 #include <numeric>
36 
37 #include "Adios2StManImpl.h"
38 
39 
40 namespace casacore
41 {
42 
44 {
45 public:
46  Adios2StManColumn(Adios2StMan::impl *aParent, int aDataType, String aColName, std::shared_ptr<adios2::IO> aAdiosIO);
47 
48  virtual Bool canAccessSlice (Bool& reask) const { reask = false; return true; };
49 
50  virtual void create(std::shared_ptr<adios2::Engine> aAdiosEngine,
51  char aOpenMode) = 0;
52  virtual void setShapeColumn(const IPosition &aShape);
53  virtual IPosition shape(uInt aRowNr);
54  Bool canChangeShape() const;
55  void setShape (uInt aRowNr, const IPosition& aShape);
56 
57  int getDataTypeSize();
58  int getDataType();
60 
61  virtual void putScalarV(uInt aRowNr, const void *aDataPtr) = 0;
62  virtual void getScalarV(uInt aRowNr, void *aDataPtr) = 0;
63 
64  virtual void putBoolV(uInt aRowNr, const Bool *aDataPtr);
65  virtual void putuCharV(uInt aRowNr, const uChar *aDataPtr);
66  virtual void putShortV(uInt aRowNr, const Short *aDataPtr);
67  virtual void putuShortV(uInt aRowNr, const uShort *aDataPtr);
68  virtual void putIntV(uInt aRowNr, const Int *aDataPtr);
69  virtual void putuIntV(uInt aRowNr, const uInt *aDataPtr);
70  virtual void putInt64V(uInt aRowNr, const Int64 *aDataPtr);
71  virtual void putfloatV(uInt aRowNr, const Float *aDataPtr);
72  virtual void putdoubleV(uInt aRowNr, const Double *aDataPtr);
73  virtual void putComplexV(uInt aRowNr, const Complex *aDataPtr);
74  virtual void putDComplexV(uInt aRowNr, const DComplex *aDataPtr);
75  virtual void putStringV(uInt aRowNr, const String *aDataPtr);
76 
77  virtual void getBoolV(uInt aRowNr, Bool *aDataPtr);
78  virtual void getuCharV(uInt aRowNr, uChar *aDataPtr);
79  virtual void getShortV(uInt aRowNr, Short *aDataPtr);
80  virtual void getuShortV(uInt aRowNr, uShort *aDataPtr);
81  virtual void getIntV(uInt aRowNr, Int *aDataPtr);
82  virtual void getuIntV(uInt aRowNr, uInt *aDataPtr);
83  virtual void getInt64V(uInt aRowNr, Int64 *aDataPtr);
84  virtual void getfloatV(uInt aRowNr, Float *aDataPtr);
85  virtual void getdoubleV(uInt aRowNr, Double *aDataPtr);
86  virtual void getComplexV(uInt aRowNr, Complex *aDataPtr);
87  virtual void getDComplexV(uInt aRowNr, DComplex *aDataPtr);
88  virtual void getStringV(uInt aRowNr, String *aDataPtr);
89 
90  virtual void putSliceBoolV(uInt rownr, const Slicer& ns, const Array<Bool>* dataPtr);
91  virtual void putSliceuCharV(uInt rownr, const Slicer& ns, const Array<uChar>* dataPtr);
92  virtual void putSliceShortV(uInt rownr, const Slicer& ns, const Array<Short>* dataPtr);
93  virtual void putSliceuShortV(uInt rownr, const Slicer& ns, const Array<uShort>* dataPtr);
94  virtual void putSliceIntV(uInt rownr, const Slicer& ns, const Array<Int>* dataPtr);
95  virtual void putSliceuIntV(uInt rownr, const Slicer& ns, const Array<uInt>* dataPtr);
96  virtual void putSlicefloatV(uInt rownr, const Slicer& ns, const Array<float>* dataPtr);
97  virtual void putSlicedoubleV(uInt rownr, const Slicer& ns, const Array<double>* dataPtr);
98  virtual void putSliceComplexV(uInt rownr, const Slicer& ns, const Array<Complex>* dataPtr);
99  virtual void putSliceDComplexV(uInt rownr, const Slicer& ns, const Array<DComplex>* dataPtr);
100  virtual void putSliceStringV(uInt rownr, const Slicer& ns, const Array<String>* dataPtr);
101 
102  virtual void getSliceBoolV(uInt rownr, const Slicer& ns, Array<Bool>* dataPtr);
103  virtual void getSliceuCharV(uInt rownr, const Slicer& ns, Array<uChar>* dataPtr);
104  virtual void getSliceShortV(uInt rownr, const Slicer& ns, Array<Short>* dataPtr);
105  virtual void getSliceuShortV(uInt rownr, const Slicer& ns, Array<uShort>* dataPtr);
106  virtual void getSliceIntV(uInt rownr, const Slicer& ns, Array<Int>* dataPtr);
107  virtual void getSliceuIntV(uInt rownr, const Slicer& ns, Array<uInt>* dataPtr);
108  virtual void getSlicefloatV(uInt rownr, const Slicer& ns, Array<float>* dataPtr);
109  virtual void getSlicedoubleV(uInt rownr, const Slicer& ns, Array<double>* dataPtr);
110  virtual void getSliceComplexV(uInt rownr, const Slicer& ns, Array<Complex>* dataPtr);
111  virtual void getSliceDComplexV(uInt rownr, const Slicer& ns, Array<DComplex>* dataPtr);
112  virtual void getSliceStringV(uInt rownr, const Slicer& ns, Array<String>* dataPtr);
113 
114 
115 protected:
116  void scalarVToSelection(uInt rownr);
117  void arrayVToSelection(uInt rownr);
118  void sliceVToSelection(uInt rownr, const Slicer &ns);
119 
121 
124  std::unordered_map<uInt, IPosition> itsCasaShapes;
126 
127  std::shared_ptr<adios2::IO> itsAdiosIO;
128  std::shared_ptr<adios2::Engine> itsAdiosEngine;
130  std::string itsAdiosDataType;
132  adios2::Dims itsAdiosStart = {0};
133  adios2::Dims itsAdiosCount = {1};
134 }; // class Adios2StManColumn
135 
136 
137 template <class T>
139 {
140 public:
141 
143  Adios2StMan::impl *aParent,
144  int aDataType,
145  String aColName,
146  std::shared_ptr<adios2::IO> aAdiosIO)
147  : Adios2StManColumn(aParent, aDataType, aColName, aAdiosIO)
148  {
149  }
150 
151  void create(std::shared_ptr<adios2::Engine> aAdiosEngine, char aOpenMode)
152  {
153  itsAdiosEngine = aAdiosEngine;
154  itsAdiosOpenMode = aOpenMode;
155  itsAdiosVariable = itsAdiosIO->InquireVariable<T>(itsColumnName);
156  if(aOpenMode == 'w')
157  {
158  if (!itsAdiosVariable)
159  {
160  itsAdiosVariable = itsAdiosIO->DefineVariable<T>(
164  itsAdiosCount);
165  }
166  }
167  else if(aOpenMode == 'r')
168  {
169  size_t cacheSize = std::accumulate(
170  itsAdiosShape.begin() + 1,
171  itsAdiosShape.end(),
173  std::multiplies<size_t>());
174  itsReadCache.resize(cacheSize);
175  }
176  itsArraySize = std::accumulate(
177  itsAdiosShape.begin() + 1,
178  itsAdiosShape.end(),
179  1,
180  std::multiplies<size_t>());
181  }
182 
183  virtual void putArrayV(uInt rownr, const void *dataPtr)
184  {
185  arrayVToSelection(rownr);
186  toAdios(dataPtr);
187  }
188 
189  virtual void getArrayV(uInt rownr, void *dataPtr)
190  {
191  arrayVToSelection(rownr);
192  if(itsReadCacheMaxRows > 0)
193  {
195  {
198  fromAdios(itsReadCache.data());
199  }
200  Bool deleteIt;
201  auto *arrayPtr = asArrayPtr(dataPtr);
202  T *data = arrayPtr->getStorage(deleteIt);
203  size_t index = itsArraySize * (itsAdiosStart[0] - itsReadCacheStartRow);
204  size_t length = sizeof(T) * itsArraySize;
205  std::memcpy(data, itsReadCache.data() + index, length);
206  arrayPtr->putStorage(data, deleteIt);
207  }
208  else
209  {
210  fromAdios(dataPtr);
211  }
212  }
213 
214  virtual void putScalarV(uInt rownr, const void *dataPtr)
215  {
216  scalarVToSelection(rownr);
217  toAdios(reinterpret_cast<const T *>(dataPtr));
218  }
219 
220  virtual void getScalarV(uInt aRowNr, void *data)
221  {
222  scalarVToSelection(aRowNr);
223  fromAdios(reinterpret_cast<T *>(data));
224  }
225 
226  virtual void putArrayColumnCellsV (const RefRows& rownrs, const void* dataPtr)
227  {
228  if(rownrs.isSliced())
229  {
230  rownrs.convert();
231  }
232  Bool deleteIt;
233  auto *arrayPtr = asArrayPtr(dataPtr);
234  const T *data = arrayPtr->getStorage(deleteIt);
235  itsAdiosCount[0] = 1;
236  for (size_t i = 1; i < itsAdiosShape.size(); ++i)
237  {
238  itsAdiosStart[i] = 0;
240  }
241  for(uInt i = 0; i < rownrs.rowVector().size(); ++i)
242  {
243  itsAdiosStart[0] = rownrs.rowVector()[i];
244  toAdios(data + i * itsCasaShape.nelements());
245  }
246  arrayPtr->freeStorage(data, deleteIt);
247  }
248 
249  virtual void getArrayColumnCellsV (const RefRows& rownrs, void* dataPtr)
250  {
251  if(rownrs.isSliced())
252  {
253  rownrs.convert();
254  }
255  Bool deleteIt;
256  auto *arrayPtr = asArrayPtr(dataPtr);
257  T *data = arrayPtr->getStorage(deleteIt);
258  itsAdiosCount[0] = 1;
259  for (size_t i = 1; i < itsAdiosShape.size(); ++i)
260  {
261  itsAdiosStart[i] = 0;
263  }
264  for(uInt i = 0; i < rownrs.rowVector().size(); ++i)
265  {
266  itsAdiosStart[0] = rownrs.rowVector()[i];
267  fromAdios(data + i * itsCasaShape.nelements());
268  }
269  arrayPtr->putStorage(data, deleteIt);
270  }
271 
272  virtual void getSliceV(uInt aRowNr, const Slicer &ns, void *dataPtr)
273  {
274  sliceVToSelection(aRowNr, ns);
275  fromAdios(dataPtr);
276  }
277 
278  virtual void putSliceV(uInt aRowNr, const Slicer &ns, const void *dataPtr)
279  {
280  sliceVToSelection(aRowNr, ns);
281  toAdios(dataPtr);
282  }
283 
284  virtual void getArrayColumnV(void *dataPtr)
285  {
286  for(auto &i:itsAdiosStart){
287  i=0;
288  }
289  fromAdios(dataPtr);
290  }
291 
292  virtual void getColumnSliceV(const Slicer &ns, void *dataPtr)
293  {
294  itsAdiosStart[0] = 0;
296  for (size_t i = 1; i < itsAdiosShape.size(); ++i)
297  {
298  itsAdiosStart[i] = ns.start()(i - 1);
299  itsAdiosCount[i] = ns.length()(i - 1);
300  }
301  fromAdios(dataPtr);
302  }
303 
304 private:
305  const String itsStringArrayBarrier = "ADIOS2BARRIER";
306  adios2::Variable<T> itsAdiosVariable;
308  size_t itsReadCacheRows = 0;
309  size_t itsReadCacheMaxRows = 1000;
310  size_t itsArraySize;
311  std::vector<T> itsReadCache;
312 
313  Array<T> *asArrayPtr(void *dataPtr) const
314  {
315  return reinterpret_cast<Array<T>*>(dataPtr);
316  }
317 
318  const Array<T> *asArrayPtr(const void *dataPtr) const
319  {
320  return reinterpret_cast<const Array<T>*>(dataPtr);
321  }
322 
323  void toAdios(const T *data)
324  {
326  itsAdiosEngine->Put<T>(itsAdiosVariable, data, adios2::Mode::Sync);
327  }
328 
329  void fromAdios(T *data)
330  {
332  itsAdiosEngine->Get<T>(itsAdiosVariable, data, adios2::Mode::Sync);
333  }
334 
335  void toAdios(const void *dataPtr)
336  {
337  Bool deleteIt;
338  auto *arrayPtr = asArrayPtr(dataPtr);
339  const T *data = arrayPtr->getStorage(deleteIt);
340  toAdios(data);
341  arrayPtr->freeStorage (data, deleteIt);
342  }
343 
344  void fromAdios(void *dataPtr)
345  {
346  Bool deleteIt;
347  auto *arrayPtr = asArrayPtr(dataPtr);
348  T *data = arrayPtr->getStorage(deleteIt);
349  fromAdios(data);
350  arrayPtr->putStorage(data, deleteIt);
351  }
352 
353 }; // class Adios2StManColumnT
354 
355 } // namespace casacore
356 
357 #endif // ADIOS2STMANCOLUMN_H
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
virtual void putSlicedoubleV(uInt rownr, const Slicer &ns, const Array< double > *dataPtr)
virtual void putBoolV(uInt aRowNr, const Bool *aDataPtr)
Put the scalar value into the given row.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
int Int
Definition: aipstype.h:50
void setShape(uInt aRowNr, const IPosition &aShape)
Set the shape of an (variable-shaped) array in the given row.
virtual void getSliceShortV(uInt rownr, const Slicer &ns, Array< Short > *dataPtr)
virtual void getSliceDComplexV(uInt rownr, const Slicer &ns, Array< DComplex > *dataPtr)
virtual void getSlicefloatV(uInt rownr, const Slicer &ns, Array< float > *dataPtr)
#define max(a, b)
Definition: hio.h:44
virtual void putScalarV(uInt rownr, const void *dataPtr)
virtual void putSliceuIntV(uInt rownr, const Slicer &ns, const Array< uInt > *dataPtr)
Array< T > * asArrayPtr(void *dataPtr) const
Adios2StManColumn(Adios2StMan::impl *aParent, int aDataType, String aColName, std::shared_ptr< adios2::IO > aAdiosIO)
virtual void getSliceuShortV(uInt rownr, const Slicer &ns, Array< uShort > *dataPtr)
virtual void getArrayV(uInt rownr, void *dataPtr)
Get the array value in the given row.
virtual void getSliceV(uInt aRowNr, const Slicer &ns, void *dataPtr)
Get a section of the array in the given row.
virtual void getArrayColumnCellsV(const RefRows &rownrs, void *dataPtr)
Get some array values in the column.
virtual void putStringV(uInt aRowNr, const String *aDataPtr)
unsigned char uChar
Definition: aipstype.h:47
virtual void putSliceShortV(uInt rownr, const Slicer &ns, const Array< Short > *dataPtr)
Bool canChangeShape() const
Can the data manager handle chaging the shape of an existing array? Default is no.
virtual void create(std::shared_ptr< adios2::Engine > aAdiosEngine, char aOpenMode)=0
virtual void putfloatV(uInt aRowNr, const Float *aDataPtr)
virtual void getSliceComplexV(uInt rownr, const Slicer &ns, Array< Complex > *dataPtr)
virtual void putScalarV(uInt aRowNr, const void *aDataPtr)=0
virtual void putInt64V(uInt aRowNr, const Int64 *aDataPtr)
virtual void getColumnSliceV(const Slicer &ns, void *dataPtr)
Get a section of all arrays in the column.
void sliceVToSelection(uInt rownr, const Slicer &ns)
virtual void getScalarV(uInt aRowNr, void *data)
virtual void getIntV(uInt aRowNr, Int *aDataPtr)
Adios2StManColumnT(Adios2StMan::impl *aParent, int aDataType, String aColName, std::shared_ptr< adios2::IO > aAdiosIO)
virtual void setShapeColumn(const IPosition &aShape)
Set the shape of all (fixed-shaped) arrays in the column.
virtual void putArrayV(uInt rownr, const void *dataPtr)
Put the array value into the given row.
adios2::Variable< T > itsAdiosVariable
short Short
Definition: aipstype.h:48
virtual void getInt64V(uInt aRowNr, Int64 *aDataPtr)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
virtual void putSliceIntV(uInt rownr, const Slicer &ns, const Array< Int > *dataPtr)
virtual void putSliceuShortV(uInt rownr, const Slicer &ns, const Array< uShort > *dataPtr)
virtual void getuIntV(uInt aRowNr, uInt *aDataPtr)
virtual void putSliceDComplexV(uInt rownr, const Slicer &ns, const Array< DComplex > *dataPtr)
virtual void getdoubleV(uInt aRowNr, Double *aDataPtr)
virtual void getDComplexV(uInt aRowNr, DComplex *aDataPtr)
std::unordered_map< uInt, IPosition > itsCasaShapes
std::shared_ptr< adios2::IO > itsAdiosIO
void arrayVToSelection(uInt rownr)
const Vector< uInt > & rowVector() const
Get the row vector as is (thus sliced if the object contains slices).
Definition: RefRows.h:142
double Double
Definition: aipstype.h:55
virtual void putSliceV(uInt aRowNr, const Slicer &ns, const void *dataPtr)
Put into a section of the array in the given row.
virtual IPosition shape(uInt aRowNr)
Get the shape of the item in the given row.
virtual void getShortV(uInt aRowNr, Short *aDataPtr)
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
const Array< T > * asArrayPtr(const void *dataPtr) const
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
virtual void putArrayColumnCellsV(const RefRows &rownrs, const void *dataPtr)
Put some array values in the column.
void create(std::shared_ptr< adios2::Engine > aAdiosEngine, char aOpenMode)
virtual void getSliceuCharV(uInt rownr, const Slicer &ns, Array< uChar > *dataPtr)
virtual void getComplexV(uInt aRowNr, Complex *aDataPtr)
virtual void getScalarV(uInt aRowNr, void *aDataPtr)=0
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const IPosition & length() const
Report the length of the resulting axes.
Definition: Slicer.h:468
virtual void getfloatV(uInt aRowNr, Float *aDataPtr)
float Float
Definition: aipstype.h:54
const IPosition & start() const
Report the defined starting position.
Definition: Slicer.h:459
virtual void getSlicedoubleV(uInt rownr, const Slicer &ns, Array< double > *dataPtr)
virtual void getArrayColumnV(void *dataPtr)
Get all array values in the column.
virtual void putIntV(uInt aRowNr, const Int *aDataPtr)
virtual void putDComplexV(uInt aRowNr, const DComplex *aDataPtr)
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
virtual void getSliceIntV(uInt rownr, const Slicer &ns, Array< Int > *dataPtr)
virtual void putuIntV(uInt aRowNr, const uInt *aDataPtr)
virtual void getSliceuIntV(uInt rownr, const Slicer &ns, Array< uInt > *dataPtr)
virtual void putShortV(uInt aRowNr, const Short *aDataPtr)
virtual void getSliceStringV(uInt rownr, const Slicer &ns, Array< String > *dataPtr)
virtual void getuCharV(uInt aRowNr, uChar *aDataPtr)
virtual void putSliceStringV(uInt rownr, const Slicer &ns, const Array< String > *dataPtr)
virtual void putSliceuCharV(uInt rownr, const Slicer &ns, const Array< uChar > *dataPtr)
void scalarVToSelection(uInt rownr)
virtual void getuShortV(uInt aRowNr, uShort *aDataPtr)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void putdoubleV(uInt aRowNr, const Double *aDataPtr)
virtual void putSliceBoolV(uInt rownr, const Slicer &ns, const Array< Bool > *dataPtr)
Put the array value into the given row.
virtual void getStringV(uInt aRowNr, String *aDataPtr)
Bool isSliced() const
Represents the vector a slice?
Definition: RefRows.h:136
virtual void putSlicefloatV(uInt rownr, const Slicer &ns, const Array< float > *dataPtr)
size_t size() const
Definition: ArrayBase.h:101
virtual void getSliceBoolV(uInt rownr, const Slicer &ns, Array< Bool > *dataPtr)
Get the array value in the given row.
virtual void putSliceComplexV(uInt rownr, const Slicer &ns, const Array< Complex > *dataPtr)
virtual Bool canAccessSlice(Bool &reask) const
Can the column data manager handle access to a cell slice? If not, the caller should do slicing itsel...
virtual void putuShortV(uInt aRowNr, const uShort *aDataPtr)
Base table column storage manager class.
Definition: StManColumn.h:102
virtual void putuCharV(uInt aRowNr, const uChar *aDataPtr)
uInt nelements() const
The number of elements in this IPosition.
Definition: IPosition.h:544
virtual void putComplexV(uInt aRowNr, const Complex *aDataPtr)
Adios2StMan::impl * itsStManPtr
virtual void getBoolV(uInt aRowNr, Bool *aDataPtr)
Get the scalar value in the given row.
unsigned int uInt
Definition: aipstype.h:51
Vector< uInt > convert(const Vector< uInt > &rootRownrs) const
Convert this object to a Vector&lt;uInt&gt; by applying the given row numbers.
std::shared_ptr< adios2::Engine > itsAdiosEngine
unsigned short uShort
Definition: aipstype.h:49
void toAdios(const void *dataPtr)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42