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