casacore
ImageAttrHandlerHDF5.h
Go to the documentation of this file.
1 //# ImageAttrHandlerHDF5.h: Attributes handler for HDF5 images
2 //# Copyright (C) 2012
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 IMAGES_IMAGEATTRHANDLERHDF5_H
29 #define IMAGES_IMAGEATTRHANDLERHDF5_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/images/Images/ImageAttrHandler.h>
35 #include <casacore/images/Images/ImageAttrGroupHDF5.h>
36 #include <casacore/casa/HDF5/HDF5Group.h>
37 #include <casacore/casa/Utilities/CountedPtr.h>
38 #include <map>
39 
40 namespace casacore {
41 
42 // <summary>
43 // Abstract base class for an image attributes handler.
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="" date="" tests="tPagedmage.cc" demos="dPagedImage.cc">
49 // </reviewed>
50 
51 // <prerequisite>
52 // <li> <linkto class=ImageInterface>ImageInterface</linkto>
53 // </prerequisite>
54 
55 // <etymology>
56 // This class makes it possible to store extra attributes with an image to
57 // describe atrbitrary meta information.
58 // </etymology>
59 
60 // <synopsis>
61 // For LOFAR it was needed to store extra meta information and to be able to
62 // convert it from casacore table format to HDF5 format and vice-versa.
63 // Furthermore, it must be possible to access the information in a way that
64 // arbitrary info can be stored and retrieved.
65 //
66 // The attributes are divided into handlers. Each handler can reside in a subtable
67 // of the image or in a handler in HDF5. All attributes in a handler have the
68 // same number of values, where each value can be a scalar or (small) array.
69 // It is possible to define units and measure info for an attribute.
70 // </synopsis>
71 
72 // <example>
73 // This example shows how to get attributes from an image.
74 // make it known to the image.
75 // <srcblock>
76 // // Open the image (as readonly for the moment).
77 // PagedImage<Float> myimage ("image.name");
78 // // Get access to attibute handler LOFAR_SOURCE.
79 // ImageExtrAttr& = myimage.attrHandler ("LOFAR_SOURCE");
80 // // Get the data for some field.
81 // Vector<String> names = ImageExtrAttr->getString("NAME");
82 // </srcblock>
83 // </example>
84 //
85 // <motivation>
86 // LOFAR needed functionality to store arbitrary attributes.
87 // </motivation>
88 
90 {
91 public:
92  // Default construct from the image table.
94 
95  // Attach the table and return this object.
96  // It looks for the table keyword ATTRGROUPS which contains the subtables
97  // defining the attribute groups.
98  // If the keyword does not exist, it will be added if <src>createHandler</src>
99  // is set.
100  // Otherwise the handler is an empty one and no groups can be added to it.
102  Bool createHandler = False);
103 
105 
106  // Attach the hid and return this object.
107  // It looks for the group ATTRGROUPS which contains groups
108  // defining the attribute groups.
109  // If the group does not exist, it will be added if <src>createHandler</src>
110  // is set.
111  // Otherwise the handler is an empty one and no groups can be added to it.
113  Bool createHandler,
114  Bool isWritable);
115 
116  // Flush the attibrutes if needed.
117  virtual void flush();
118 
119  // Test if the given attribute group is present.
120  virtual Bool hasGroup (const String& name);
121 
122  // Get all attribute group names.
123  virtual Vector<String> groupNames() const;
124 
125  // Get access to a group.
126  virtual ImageAttrGroup& openGroup (const String& groupName);
127 
128  // Create an attribute group with the given name.
129  virtual ImageAttrGroup& createGroup (const String& groupName);
130 
131  // Close the group with the given name. It will flush its attributes.
132  // Nothing is done if it is not open.
133  virtual void closeGroup (const String& groupName);
134 
135 private:
136  Bool itsCanWrite; //# writable?
137  CountedPtr<HDF5Group> itsGroup; //# HDF5 group to add to
138  std::map<String,ImageAttrGroupHDF5> itsGroupMap; //# attribute groups
139 };
140 
141 } //# NAMESPACE CASACORE - END
142 
143 #endif
Referenced counted pointer for constant data.
Definition: CountedPtr.h:81
virtual Vector< String > groupNames() const
Get all attribute group names.
ImageAttrHandlerHDF5 & attachHid(const HDF5Object &hid, Bool createHandler, Bool isWritable)
Attach the hid and return this object.
virtual void flush()
Flush the attibrutes if needed.
ImageAttrHandlerHDF5()
Default construct from the image table.
ImageAttrHandlerHDF5 & attachTable(const Table &image, Bool createHandler=False)
Attach the table and return this object.
virtual Bool hasGroup(const String &name)
Test if the given attribute group is present.
virtual ImageAttrGroup & openGroup(const String &groupName)
Get access to a group.
std::map< String, ImageAttrGroupHDF5 > itsGroupMap
virtual ImageAttrGroup & createGroup(const String &groupName)
Create an attribute group with the given name.
CountedPtr< HDF5Group > itsGroup
virtual void closeGroup(const String &groupName)
Close the group with the given name.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42