casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VLADiskInput.h
Go to the documentation of this file.
00001 //# VLADiskInput.h: This class reads VLA archive files from a Disk
00002 //# Copyright (C) 1999,2000
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: VLADiskInput.h,v 19.3.14.1 2006/02/12 05:56:12 wyoung Exp $
00027 
00028 #ifndef NRAO_VLADISKINPUT_H
00029 #define NRAO_VLADISKINPUT_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/IO/RegularFileIO.h>
00033 #include <nrao/VLA/VLAArchiveInput.h>
00034 
00035 #include <casa/namespace.h>
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 class Path;
00038 } //# NAMESPACE CASA - END
00039 
00040 
00041 // <summary>This class reads VLA archive records from a Disk file</summary>
00042 
00043 // <reviewed reviewer="" date="" tests="" demos="">
00044 
00045 // <prerequisite>
00046 // <ol>
00047 //   <li> The IO Module
00048 // </ol>
00049 // </prerequisite>
00050 //
00051 // <etymology>
00052 // This class is designed to reads VLA archive records from a Disk file
00053 // </etymology>
00054 //
00055 // <synopsis> 
00056 
00057 // This class is designed to read VLA archive data.  The data may be read from
00058 // a disk, tape drive or any other data source supported by the IO module.  A
00059 // call to the operator++() function assembles the next reconstructed VLA
00060 // archive data record from the input. A reference to this data can be
00061 // obtained using the logicalRecord function.
00062 //
00063 // Refer to the "VLA Archive Data Format", VLA Computer Memorandum 186
00064 // by G.C. Hunt, K.P. Sowinski, and T.J. Bottomly; June 1993.
00065 // (This is also available as AIPS++ note 159)
00066 //
00067 // The VLA archive records are always a multiple of 2048 bytes.  The
00068 // record sizes were designed for use with magnetic tapes, so there is
00069 // a maximum physical record size of 13*2048=26624 bytes.
00070 //
00071 // The low level class (blockio), that actually does the I/O, allows
00072 // for a record (hereinafter chunk) size and for a input block size of
00073 // a multiple of the chunk size.  The low level read operation tests
00074 // for the number of bytes actually read from the device.
00075 //
00076 // The helper classes VlaDiskInput, VlaTapeInput, and VlaStdInput are
00077 // designed to deal with the low level input from the devices in an
00078 // analogous fashion to the ones used for FITS input.
00079 //
00080 // Since a read may be issued for an arbitrary number of bytes from a
00081 // disk, the chunk multiple is arbitrary and may be used to tune the
00082 // speed of operation.  There is an obvious trade-off between the
00083 // block size created in the blockio class and the number of read
00084 // operations.
00085 //
00086 // The story is quite different for tape input.  A read request for at
00087 // least the maximum physical record size must be made to avoid loss of
00088 // data.  Since a single tape record will be read with a single read
00089 // operation, there is no point is having it any larger.  The chunk
00090 // multiple must be exactly 13 so that the block size is 26624.
00091 //
00092 // The reconstitution algorithm is as follows:
00093 //
00094 // 1. Read a 2048 chunk from the input.
00095 //
00096 // The first two 16-bit integers should contain the values 1 and n,
00097 // where n is the number of "physical records" in the current "logical  
00098 // record."  (If the first value is not 1, then the chunk is rejected
00099 // and a new one read until the first 16-bit value is 1.)  These two
00100 // values are not part of the reconstituted "logical record."
00101 //
00102 // 2. The next 32-bit integer contains the length of the "logical
00103 // record" in 16-bit words.  The buffer is resized so that it can
00104 // contain the whole reconstituted "logical record."
00105 //
00106 // 3. The remainder of the chunk is copied to the buffer.
00107 //
00108 // 4. Successive chunks are read from the input.
00109 //
00110 // The chunks are copied into the buffer until the "logical record"
00111 // is complete.  For "logical records" longer than 26620 byte, this is
00112 // not the whole story.  Each "physical record" contains maximum of 13
00113 // chunks.  When the first "physical record" of 13 chunks has been read,
00114 // the next chunk will be the first of the next "physical record."  The
00115 // first two 16-bit integers will now be 2 and n, to indicate that this
00116 // is the second "physical record" of the sequence.  These 4 bytes are
00117 // decoded and the rest of this chunk is copied to the buffer.  And so
00118 // on...
00119 //
00120 // An end-of-file condition on the input will cause record processing
00121 // to be declared complete.  
00122 // </synopsis> 
00123 //
00124 // <example>
00125 // To open and read a VLA archive data file
00126 // <code>
00127 //    VLAArchiveInput *in;
00128 //    Block <Char> *buff;
00129 //    String fileName = " ";
00130 //    String fileType = "tape";
00131 //
00132 //    if (fileType == String("tape")) {
00133 //        in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Tape);
00134 //    } else {
00135 //        in = new VLAArchiveInput(fileName.chars(), VLAArchiveInput::Disk);
00136 //    }
00137 //
00138 //    uInt record = 0;
00139 //    for (buff=&(in->next()); in->atEnd()==False; buff=&(in->next()), record++) {
00140 //        cout << "Record" << record << endl;
00141 //        // process record pointed to by buff
00142 //    }
00143 // </code>
00144 //
00145 // </example>
00146 //
00147 // <motivation>
00148 // </motivation>
00149 //
00150 // <todo asof="">
00151 // <ol>
00152 //   <li> Bulletproofing - check for realistic buffer size (<1e6)
00153 //   <li> Bulletproofing - check newn and newm on each read
00154 //   <li> What happens after a single end-of-file on a tape drive?
00155 //   <li> Add record skipping
00156 //   <li> Should it work with stdin?  This is in place but not debugged.
00157 // </ol>
00158 // </todo>
00159 
00160 class VLADiskInput: public VLAArchiveInput
00161 {
00162 public: 
00163   // Create an object that reads its data from the specified file on disk.
00164   // An exception is thrown if the file does not exist or cannot be read.
00165   VLADiskInput(const Path& fileName);
00166 
00167   // Use this method to attach the VLA online data repository
00168   // onlineFlag will typically be "online", but could be "online:-1"
00169   // for previous day's file.  The VLA online data repository typically
00170   // holds 14 days
00171   VLADiskInput(const String &onlineFlag);
00172     
00173   // The destructor closes the file.
00174   virtual ~VLADiskInput();
00175 
00176   // Reads the next logical record from specified IO source. Returns False if
00177   // there was a problem assembling the next record ie., it returns the value
00178   // of the hasData() member function.
00179   virtual Bool read();
00180 
00181   // Returns the number of bytes read so far.
00182   virtual uInt bytesRead();
00183 
00184   // Returns the size of the file in bytes.
00185   virtual uInt totalBytes();
00186   
00187 private: 
00188   //# The default constructor is private and undefined
00189   VLADiskInput();
00190     
00191   //# The copy constructor is private and undefined
00192   VLADiskInput(const VLADiskInput& other);
00193 
00194   //# The assignment operator is private and undefined
00195   VLADiskInput& operator=(const VLADiskInput& other);
00196 
00197   //# Reads through a VLA archive looking for the first physical record in a
00198   //# logical record. Returns False if the first record could not be found. If
00199   //# It was found then this function also returns the number of physical
00200   //# records in this logical record.
00201   Bool findFirstRecord(Short& m);
00202 
00203   //# This object that provides the data input.
00204   RegularFileIO *itsFile;
00205 
00206   // The following privates are used for accessing the VLA online repository
00207   // Directory containing the visibility data
00208   Bool   onlineFill;
00209   String visDir; 
00210   Int oldDay;
00211   Int previousDay;
00212 
00213   String getTodaysFile(int relDay=0);
00214   Int whatsToday();
00215   void reattachCurrent();
00216 };
00217 
00218 #endif