00001 //# ImageAttrHandlerHDF5.h: Attributes handler for HDF5 images 00002 //# Copyright (C) 2012 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef IMAGES_IMAGEATTRHANDLERHDF5_H 00029 #define IMAGES_IMAGEATTRHANDLERHDF5_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/images/Images/ImageAttrHandler.h> 00035 #include <casacore/images/Images/ImageAttrGroupHDF5.h> 00036 #include <casacore/casa/HDF5/HDF5Group.h> 00037 #include <casacore/casa/Utilities/CountedPtr.h> 00038 #include <map> 00039 00040 namespace casacore { 00041 00042 // <summary> 00043 // Abstract base class for an image attributes handler. 00044 // </summary> 00045 00046 // <use visibility=export> 00047 00048 // <reviewed reviewer="" date="" tests="tPagedmage.cc" demos="dPagedImage.cc"> 00049 // </reviewed> 00050 00051 // <prerequisite> 00052 // <li> <linkto class=ImageInterface>ImageInterface</linkto> 00053 // </prerequisite> 00054 00055 // <etymology> 00056 // This class makes it possible to store extra attributes with an image to 00057 // describe atrbitrary meta information. 00058 // </etymology> 00059 00060 // <synopsis> 00061 // For LOFAR it was needed to store extra meta information and to be able to 00062 // convert it from casacore table format to HDF5 format and vice-versa. 00063 // Furthermore, it must be possible to access the information in a way that 00064 // arbitrary info can be stored and retrieved. 00065 // 00066 // The attributes are divided into handlers. Each handler can reside in a subtable 00067 // of the image or in a handler in HDF5. All attributes in a handler have the 00068 // same number of values, where each value can be a scalar or (small) array. 00069 // It is possible to define units and measure info for an attribute. 00070 // </synopsis> 00071 00072 // <example> 00073 // This example shows how to get attributes from an image. 00074 // make it known to the image. 00075 // <srcblock> 00076 // // Open the image (as readonly for the moment). 00077 // PagedImage<Float> myimage ("image.name"); 00078 // // Get access to attibute handler LOFAR_SOURCE. 00079 // ImageExtrAttr& = myimage.attrHandler ("LOFAR_SOURCE"); 00080 // // Get the data for some field. 00081 // Vector<String> names = ImageExtrAttr->getString("NAME"); 00082 // </srcblock> 00083 // </example> 00084 // 00085 // <motivation> 00086 // LOFAR needed functionality to store arbitrary attributes. 00087 // </motivation> 00088 00089 class ImageAttrHandlerHDF5 : public ImageAttrHandler 00090 { 00091 public: 00092 // Default construct from the image table. 00093 ImageAttrHandlerHDF5(); 00094 00095 // Attach the table and return this object. 00096 // It looks for the table keyword ATTRGROUPS which contains the subtables 00097 // defining the attribute groups. 00098 // If the keyword does not exist, it will be added if <src>createHandler</src> 00099 // is set. 00100 // Otherwise the handler is an empty one and no groups can be added to it. 00101 ImageAttrHandlerHDF5& attachTable (const Table& image, 00102 Bool createHandler = False); 00103 00104 virtual ~ImageAttrHandlerHDF5(); 00105 00106 // Attach the hid and return this object. 00107 // It looks for the group ATTRGROUPS which contains groups 00108 // defining the attribute groups. 00109 // If the group does not exist, it will be added if <src>createHandler</src> 00110 // is set. 00111 // Otherwise the handler is an empty one and no groups can be added to it. 00112 ImageAttrHandlerHDF5& attachHid (const HDF5Object& hid, 00113 Bool createHandler, 00114 Bool isWritable); 00115 00116 // Flush the attibrutes if needed. 00117 virtual void flush(); 00118 00119 // Test if the given attribute group is present. 00120 virtual Bool hasGroup (const String& name); 00121 00122 // Get all attribute group names. 00123 virtual Vector<String> groupNames() const; 00124 00125 // Get access to a group. 00126 virtual ImageAttrGroup& openGroup (const String& groupName); 00127 00128 // Create an attribute group with the given name. 00129 virtual ImageAttrGroup& createGroup (const String& groupName); 00130 00131 // Close the group with the given name. It will flush its attributes. 00132 // Nothing is done if it is not open. 00133 virtual void closeGroup (const String& groupName); 00134 00135 private: 00136 Bool itsCanWrite; //# writable? 00137 CountedPtr<HDF5Group> itsGroup; //# HDF5 group to add to 00138 std::map<String,ImageAttrGroupHDF5> itsGroupMap; //# attribute groups 00139 }; 00140 00141 } //# NAMESPACE CASACORE - END 00142 00143 #endif