casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VLAArchiveInput.h
Go to the documentation of this file.
1 //# VLAArchiveInput.h: An abstract class for reading VLA archive records
2 //# Copyright (C) 1999,2000
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 NRAO_VLAARCHIVEINPUT_H
29 #define NRAO_VLAARCHIVEINPUT_H
30 
31 #include <casa/aips.h>
32 #include <casa/IO/ByteSinkSource.h>
33 #include <casa/IO/ConversionIO.h>
34 #include <casa/IO/MemoryIO.h>
36 
37 #include <casa/namespace.h>
38 namespace casacore{
39 
40 class ByteSource;
41 }
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 } //# NAMESPACE CASA - END
45 
46 
47 // <summary>This class reads VLA archive records from a Tape</summary>
48 
49 // <reviewed reviewer="" date="" tests="" demos="">
50 
51 // <prerequisite>
52 // <ol>
53 // <li> The IO Module
54 // </ol>
55 // </prerequisite>
56 //
57 // <etymology>
58 // This class is designed to reads VLA archive records from a Tape
59 // </etymology>
60 //
61 // <synopsis>
62 
63 // This class is designed to read VLA archive data. The data may be read from
64 // a disk, tape drive or any other data source supported by the IO module. A
65 // call to the operator++() function assembles the next reconstructed VLA
66 // archive data record from the input. A reference to this data can be
67 // obtained using the logicalRecord function.
68 //
69 // Refer to the "VLA Archive casacore::Data casacore::Format", VLA Computer Memorandum 186
70 // by G.C. Hunt, K.P. Sowinski, and T.J. Bottomly; June 1993.
71 // (This is also available as AIPS++ note 159)
72 //
73 // The VLA archive records are always a multiple of 2048 bytes. The
74 // record sizes were designed for use with magnetic tapes, so there is
75 // a maximum physical record size of 13*2048=26624 bytes.
76 //
77 // The low level class (blockio), that actually does the I/O, allows
78 // for a record (hereinafter chunk) size and for a input block size of
79 // a multiple of the chunk size. The low level read operation tests
80 // for the number of bytes actually read from the device.
81 //
82 // The helper classes VlaDiskInput, VlaTapeInput, and VlaStdInput are
83 // designed to deal with the low level input from the devices in an
84 // analogous fashion to the ones used for casacore::FITS input.
85 //
86 // Since a read may be issued for an arbitrary number of bytes from a
87 // disk, the chunk multiple is arbitrary and may be used to tune the
88 // speed of operation. There is an obvious trade-off between the
89 // block size created in the blockio class and the number of read
90 // operations.
91 //
92 // The story is quite different for tape input. A read request for at
93 // least the maximum physical record size must be made to avoid loss of
94 // data. Since a single tape record will be read with a single read
95 // operation, there is no point is having it any larger. The chunk
96 // multiple must be exactly 13 so that the block size is 26624.
97 //
98 // The reconstitution algorithm is as follows:
99 //
100 // 1. Read a 2048 chunk from the input.
101 //
102 // The first two 16-bit integers should contain the values 1 and n,
103 // where n is the number of "physical records" in the current "logical
104 // record." (If the first value is not 1, then the chunk is rejected
105 // and a new one read until the first 16-bit value is 1.) These two
106 // values are not part of the reconstituted "logical record."
107 //
108 // 2. The next 32-bit integer contains the length of the "logical
109 // record" in 16-bit words. The buffer is resized so that it can
110 // contain the whole reconstituted "logical record."
111 //
112 // 3. The remainder of the chunk is copied to the buffer.
113 //
114 // 4. Successive chunks are read from the input.
115 //
116 // The chunks are copied into the buffer until the "logical record"
117 // is complete. For "logical records" longer than 26620 byte, this is
118 // not the whole story. Each "physical record" contains maximum of 13
119 // chunks. When the first "physical record" of 13 chunks has been read,
120 // the next chunk will be the first of the next "physical record." The
121 // first two 16-bit integers will now be 2 and n, to indicate that this
122 // is the second "physical record" of the sequence. These 4 bytes are
123 // decoded and the rest of this chunk is copied to the buffer. And so
124 // on...
125 //
126 // An end-of-file condition on the input will cause record processing
127 // to be declared complete.
128 // </synopsis>
129 //
130 // <example>
131 // To open and read a VLA archive data file
132 // <code>
133 // VLAArchiveInput *in;
134 // casacore::Block <casacore::Char> *buff;
135 // casacore::String fileName = " ";
136 // casacore::String fileType = "tape";
137 //
138 // if (fileType == casacore::String("tape")) {
139 // in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Tape);
140 // } else {
141 // in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Disk);
142 // }
143 //
144 // casacore::uInt record = 0;
145 // for (buff=&(in->next()); in->atEnd()==false; buff=&(in->next()), record++) {
146 // cout << "casacore::Record" << record << endl;
147 // // process record pointed to by buff
148 // }
149 // </code>
150 //
151 // </example>
152 //
153 // <motivation>
154 // </motivation>
155 //
156 // <todo asof="">
157 // <ol>
158 // <li> Bulletproofing - check for realistic buffer size (<1e6)
159 // <li> Bulletproofing - check newn and newm on each read
160 // <li> What happens after a single end-of-file on a tape drive?
161 // <li> Add record skipping
162 // <li> Should it work with stdin? This is in place but not debugged.
163 // </ol>
164 // </todo>
165 
167 {
168 public:
169  // The destructor is virtual to ensure that the destructor in a derived
170  // class is actually used.
171  virtual ~VLAArchiveInput();
172 
173  // This returns a reconstructed VLA logical record from the input
174  // stream. This casacore::ByteSource has the data stored in memory, and hence is
175  // seekable. casacore::Data read from this casacore::ByteSource will have the ModComp numeric
176  // conversions applied.
178  const casacore::ByteSource& logicalRecord() const;
179 
180  // Reads the next logical record from specified IO source. Returns false if
181  // there was a problem assembling the next record ie., it returns the value
182  // of the hasData() member function.
183  virtual casacore::Bool read() = 0;
184 
185  // Returns if true if the current record contains data. The current record
186  // could be empty for a number of reasons including:
187  // <ul>
188  // <li> You attempted to read beyond the end of the file.
189  // <li> The physical record sequence numbers were not the expected ones
190  // <li> An I/O Error occured while trying to read from the file.
191  // <li> The beginning of a logical record could not be found. This is after
192  // searching 5MB of data.
193  // </ul>
194  casacore::Bool hasData() const;
195 
196 protected:
197  //# the default constructor initialises the itsRecord data member
198  VLAArchiveInput();
199 
200  //# All reads will be in multiples of this blocksize.
201  static const casacore::uInt BlockSize;
202  //# The size in bytes of the physical record sequence numbers
204  //# A Physical casacore::Record can never be bigger than this many blocks.
206 
207  //# These objects contains the current logical record. The memory IO object
208  //# is used to put the data. It is taken out using the casacore::ByteSinkSource which
209  //# will apply any numeric conversions.
211 
212 private:
215 
216 protected:
218 };
219 #endif
This class reads VLA archive records from a Tape.
static const casacore::uInt HeaderSize
virtual ~VLAArchiveInput()
The destructor is virtual to ensure that the destructor in a derived class is actually used...
Class for read-only access to data in a given format.
Definition: ByteSource.h:91
Class for IO in a converted format.
Definition: ConversionIO.h:74
casacore::Bool hasData() const
Returns if true if the current record contains data.
casacore::ByteSource & logicalRecord()
This returns a reconstructed VLA logical record from the input stream.
static const casacore::uInt MaxBlocksPerPhysicalRecord
casacore::MemoryIO itsMemIO
Class for read/write access to data in a given format.
casacore::ConversionIO itsCtrIO
casacore::ByteSinkSource itsRecord
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
A DataConversion class to convert between Modcomp format.
Class for IO to a memory buffer.
Definition: MemoryIO.h:124
static const casacore::uInt BlockSize
casacore::ModcompDataConversion itsModComp
virtual casacore::Bool read()=0
Reads the next logical record from specified IO source.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42