00001 //# ImageAttrGroup.h: Abstract base class for an image attributes group 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_IMAGEATTRGROUP_H 00029 #define IMAGES_IMAGEATTRGROUP_H 00030 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/Containers/ValueHolder.h> 00035 #include <casacore/casa/Arrays/Vector.h> 00036 00037 namespace casacore { 00038 00039 // <summary> 00040 // Abstract base class for an image attributes group. 00041 // </summary> 00042 00043 // <use visibility=export> 00044 00045 // <reviewed reviewer="" date="" tests="tPagedmage.cc" demos="dPagedImage.cc"> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 // <li> <linkto class=ImageInterface>ImageInterface</linkto> 00050 // </prerequisite> 00051 00052 // <etymology> 00053 // This class makes it possible to store extra attributes with an image to 00054 // describe atrbitrary meta information. 00055 // </etymology> 00056 00057 // <synopsis> 00058 // For LOFAR it is needed to store extra meta information and be possible to 00059 // convert it from casacore table format to HDF5 format and vice-versa. 00060 // Furthermore, it must be possible to access the information in a way that 00061 // arbitrary attributes can be stored and retrieved in a way that is agnostic 00062 // to the format the image is stored in. It must also work fine for an image 00063 // stored in FITS format, be it that such an image cannot have such attributes. 00064 // 00065 // The attributes are divided into groups. A group resides in a subtable 00066 // of a casacore image or in a group of an HDF5 image. This class handles 00067 // the attributes of a group. It can get and put the attribute values, as well 00068 // as their unit and measure info (type and reference frame type). 00069 // For HDF5 images the unit is stored in attribute <src>attrname>_UNIT</src> 00070 // and the measure info in <src>attrname>_MEASINFO</src>. For casacore images 00071 // that info is stored as TableMeasure info in the column keywords. 00072 // 00073 // All attributes in a group must have the same number of values, where each 00074 // value can be a scalar or (small) array. The unit and measure info have 00075 // only one value, thus all values of an attribute have the same unit. 00076 // </synopsis> 00077 00078 // <example> 00079 // This example shows how to get attributes from an image. 00080 // <srcblock> 00081 // // Open the image. 00082 // PagedImage<Float> myimage ("image.name"); 00083 // // Open the attribute handler. 00084 // ImageAttrHandler& attrHandler = myimage.attrHandler(); 00085 // // Get access to attibute group LOFAR_SOURCE. 00086 // ImageAttrGroup& lofarSource = attrHandler.openGroup ("LOFAR_SOURCE"); 00087 // // Get the names of all attributes in this group. 00088 // Vector<String> attrNames = lofarSource.attrNames(); 00089 // // Get the value of the ATTRNAME attribute (if there). 00090 // if (lofarSource.hasAttr ("ATTRNAME)) { 00091 // ValueHolder vh (lofarSource.getData ("ATTRNAME")); 00092 // Vector<String> name = vh.asString(); 00093 // } 00094 // </srcblock> 00095 // The following example shows how to add a group and attribute. 00096 // <srcblock> 00097 // // Open the image. 00098 // PagedImage<Float> myimage ("image.name"); 00099 // // Open the attribute handler. 00100 // ImageAttrHandler& attrHandler = myimage.attrHandler(); 00101 // // Add attribute group LOFAR_SOURCE. 00102 // ImageAttrGroup& lofarSource = attrHandler.createGroup (LOFAR_SOURCE); 00103 // // Add an attribute which has unit Hz. 00104 // // The value has 2 values (e.g. for 2 frequency bands). 00105 // Vector<double> freqs(2); 00106 // freqs[0]=4.5e7; freqs[1]=5.5e7; 00107 // lofarSource.putData ("CENTER_FREQ", ValueHolder(freqs), 00108 // Vector<String(1,"Hz")); 00109 // </srcblock> 00110 // </example> 00111 // 00112 // <motivation> 00113 // LOFAR needed functionality to store arbitrary attributes. 00114 // </motivation> 00115 00116 class ImageAttrGroup 00117 { 00118 public: 00119 // Default constructor. 00120 ImageAttrGroup() 00121 {} 00122 00123 virtual ~ImageAttrGroup(); 00124 00125 // Get the number of rows in the group. 00126 virtual uInt nrows() const = 0; 00127 00128 // Test if an attribute exists. 00129 virtual Bool hasAttr (const String& attrName) const = 0; 00130 00131 // Get all attribute names. 00132 virtual Vector<String> attrNames() const = 0; 00133 00134 // Get the datatype of a attribute. 00135 // It returns TpOther if the attribute is not defined. 00136 virtual DataType dataType (const String& attrName) const = 0; 00137 00138 // Get the data of the given attribute in the given row 00139 virtual ValueHolder getData (const String& attrName, uInt rownr) = 0; 00140 00141 // Get the data of all attributes in a rows. 00142 virtual Record getDataRow (uInt rownr) = 0; 00143 00144 // Get the possible units of the values. 00145 // An empty vector is returned if the attribute has no units. 00146 virtual Vector<String> getUnit (const String& attrName) = 0; 00147 00148 // Get the possible measure info as type and Ref. 00149 // An empty vector is returned if the attribute has no MEASINFO. 00150 virtual Vector<String> getMeasInfo (const String& attrName) = 0; 00151 00152 // Put the data of the given attribute in the given row. 00153 // If the row or attribute is new, it will be added. Note that the 00154 // new row must be directly after the last row in the group. 00155 // <br>If not empty, the units and MEASINFO will be put as column keywords. 00156 // The MEASINFO vector must be given as type,Ref. 00157 virtual void putData (const String& attrName, uInt rownr, 00158 const ValueHolder& data, 00159 const Vector<String>& units = Vector<String>(), 00160 const Vector<String>& measInfo = Vector<String>()) = 0; 00161 }; 00162 00163 } //# NAMESPACE CASACORE - END 00164 00165 #endif