casacore
 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>
35 
36 #include "Adios2StManImpl.h"
37 
38 
39 namespace casacore
40 {
41 
43 {
44 public:
45  Adios2StManColumn(Adios2StMan::impl *aParent, int aDataType, String aColName, std::shared_ptr<adios2::IO> aAdiosIO);
46 
47  virtual void create(std::shared_ptr<adios2::Engine> aAdiosEngine,
48  char aOpenMode) = 0;
49  virtual void setShapeColumn(const IPosition &aShape) override;
50  virtual IPosition shape(rownr_t aRowNr) override;
51  Bool canChangeShape() const override;
52  void setShape (rownr_t aRowNr, const IPosition& aShape) override;
53 
54  int getDataTypeSize();
55  int getDataType();
57 
58 protected:
59 
60  // scalar get/put
61  virtual void getBool(rownr_t aRowNr, Bool *aDataPtr) override;
62  virtual void getuChar(rownr_t aRowNr, uChar *aDataPtr) override;
63  virtual void getShort(rownr_t aRowNr, Short *aDataPtr) override;
64  virtual void getuShort(rownr_t aRowNr, uShort *aDataPtr) override;
65  virtual void getInt(rownr_t aRowNr, Int *aDataPtr) override;
66  virtual void getuInt(rownr_t aRowNr, uInt *aDataPtr) override;
67  virtual void getInt64(rownr_t aRowNr, Int64 *aDataPtr) override;
68  virtual void getfloat(rownr_t aRowNr, Float *aDataPtr) override;
69  virtual void getdouble(rownr_t aRowNr, Double *aDataPtr) override;
70  virtual void getComplex(rownr_t aRowNr, Complex *aDataPtr) override;
71  virtual void getDComplex(rownr_t aRowNr, DComplex *aDataPtr) override;
72  virtual void getString(rownr_t aRowNr, String *aDataPtr) override;
73 
74  virtual void putBool(rownr_t aRowNr, const Bool *aDataPtr) override;
75  virtual void putuChar(rownr_t aRowNr, const uChar *aDataPtr) override;
76  virtual void putShort(rownr_t aRowNr, const Short *aDataPtr) override;
77  virtual void putuShort(rownr_t aRowNr, const uShort *aDataPtr) override;
78  virtual void putInt(rownr_t aRowNr, const Int *aDataPtr) override;
79  virtual void putuInt(rownr_t aRowNr, const uInt *aDataPtr) override;
80  virtual void putInt64(rownr_t aRowNr, const Int64 *aDataPtr) override;
81  virtual void putfloat(rownr_t aRowNr, const Float *aDataPtr) override;
82  virtual void putdouble(rownr_t aRowNr, const Double *aDataPtr) override;
83  virtual void putComplex(rownr_t aRowNr, const Complex *aDataPtr) override;
84  virtual void putDComplex(rownr_t aRowNr, const DComplex *aDataPtr) override;
85  virtual void putString(rownr_t aRowNr, const String *aDataPtr) override;
86 
87  // The rest of the get and put functions
88  virtual void getScalarColumnV (ArrayBase& dataPtr) override;
89  virtual void putScalarColumnV (const ArrayBase& dataPtr) override;
90  virtual void getScalarColumnCellsV (const RefRows& rownrs,
91  ArrayBase& dataPtr) override;
92  virtual void putScalarColumnCellsV (const RefRows& rownrs,
93  const ArrayBase& dataPtr) override;
94  virtual void getArrayV (rownr_t rownr, ArrayBase& dataPtr) override;
95  virtual void putArrayV (rownr_t rownr, const ArrayBase& data) override;
96  virtual void getArrayColumnV (ArrayBase& data) override;
97  virtual void putArrayColumnV (const ArrayBase& data) override;
98  virtual void getArrayColumnCellsV (const RefRows& rownrs,
99  ArrayBase& data) override;
100  virtual void putArrayColumnCellsV (const RefRows& rownrs,
101  const ArrayBase& data) override;
102  virtual void getSliceV (rownr_t rownr, const Slicer& slicer, ArrayBase& data) override;
103  virtual void putSliceV (rownr_t rownr, const Slicer& slicer,
104  const ArrayBase& data) override;
105  virtual void getColumnSliceV (const Slicer& slicer, ArrayBase& data) override;
106  virtual void putColumnSliceV (const Slicer& slicer, const ArrayBase& data) override;
107  virtual void getColumnSliceCellsV (const RefRows& rownrs,
108  const Slicer& slicer, ArrayBase& data) override;
109  virtual void putColumnSliceCellsV (const RefRows& rownrs,
110  const Slicer& slicer,
111  const ArrayBase& data) override;
112 
113 
114 private:
115  void putScalar(rownr_t rownr, const void *dataPtr);
116  void getScalar(rownr_t rownr, void *dataPtr);
117  virtual void toAdios(const ArrayBase *arrayPtr) = 0;
118  virtual void fromAdios(ArrayBase *arrayPtr) = 0;
119  virtual void toAdios(const void *dataPtr, std::size_t offset=0) = 0;
120  virtual void fromAdios(void *dataPtr, std::size_t offset=0) = 0;
121 
122 
123 protected:
124  void scalarToSelection(rownr_t rownr);
126  void scalarColumnCellsVToSelection(const RefRows &rownrs);
127  void arrayVToSelection(rownr_t rownr);
129  void sliceVToSelection(rownr_t rownr, const Slicer &ns);
130  void columnSliceVToSelection(const Slicer &ns);
131  void columnSliceCellsVToSelection(const RefRows &rows, const Slicer &ns);
132  void columnSliceCellsVToSelection(rownr_t row_start, rownr_t row_end, const Slicer &ns);
133 
135 
138  std::unordered_map<rownr_t, IPosition> itsCasaShapes;
140 
141  std::shared_ptr<adios2::IO> itsAdiosIO;
142  std::shared_ptr<adios2::Engine> itsAdiosEngine;
143  std::string itsAdiosDataType;
145  adios2::Dims itsAdiosStart = {0};
146  adios2::Dims itsAdiosCount = {1};
147 }; // class Adios2StManColumn
148 
149 
150 template <class T>
152 {
153 public:
154 
156 
157  void create(std::shared_ptr<adios2::Engine> aAdiosEngine, char aOpenMode)
158  {
159  itsAdiosEngine = aAdiosEngine;
160  itsAdiosVariable = itsAdiosIO->InquireVariable<T>(itsColumnName);
161  if (!itsAdiosVariable && aOpenMode == 'w')
162  {
163  itsAdiosVariable = itsAdiosIO->DefineVariable<T>(
167  itsAdiosCount);
168  }
169  }
170 
171 private:
172  adios2::Variable<T> itsAdiosVariable;
173 
174  void toAdios(const void *data, std::size_t offset)
175  {
176  const T *tData = static_cast<const T *>(data);
177  if(!isShapeFixed)
180  itsAdiosEngine->Put<T>(itsAdiosVariable, tData + offset, adios2::Mode::Sync);
181  }
182 
183  void fromAdios(void *data, std::size_t offset)
184  {
185  T *tData = static_cast<T *>(data);
187  itsAdiosEngine->Get<T>(itsAdiosVariable, tData + offset, adios2::Mode::Sync);
188  }
189 
190  void toAdios(const ArrayBase *arrayPtr)
191  {
192  Bool deleteIt;
193  const void *data = arrayPtr->getVStorage(deleteIt);
194  toAdios(data, 0);
195  arrayPtr->freeVStorage (data, deleteIt);
196  }
197 
198  void fromAdios(ArrayBase *arrayPtr)
199  {
200  Bool deleteIt;
201  void *data = arrayPtr->getVStorage(deleteIt);
202  fromAdios(data, 0);
203  arrayPtr->putVStorage(data, deleteIt);
204  }
205 
206 }; // class Adios2StManColumnT
207 
208 class Adios2StManColumnString : public Adios2StManColumnT<std::string>
209 {
210 public:
211  using Adios2StManColumnT::Adios2StManColumnT;
212 
213 protected:
214  void putArrayV(rownr_t rownr, const ArrayBase& data);
215  void getArrayV(rownr_t rownr, ArrayBase& data);
216  void getSliceV(rownr_t /*aRowNr*/, const Slicer &/*ns*/, ArrayBase &/*data*/);
217  void putSliceV(rownr_t /*aRowNr*/, const Slicer &/*ns*/, const ArrayBase &/*data*/);
218  void getColumnSliceV(const Slicer &/*ns*/, ArrayBase &/*data*/);
219  void putColumnSliceV(const Slicer &/*ns*/, const ArrayBase &/*data*/);
220  void getColumnSliceCellsV(const RefRows& /*rownrs*/, const Slicer& /*slicer*/, ArrayBase& /*data*/);
221  void putColumnSliceCellsV(const RefRows& /*rownrs*/, const Slicer& /*slicer*/, const ArrayBase& /*data*/);
222 
223 private:
224  const String itsStringArrayBarrier = "ADIOS2BARRIER";
225 }; // class Adios2StManColumnString
226 
227 } // namespace casacore
228 
229 #endif // ADIOS2STMANCOLUMN_H
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:118
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
virtual void putInt(rownr_t aRowNr, const Int *aDataPtr) override
virtual void putfloat(rownr_t aRowNr, const Float *aDataPtr) override
Non-templated base class for templated Array class.
Definition: ArrayBase.h:72
void toAdios(const void *data, std::size_t offset)
void columnSliceCellsVToSelection(const RefRows &rows, const Slicer &ns)
virtual void putComplex(rownr_t aRowNr, const Complex *aDataPtr) override
virtual void getArrayV(rownr_t rownr, ArrayBase &dataPtr) override
Get the array value in the given row.
void getArrayV(rownr_t rownr, ArrayBase &data)
Get the array value in the given row.
virtual void getString(rownr_t aRowNr, String *aDataPtr) override
virtual void putDComplex(rownr_t aRowNr, const DComplex *aDataPtr) override
virtual void putArrayV(rownr_t rownr, const ArrayBase &data) override
Put the array value into the given row.
void putColumnSliceCellsV(const RefRows &, const Slicer &, const ArrayBase &)
Put into a section of some arrays in the column.
void putArrayV(rownr_t rownr, const ArrayBase &data)
Put the array value into the given row.
virtual void putdouble(rownr_t aRowNr, const Double *aDataPtr) override
Adios2StManColumn(Adios2StMan::impl *aParent, int aDataType, String aColName, std::shared_ptr< adios2::IO > aAdiosIO)
virtual void putuShort(rownr_t aRowNr, const uShort *aDataPtr) override
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
void getColumnSliceCellsV(const RefRows &, const Slicer &, ArrayBase &)
Get a section of some arrays in the column.
virtual void getShort(rownr_t aRowNr, Short *aDataPtr) override
unsigned char uChar
Definition: aipstype.h:47
virtual void putScalarColumnCellsV(const RefRows &rownrs, const ArrayBase &dataPtr) override
Put some scalar values in the column.
virtual void create(std::shared_ptr< adios2::Engine > aAdiosEngine, char aOpenMode)=0
virtual void putArrayColumnCellsV(const RefRows &rownrs, const ArrayBase &data) override
Put some array values in the column.
void putColumnSliceV(const Slicer &, const ArrayBase &)
Put into a section of all arrays in the column.
virtual void getArrayColumnCellsV(const RefRows &rownrs, ArrayBase &data) override
Get some array values in the column.
virtual void putuChar(rownr_t aRowNr, const uChar *aDataPtr) override
Base table column storage manager class.
virtual void getColumnSliceCellsV(const RefRows &rownrs, const Slicer &slicer, ArrayBase &data) override
Get a section of some arrays in the column.
void scalarToSelection(rownr_t rownr)
virtual void getDComplex(rownr_t aRowNr, DComplex *aDataPtr) override
virtual void * getVStorage(bool &deleteIt)
The following functions behave the same as the corresponding getStorage functions in the derived temp...
void fromAdios(ArrayBase *arrayPtr)
adios2::Variable< T > itsAdiosVariable
virtual void getScalarColumnV(ArrayBase &dataPtr) override
The rest of the get and put functions.
short Short
Definition: aipstype.h:48
virtual void getInt64(rownr_t aRowNr, Int64 *aDataPtr) override
virtual void getuInt(rownr_t aRowNr, uInt *aDataPtr) override
void toAdios(const ArrayBase *arrayPtr)
virtual void getuShort(rownr_t aRowNr, uShort *aDataPtr) override
virtual void toAdios(const ArrayBase *arrayPtr)=0
void getScalar(rownr_t rownr, void *dataPtr)
virtual IPosition shape(rownr_t aRowNr) override
Get the shape of the item in the given row.
std::shared_ptr< adios2::IO > itsAdiosIO
void setShape(rownr_t aRowNr, const IPosition &aShape) override
Set the shape of an (variable-shaped) array in the given row.
virtual void getfloat(rownr_t aRowNr, Float *aDataPtr) override
virtual void putBool(rownr_t aRowNr, const Bool *aDataPtr) override
Put the scalar value into the given row.
virtual void getBool(rownr_t aRowNr, Bool *aDataPtr) override
scalar get/put
virtual void putuInt(rownr_t aRowNr, const uInt *aDataPtr) override
double Double
Definition: aipstype.h:55
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
void putSliceV(rownr_t, const Slicer &, const ArrayBase &)
Put into a section of the array in the given row.
virtual void getSliceV(rownr_t rownr, const Slicer &slicer, ArrayBase &data) override
Get a section of the array in the given row.
void create(std::shared_ptr< adios2::Engine > aAdiosEngine, char aOpenMode)
void getColumnSliceV(const Slicer &, ArrayBase &)
Get a section of all arrays in the column.
virtual void getuChar(rownr_t aRowNr, uChar *aDataPtr) override
virtual void putColumnSliceV(const Slicer &slicer, const ArrayBase &data) override
Put into a section of all arrays in the column.
virtual void getComplex(rownr_t aRowNr, Complex *aDataPtr) override
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void putScalar(rownr_t rownr, const void *dataPtr)
virtual void getdouble(rownr_t aRowNr, Double *aDataPtr) override
void arrayVToSelection(rownr_t rownr)
virtual void putColumnSliceCellsV(const RefRows &rownrs, const Slicer &slicer, const ArrayBase &data) override
Put into a section of some arrays in the column.
void scalarColumnCellsVToSelection(const RefRows &rownrs)
virtual void getInt(rownr_t aRowNr, Int *aDataPtr) override
float Float
Definition: aipstype.h:54
virtual void putScalarColumnV(const ArrayBase &dataPtr) override
Put all scalar values in the column.
Bool canChangeShape() const override
Can the data manager handle chaging the shape of an existing array? Default is no.
virtual void fromAdios(ArrayBase *arrayPtr)=0
virtual void putInt64(rownr_t aRowNr, const Int64 *aDataPtr) override
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:288
virtual void getColumnSliceV(const Slicer &slicer, ArrayBase &data) override
Get a section of all arrays in the column.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
virtual void putArrayColumnV(const ArrayBase &data) override
Put all array values in the column.
virtual void getScalarColumnCellsV(const RefRows &rownrs, ArrayBase &dataPtr) override
Get some scalar values in the column.
virtual void setShapeColumn(const IPosition &aShape) override
Set the shape of all (fixed-shaped) arrays in the column.
std::unordered_map< rownr_t, IPosition > itsCasaShapes
void columnSliceVToSelection(const Slicer &ns)
String: the storage and methods of handling collections of characters.
Definition: String.h:225
virtual void putString(rownr_t aRowNr, const String *aDataPtr) override
void fromAdios(void *data, std::size_t offset)
virtual void putVStorage(void *&storage, bool deleteAndCopy)
virtual void getArrayColumnV(ArrayBase &data) override
Get all array values in the column.
virtual void freeVStorage(const void *&storage, bool deleteIt) const
virtual void putSliceV(rownr_t rownr, const Slicer &slicer, const ArrayBase &data) override
Put into a section of the array in the given row.
virtual void putShort(rownr_t aRowNr, const Short *aDataPtr) override
Adios2StMan::impl * itsStManPtr
void sliceVToSelection(rownr_t rownr, const Slicer &ns)
unsigned int uInt
Definition: aipstype.h:51
std::shared_ptr< adios2::Engine > itsAdiosEngine
unsigned short uShort
Definition: aipstype.h:49
void getSliceV(rownr_t, const Slicer &, ArrayBase &)
Get a section of the array in the given row.