Loading...
Searching...
No Matches
HDF5DataType.h
Go to the documentation of this file.
//# HDF5DataType.h: An class representing an HDF5 data type
//# Copyright (C) 2008
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef CASA_HDF5DATATYPE_H
#define CASA_HDF5DATATYPE_H
//# Includes
#include <casacore/casa/aips.h>
#include <casacore/casa/HDF5/HDF5Object.h>
#include <casacore/casa/HDF5/HDF5HidMeta.h>
#include <casacore/casa/BasicSL/Complex.h>
#include <casacore/casa/BasicSL/String.h>
#include <casacore/casa/Utilities/DataType.h>
#include <vector>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward Declarations
class IPosition;
template<typename T> class Block;
// <summary>
// A class representing an HDF5 data type.
// </summary>
// <use visibility=local>
// <reviewed reviewer="" date="" tests="tHDF5DataType.cc">
// </reviewed>
// <prerequisite>
// <li> <a href="http://hdf.ncsa.uiuc.edu">HDF5 system</a>
// </prerequisite>
// <synopsis>
// This class wraps the HDF5 functions to create a data type
// for the data in memory and for the file.
// The HDF5 file data type order is set to LittleEndian.
// <br>
// The basic constructors define a scalar of a basic data type or
// data type Complex and DComplex. Strings are also supported.
// However, it is also possible to define a fixed shaped array for any
// HDF5DataType. Furthermore, it is possible to define a compound data
// type consisting of named fields of any HDF5DataType with a fixed size.
// Arrays and/or compounds can be nested at will.
// <br>
// Variable length strings are supported, but cannot be used in compounds.
// <br>
// Older HDF5 versions did not support empty arrays. Therefore they are
// represented as a compound with 3 fields. Also they did not support
// boolean values; they are represented as a signed char.
// HDF5 does not support complex values either. They are represented
// as a compound with fields 're' and 'im'.
// </synopsis>
// <motivation>
// The HDF5 C++ interface only supports the HDF5 C functionality and
// resembles that to much. For instance, it does not use STL containers.
// It does not support non-basic data types, in particular Complex.
// </motivation>
class HDF5DataType
{
public:
// The default constructor makes an invalid object.
// It is needed to make a vector of objects.
HDF5DataType()
: itsSize(0)
{}
// Create an HDF5 datatype object for the given fixed length type.
// It uses the corresponding native HDF5 data type. Only for Bool it
// uses a uchar, because the HDF5 bool type is a uint.
// For the complex types it makes a compound HDF5 data type.
// The String type is meant for an array of strings.
// <group>
explicit HDF5DataType (const Bool*);
explicit HDF5DataType (const uChar*);
explicit HDF5DataType (const Short*);
explicit HDF5DataType (const uShort*);
explicit HDF5DataType (const Int*);
explicit HDF5DataType (const uInt*);
explicit HDF5DataType (const Int64*);
explicit HDF5DataType (const Float*);
explicit HDF5DataType (const Double*);
explicit HDF5DataType (const Complex*);
explicit HDF5DataType (const DComplex*);
explicit HDF5DataType (const String*);
// </group>
// Create an HDF5 datatype object for a scalar string.
// The length of the string is part of the type.
explicit HDF5DataType (const String& value);
// Create an HDF5 datatype object for an empty array.
// Both arguments are dummy (needed to distinguish the constructor).
// An empty array as represented as a compound data type with integer
// field names emptyarray, rank and casatype.
HDF5DataType (Int, Int);
// Define a compound data type consisting of the given fields and types.
// An exception is thrown if the vectors are empty or have mismatching
// sizes.
HDF5DataType (const std::vector<String>& names,
const std::vector<HDF5DataType>& types);
// Create an array of the given data type.
// An exception is thrown if the shape is empty.
HDF5DataType (const HDF5DataType&, const IPosition& shape);
// The copy constructor makes a deep copy.
HDF5DataType (const HDF5DataType& that);
// The destructor closes the HDF5 data type object.
~HDF5DataType();
// Assignment makes a deep copy.
HDF5DataType& operator= (const HDF5DataType& that);
// Get the Casacore data type for the given HDF5 data type.
// TpRecord is returned for a compound data type.
static DataType getDataType (hid_t);
// Get the HID for the data type in memory.
hid_t getHidMem() const
{ return itsHidMem; }
// Get the HID for the data type in the file.
hid_t getHidFile() const
{ return itsHidFile; }
// Get the size in bytes of the data type (in memory).
// Note that the size of a string is variable, thus 0.
uInt size() const
{ return itsSize; }
// Test if the data type is Complex or DComplex.
static Bool isComplex (hid_t dtid);
// Test if the data type is an empty array.
static Bool isEmptyArray (hid_t dtid);
// Get the shape of an array data type.
// It returns an empty IPosition for non-arrays.
static IPosition getShape (hid_t dtid);
// Helper functions to convert shapes.
// It reverses the axes, because HDF5 uses C-order.
// <group>
static Block<hsize_t> fromShape (const IPosition& shape);
static IPosition toShape (const Block<hsize_t>& b);
// </group>
private:
// Add a field to a compound data type.
// It does it for the memory and file data type.
void addToCompound (const char* name,
uInt offset,
const HDF5DataType& dtype);
//# Data members
HDF5HidDataType itsHidMem;
HDF5HidDataType itsHidFile;
uInt itsSize;
};
}
#endif
casacore::Block
simple 1-D array
Definition Block.h:198
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Short *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const HDF5DataType &, const IPosition &shape)
Create an array of the given data type.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Bool *)
Create an HDF5 datatype object for the given fixed length type.
casacore::HDF5DataType::addToCompound
void addToCompound(const char *name, uInt offset, const HDF5DataType &dtype)
Add a field to a compound data type.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const DComplex *)
casacore::HDF5DataType::~HDF5DataType
~HDF5DataType()
The destructor closes the HDF5 data type object.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const uInt *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const std::vector< String > &names, const std::vector< HDF5DataType > &types)
Define a compound data type consisting of the given fields and types.
casacore::HDF5DataType::itsHidFile
HDF5HidDataType itsHidFile
Definition HDF5DataType.h:185
casacore::HDF5DataType::toShape
static IPosition toShape(const Block< hsize_t > &b)
casacore::HDF5DataType::itsHidMem
HDF5HidDataType itsHidMem
Definition HDF5DataType.h:184
casacore::HDF5DataType::operator=
HDF5DataType & operator=(const HDF5DataType &that)
Assignment makes a deep copy.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(Int, Int)
Create an HDF5 datatype object for an empty array.
casacore::HDF5DataType::isComplex
static Bool isComplex(hid_t dtid)
Test if the data type is Complex or DComplex.
casacore::HDF5DataType::getHidMem
hid_t getHidMem() const
Get the HID for the data type in memory.
Definition HDF5DataType.h:147
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Complex *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Int *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const String &value)
Create an HDF5 datatype object for a scalar string.
casacore::HDF5DataType::itsSize
uInt itsSize
Definition HDF5DataType.h:186
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Int64 *)
casacore::HDF5DataType::getHidFile
hid_t getHidFile() const
Get the HID for the data type in the file.
Definition HDF5DataType.h:151
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const String *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const HDF5DataType &that)
The copy constructor makes a deep copy.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Double *)
casacore::HDF5DataType::size
uInt size() const
Get the size in bytes of the data type (in memory).
Definition HDF5DataType.h:156
casacore::HDF5DataType::isEmptyArray
static Bool isEmptyArray(hid_t dtid)
Test if the data type is an empty array.
casacore::HDF5DataType::HDF5DataType
HDF5DataType()
The default constructor makes an invalid object.
Definition HDF5DataType.h:89
casacore::HDF5DataType::getDataType
static DataType getDataType(hid_t)
Get the Casacore data type for the given HDF5 data type.
casacore::HDF5DataType::fromShape
static Block< hsize_t > fromShape(const IPosition &shape)
Helper functions to convert shapes.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const uShort *)
casacore::HDF5DataType::getShape
static IPosition getShape(hid_t dtid)
Get the shape of an array data type.
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const uChar *)
casacore::HDF5DataType::HDF5DataType
HDF5DataType(const Float *)
casacore::HDF5HidDataType
A class representing an HDF5 datatype hid.
Definition HDF5HidMeta.h:100
casacore::IPosition
Definition IPosition.h:117
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::uChar
unsigned char uChar
Definition aipstype.h:45
casacore::offset
int offset(int, int) const
compute a linear offset from array indicies
casacore::Short
short Short
Definition aipstype.h:46
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::uShort
unsigned short uShort
Definition aipstype.h:47
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size).
Definition aipsxtype.h:36
casacore::shape
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
casacore::Float
float Float
Definition aipstype.h:52
casacore::name
String name() const
Return the name of the field.
Definition RecordField.h:163
casacore::Int
int Int
Definition aipstype.h:48
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
casacore::value
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368
casacore::Double
double Double
Definition aipstype.h:53