casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SDDFile.h
Go to the documentation of this file.
00001 //# SDDFile.h: a class for accessing unipops SDD data files
00002 //# Copyright (C) 1999,2001
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 //#
00027 //# $Id$
00028 
00029 #ifndef NRAO_SDDFILE_H
00030 #define NRAO_SDDFILE_H
00031 
00032 //#! Includes go here
00033 #include <casa/aips.h>
00034 #include <nrao/SDD/SDDIndex.h>
00035 #include <casa/Containers/Block.h>
00036 #include <casa/Utilities/CountedPtr.h>
00037 #include <casa/Arrays/Vector.h>
00038 
00039 #include <casa/namespace.h>
00040 //# Forward declarations
00041 namespace casa { //# NAMESPACE CASA - BEGIN
00042 class String;
00043 } //# NAMESPACE CASA - END
00044 
00045 class SDDBootStrap;
00046 class SDDHeader;
00047 
00048 #include <casa/iosfwd.h>
00049 
00050 #include <casa/namespace.h>
00051 // <summary>
00052 // a class for accessing unipops SDD data files
00053 // </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00058 // </reviewed>
00059 
00060 // <prerequisite>
00061 //   <li> SDDFile
00062 //   <li> SDDIndex
00063 //   <li> SDDHeader
00064 // </prerequisite>
00065 //
00066 // <etymology>
00067 // </etymology>
00068 //
00069 // <synopsis>
00070 // </synopsis>
00071 //
00072 // <example>
00073 // </example>
00074 //
00075 // <motivation>
00076 // </motivation>
00077 //
00078 
00079 class SDDFile {
00080 public:
00081     // These file options are straight out of Table.  They
00082     // should be made more general.
00083     enum FileOption {Old=1,                 // existing table
00084                      New,                   // create table
00085                      NewNoReplace,          // create table (may not exist)
00086                      Scratch,               // scratch table
00087                      Update,                // update existing table
00088                      Delete};               // delete table
00089 
00090 
00091     // creates the parts, but nothing is attached to any file
00092     SDDFile();
00093     // open the indicated file, with the indicated options
00094     SDDFile(const String& fileName, FileOption option = Old);
00095     // Copy constructor
00096     SDDFile(const SDDFile& other);
00097 
00098     ~SDDFile();
00099 
00100     // assignment operator
00101     SDDFile& operator=(const SDDFile& other);
00102 
00103     // attach to a file
00104     void attach(const String& fileName, FileOption option = Old);
00105 
00106     // return a reference to the BootStrap
00107     SDDBootStrap& bootStrap() {return *boot_p;}
00108 
00109     // return a reference to the Index
00110     const SDDIndex& index() const {return *index_p;}
00111     SDDIndex& index() {return *index_p;}
00112 
00113     const SDDIndexRep& index(uInt entry) const 
00114     {return (*index_p)(entry); }
00115     SDDIndexRep& index(uInt entry) {return (*index_p)(entry); }
00116 
00117     // the number of vectors at a specific entry
00118     uInt nvectors(uInt entry) const { return nvectors_p[entry]; }
00119 
00120     // check if a specific index entry is in use
00121     Bool inUse(uInt entry) const { return ( index_p->inUse(entry)); }
00122 
00123     // return a reference to the Header at location i
00124     SDDHeader& header(uInt location);
00125 
00126     // get the data vector at the indicated location in the index
00127     // If there is more than one vector at that location (for OTF and PZ
00128     // data at the 12m), get the one indicated.  If the arguments are 
00129     // invalid, getData returns False and does NOT alter the array argument
00130     Bool getData(Array<Float>& data, uInt location, uInt which=0);
00131 
00132     // The following are specific to OTF data
00133     // they are the single values appropriate for a given location and vector
00134     // for non-OTF rows, these return 0 for the offsets (time, raOffset, decOffset),
00135     // and the header values for az and el
00136     Float time(uInt location, uInt which);
00137     Float raOffset(uInt location, uInt which);
00138     Float decOffset(uInt location, uInt which);
00139     Float az(uInt location, uInt which);
00140     Float el(uInt location, uInt which);
00141 
00142     // return a reference to the header/data corresponding to scan & subscan
00143     SDDHeader& header(uInt scan, uInt subscan);
00144 
00145     // update the bootstrap and index if the file on disk has changed
00146     // this also needs to reset the rowMap and make sure the "current" values
00147     // point at appropriate things.  If the "current" values are no longer
00148     // available, reset to the first thing that is available.
00149     // The return values are the same as the SDDIndex functions they use
00150     Bool fullUpdate();
00151     Bool incrementalUpdate();
00152 
00153 private:
00154     SDDBootStrap* boot_p;
00155     SDDIndex* index_p;
00156     SDDHeader* header_p;
00157 
00158     Vector<Float> data_p;
00159 
00160     Double cosdec_p;
00161     Vector<Float> time_p;
00162     Vector<Float> raOffset_p;
00163     Vector<Float> decOffset_p;
00164     Vector<Float> az_p;
00165     Vector<Float> el_p;
00166 
00167     CountedPtr<fstream> file_p;
00168 
00169     // The cache of number of vectors per entry
00170     Block<uInt> nvectors_p;
00171 
00172     // For all of the current pointers, if < 0 they point at nothing valid
00173     // It is always true that the header and various data vectors are always from
00174     // the same location, only the row number may vary.
00175     // the current index entry location loaded here for the header and OTF data
00176     Int currentHeader_p;
00177     // This is the offset into this location that corresponds to this row
00178     Int currentOffset_p;
00179 
00180     FileOption option_p;
00181     String* fileName_p;
00182 
00183     void seek(uInt record=0);
00184 
00185     uInt fileMode(FileOption option) const;
00186 
00187     void loadLocation(uInt location);
00188     void resetCache();
00189     void init_nvectors();
00190 };
00191 
00192 #endif