casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VLADiskInput.h
Go to the documentation of this file.
1 //# VLADiskInput.h: This class reads VLA archive files from a Disk
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: VLADiskInput.h,v 19.3.14.1 2006/02/12 05:56:12 wyoung Exp $
27 
28 #ifndef NRAO_VLADISKINPUT_H
29 #define NRAO_VLADISKINPUT_H
30 
31 #include <casa/aips.h>
32 #include <casa/IO/RegularFileIO.h>
34 
35 #include <casa/namespace.h>
36 namespace casacore{
37 
38 class Path;
39 }
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 } //# NAMESPACE CASA - END
43 
44 
45 // <summary>This class reads VLA archive records from a Disk file</summary>
46 
47 // <reviewed reviewer="" date="" tests="" demos="">
48 
49 // <prerequisite>
50 // <ol>
51 // <li> The IO Module
52 // </ol>
53 // </prerequisite>
54 //
55 // <etymology>
56 // This class is designed to reads VLA archive records from a Disk file
57 // </etymology>
58 //
59 // <synopsis>
60 
61 // This class is designed to read VLA archive data. The data may be read from
62 // a disk, tape drive or any other data source supported by the IO module. A
63 // call to the operator++() function assembles the next reconstructed VLA
64 // archive data record from the input. A reference to this data can be
65 // obtained using the logicalRecord function.
66 //
67 // Refer to the "VLA Archive casacore::Data casacore::Format", VLA Computer Memorandum 186
68 // by G.C. Hunt, K.P. Sowinski, and T.J. Bottomly; June 1993.
69 // (This is also available as AIPS++ note 159)
70 //
71 // The VLA archive records are always a multiple of 2048 bytes. The
72 // record sizes were designed for use with magnetic tapes, so there is
73 // a maximum physical record size of 13*2048=26624 bytes.
74 //
75 // The low level class (blockio), that actually does the I/O, allows
76 // for a record (hereinafter chunk) size and for a input block size of
77 // a multiple of the chunk size. The low level read operation tests
78 // for the number of bytes actually read from the device.
79 //
80 // The helper classes VlaDiskInput, VlaTapeInput, and VlaStdInput are
81 // designed to deal with the low level input from the devices in an
82 // analogous fashion to the ones used for casacore::FITS input.
83 //
84 // Since a read may be issued for an arbitrary number of bytes from a
85 // disk, the chunk multiple is arbitrary and may be used to tune the
86 // speed of operation. There is an obvious trade-off between the
87 // block size created in the blockio class and the number of read
88 // operations.
89 //
90 // The story is quite different for tape input. A read request for at
91 // least the maximum physical record size must be made to avoid loss of
92 // data. Since a single tape record will be read with a single read
93 // operation, there is no point is having it any larger. The chunk
94 // multiple must be exactly 13 so that the block size is 26624.
95 //
96 // The reconstitution algorithm is as follows:
97 //
98 // 1. Read a 2048 chunk from the input.
99 //
100 // The first two 16-bit integers should contain the values 1 and n,
101 // where n is the number of "physical records" in the current "logical
102 // record." (If the first value is not 1, then the chunk is rejected
103 // and a new one read until the first 16-bit value is 1.) These two
104 // values are not part of the reconstituted "logical record."
105 //
106 // 2. The next 32-bit integer contains the length of the "logical
107 // record" in 16-bit words. The buffer is resized so that it can
108 // contain the whole reconstituted "logical record."
109 //
110 // 3. The remainder of the chunk is copied to the buffer.
111 //
112 // 4. Successive chunks are read from the input.
113 //
114 // The chunks are copied into the buffer until the "logical record"
115 // is complete. For "logical records" longer than 26620 byte, this is
116 // not the whole story. Each "physical record" contains maximum of 13
117 // chunks. When the first "physical record" of 13 chunks has been read,
118 // the next chunk will be the first of the next "physical record." The
119 // first two 16-bit integers will now be 2 and n, to indicate that this
120 // is the second "physical record" of the sequence. These 4 bytes are
121 // decoded and the rest of this chunk is copied to the buffer. And so
122 // on...
123 //
124 // An end-of-file condition on the input will cause record processing
125 // to be declared complete.
126 // </synopsis>
127 //
128 // <example>
129 // To open and read a VLA archive data file
130 // <code>
131 // VLAArchiveInput *in;
132 // casacore::Block <casacore::Char> *buff;
133 // casacore::String fileName = " ";
134 // casacore::String fileType = "tape";
135 //
136 // if (fileType == casacore::String("tape")) {
137 // in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Tape);
138 // } else {
139 // in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Disk);
140 // }
141 //
142 // casacore::uInt record = 0;
143 // for (buff=&(in->next()); in->atEnd()==false; buff=&(in->next()), record++) {
144 // cout << "casacore::Record" << record << endl;
145 // // process record pointed to by buff
146 // }
147 // </code>
148 //
149 // </example>
150 //
151 // <motivation>
152 // </motivation>
153 //
154 // <todo asof="">
155 // <ol>
156 // <li> Bulletproofing - check for realistic buffer size (<1e6)
157 // <li> Bulletproofing - check newn and newm on each read
158 // <li> What happens after a single end-of-file on a tape drive?
159 // <li> Add record skipping
160 // <li> Should it work with stdin? This is in place but not debugged.
161 // </ol>
162 // </todo>
163 
165 {
166 public:
167  // Create an object that reads its data from the specified file on disk.
168  // An exception is thrown if the file does not exist or cannot be read.
169  VLADiskInput(const casacore::Path& fileName);
170 
171  // Use this method to attach the VLA online data repository
172  // onlineFlag will typically be "online", but could be "online:-1"
173  // for previous day's file. The VLA online data repository typically
174  // holds 14 days
175  VLADiskInput(const casacore::String &onlineFlag);
176 
177  // The destructor closes the file.
178  virtual ~VLADiskInput();
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();
184 
185  // Returns the number of bytes read so far.
186  virtual casacore::uInt bytesRead();
187 
188  // Returns the size of the file in bytes.
189  virtual casacore::uInt totalBytes();
190 
191 private:
192  //# The default constructor is private and undefined
193  VLADiskInput();
194 
195  //# The copy constructor is private and undefined
196  VLADiskInput(const VLADiskInput& other);
197 
198  //# The assignment operator is private and undefined
199  VLADiskInput& operator=(const VLADiskInput& other);
200 
201  //# Reads through a VLA archive looking for the first physical record in a
202  //# logical record. Returns false if the first record could not be found. If
203  //# It was found then this function also returns the number of physical
204  //# records in this logical record.
206 
207  //# This object that provides the data input.
209 
210  // The following privates are used for accessing the VLA online repository
211  // casacore::Directory containing the visibility data
216 
217  casacore::String getTodaysFile(int relDay=0);
219  void reattachCurrent();
220 };
221 
222 #endif
VLADiskInput & operator=(const VLADiskInput &other)
This class reads VLA archive records from a Tape.
int Int
Definition: aipstype.h:50
This class reads VLA archive records from a Disk file.
Definition: VLADiskInput.h:164
virtual casacore::Bool read()
Reads the next logical record from specified IO source.
casacore::Int whatsToday()
Path name of a file.
Definition: Path.h:126
virtual casacore::uInt bytesRead()
Returns the number of bytes read so far.
short Short
Definition: aipstype.h:48
casacore::Bool onlineFill
The following privates are used for accessing the VLA online repository casacore::Directory containin...
Definition: VLADiskInput.h:212
casacore::String visDir
Definition: VLADiskInput.h:213
casacore::Int previousDay
Definition: VLADiskInput.h:215
virtual casacore::uInt totalBytes()
Returns the size of the file in bytes.
casacore::Bool findFirstRecord(casacore::Short &m)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::RegularFileIO * itsFile
Definition: VLADiskInput.h:208
casacore::Int oldDay
Definition: VLADiskInput.h:214
virtual ~VLADiskInput()
The destructor closes the file.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Class for IO on a regular file.
Definition: RegularFileIO.h:81
void reattachCurrent()
unsigned int uInt
Definition: aipstype.h:51
casacore::String getTodaysFile(int relDay=0)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42