casa
$Rev:20696$
|
00001 //# GBTScanLogReader: GBTScanLogReader reads and iterates through a GBT ScanLog 00002 //# Copyright (C) 1999,2000,2001,2002,2003 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_GBTSCANLOGREADER_H 00030 #define NRAO_GBTSCANLOGREADER_H 00031 00032 #include <casa/Arrays/Vector.h> 00033 #include <casa/Containers/Block.h> 00034 #include <casa/Containers/RecordField.h> 00035 #include <nrao/FITS/GBTStateTable.h> 00036 #include <fits/FITS/FITSTable.h> 00037 #include <casa/BasicSL/Constants.h> 00038 #include <casa/OS/File.h> 00039 #include <casa/Quanta/MVTime.h> 00040 #include <tables/Tables/Table.h> 00041 #include <casa/BasicSL/String.h> 00042 00043 #include <nrao/FITS/GBTGOFile.h> 00044 #include <nrao/FITS/GBTLO1File.h> 00045 00046 #include <casa/namespace.h> 00047 //# Forward Declarations 00048 namespace casa { //# NAMESPACE CASA - BEGIN 00049 class Record; 00050 } //# NAMESPACE CASA - END 00051 00052 00053 // <summary> 00054 // </summary> 00055 00056 // <use visibility=local> 00057 00058 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00059 // </reviewed> 00060 00061 // <prerequisite> 00062 // <li> SomeClass 00063 // <li> SomeOtherClass 00064 // <li> some concept 00065 // </prerequisite> 00066 // 00067 // <etymology> 00068 // </etymology> 00069 // 00070 // <synopsis> 00071 // </synopsis> 00072 // 00073 // <example> 00074 // </example> 00075 // 00076 // <motivation> 00077 // </motivation> 00078 // 00079 // <thrown> 00080 // <li> 00081 // <li> 00082 // </thrown> 00083 // 00084 // <todo asof="yyyy/mm/dd"> 00085 // <li> add this feature 00086 // <li> fix this bug 00087 // <li> start discussion of this possible extension 00088 // </todo> 00089 00090 class GBTScanLogReader 00091 { 00092 public: 00093 // the types of backends 00094 enum BACKENDS {ANY=0, DCR, HOLOGRAPHY, SP, ACS, 00095 UNKNOWN, NUM_BACKENDS=UNKNOWN}; 00096 00097 // construct this using the indicated ScanLog FITS file 00098 GBTScanLogReader(const File& scanlog, Int minscan=-1, 00099 Int maxscan=LONG_MAX); 00100 00101 ~GBTScanLogReader(); 00102 00103 // inquire about the health of the underling table 00104 Bool isValid() {return scanLog_p.isValid();} 00105 00106 // reopen using the given file. If scanlog is the same 00107 // file then it will be repositioned at the same current 00108 // position (same scan) as it currently is if keepPosition 00109 // is True. This assumes that nothing in the scanlog has 00110 // changed up until that point. If scanlog is a different 00111 // file or if keepPosition is False, then this resets 00112 // everything to the state it would have been immediately 00113 // after construction using the given scanlog. 00114 Bool reopen(const File &scanlog, Bool keepPosition=True); 00115 00116 // reopen using the same file 00117 Bool reopen(Bool keepPosition=True); 00118 00119 // Toggle the emission of warning messages. This object starts 00120 // off initially being silent (no warning messages) 00121 // regarding missing files or scans without backends. 00122 // This is desirable so that warnings aren't issued until 00123 // real data is seen to arrive and a fill is started. 00124 void warn(Bool dowarn = True) {dowarn_p = dowarn;} 00125 00126 // move the pointer to the next group in the log. 00127 // When next has been called and the file is at the end, the 00128 // scan number will be < 0 00129 void next(); 00130 00131 // the current scan number, this will be negative if 00132 // the file is empty 00133 Int scan() const {return scan_p;} 00134 00135 // the indicated DMJD 00136 const MVTime &dmjd() const {return dmjd_p;} 00137 00138 // The timestamp from the file names (uses the backend file 00139 // file name, which should be consistent with the others, although 00140 // there is no consistency check here). 00141 const MVTime &timeStamp() const {return timeStamp_p;} 00142 00143 // return the next time stamp 00144 const MVTime &nextTimeStamp() const { return nextTimeStamp_p;} 00145 00146 //# update the pointer to re-read the same scan log 00147 //# not yet implemented 00148 //# void update(); 00149 00150 // are there more groups (T) or is this pointed at the end (F) 00151 Bool more() const {return nextScan_p >= 0;} 00152 00153 // return the name of the DCR backend FITS file in this scan 00154 // This string has zero length if there is no DCR data in 00155 // this scan. There should never be more than one DCR 00156 // file in a scan but if there is, a warning is issued and 00157 // the last one seen is used. 00158 const String &dcrfile() const {return itsDCRFile;} 00159 00160 // return the name of the HOLO backend FITS file in this scan 00161 // This string has zero length if there is no HOLO data in 00162 // this scan. There should never be more than one HOLO 00163 // file in a scan but if there is, a warning is issued and 00164 // the last one seen is used. 00165 const String &holofile() const {return itsHOLOFile;} 00166 00167 // return the name of the SP backend FITS file in this scan 00168 // This string has zero length if there is no SP data in 00169 // this scan. There should never be more than one SP 00170 // file in a scan but if there is, a warning is issued and 00171 // the last one seen is used. 00172 const String &spfile() const {return itsSPFile;} 00173 00174 // return the names of the ACS backend FITS file in this scan 00175 // This vector has zero elements if there are no ACS files 00176 // in thie scan. 00177 const Vector<String> &acsfiles() const {return itsACSFiles;} 00178 00179 // return the list of backend types in this group 00180 const Block<Int>& backends() const {return backends_p;} 00181 00182 // The names of the current backend files 00183 const Block<String>& backendFiles() const {return backendFiles_p;} 00184 00185 // The names of all of the current DAP files 00186 const Block<String>& dapFiles() const {return dapFiles_p;} 00187 00188 // The name of the IF manager file - there should only be one in a scan. 00189 // When more than one is seen, the first seen is used and a warning 00190 // message is sent to the logger. If no IF manager file is present in 00191 // the scan, this string will be empty. 00192 const String &ifManagerFile() const {return ifManagerFile_p;} 00193 00194 // The GBTGOFile from the FITS file written by the user interface - there should 00195 // be only one in a scan. When more than one is seen, the first is used 00196 // and a warning message is sent to the logger. If no user FITS file is 00197 // present in the scan, this GBTGOFile will not be attached. 00198 const GBTGOFile &GOFile() const {if (!goFileSet_p) attachGO(); return goFile_p;} 00199 00200 // The GBTLO1File for LO1A. There should be only one in a scan. When more 00201 // than one is seen, the first is used and a warning message is sent to the 00202 // logger. If no LO1A file is seen, then this GBTLO1File will not be attached. 00203 const GBTLO1File &LO1A() const {if (!lo1Aset_p) attachLO1A(); return itsLO1A_p;} 00204 00205 // The GBTLO1File for LO1B. There should be only one in a scan. When more 00206 // than one is seen, the first is used and a warning message is sent to the 00207 // logger. If no LO1B is seen, then this GBTLO1File will not be attached. 00208 const GBTLO1File &LO1B() const {if (!lo1Bset_p) attachLO1B(); return itsLO1B_p;} 00209 00210 // The name of the Antenna FITS file - there should be only one in a scan. 00211 // When more than one is seen, the first seen is used and a warning message 00212 // is sent to the logger. If no Antenna file is present in the scan, 00213 // this string will be empty. 00214 const String &antennaFile() const {return antennaFile_p;} 00215 00216 // The names of any RX_CAL_INFO files 00217 const Block<String> &rxCalInfoFiles() const {return rxCalFiles_p;} 00218 00219 // The master state table as indicated by the state files in the backend 00220 // files. The first state file found indicating where the master is 00221 // will be believed. If no master is indicated, this table will be null. 00222 const GBTStateTable &masterState() const {if (!masterStateSet_p) attachMasterState(); return state_p;} 00223 00224 // The name of the backend file from which the master state came. 00225 const String &masterStateBackend() const { if (!masterStateSet_p) attachMasterState(); return stateName_p;} 00226 00227 // return the names of all of the files associated with this scan 00228 const Block<String> &allFiles() const {if (!lo1Bchecked_p) checkLO1Bname(); return allFiles_p;} 00229 00230 // return the current minimum scan number 00231 Int minscan() const { return minScan_p;} 00232 00233 // set the minimum scan number 00234 void setMinscan(Int minscan) { minScan_p = minscan; doScanCheck();} 00235 00236 // return the current maximum scan number 00237 Int maxscan() const { return maxScan_p;} 00238 00239 // set the maximum scan number 00240 void setMaxscan(Int maxscan) 00241 { maxScan_p = maxscan; if (maxScan_p<0) maxScan_p = LONG_MAX; doScanCheck();} 00242 00243 // recheck and possible reset the current scan to ensure it lies between minscan 00244 // and maxscan. Necessary because setting minscan and maxscan involves two calls. 00245 // This should be done after min and max scan have been set. 00246 void checkScanNumber() {while (scan()>=0 && (scan() < minscan() || scan() > maxscan())) next();} 00247 00248 // translate a string into a backend type 00249 static GBTScanLogReader::BACKENDS type(const String &name); 00250 00251 // translate a type into a name, all lower case 00252 static String name(const GBTScanLogReader::BACKENDS type); 00253 00254 // return the primary keywords associated with the underlying FITSTable 00255 const TableRecord &primaryKeywords() { return scanLog_p.primaryKeywords();} 00256 00257 // return the STARTING line for this scan 00258 const String &starting() { return startingLine_p;} 00259 00260 // return the FINISHED line for this scan 00261 const String &finished() { return finishedLine_p;} 00262 00263 private: 00264 File scanLogFile_p; 00265 String rootdir_p; 00266 00267 FITSTable scanLog_p; 00268 MVTime dmjd_p, nextDmjd_p, workingDmjd_p, 00269 timeStamp_p, nextTimeStamp_p; 00270 Int scan_p, nextScan_p, workingScan_p, minScan_p, maxScan_p; 00271 00272 Block<Int> backends_p, nextBackends_p, workingBackends_p; 00273 Block<String> backendFiles_p, nextBackendFiles_p, workingBackendFiles_p, 00274 dapFiles_p, nextDapFiles_p, workingDapFiles_p; 00275 00276 Block<String> rxCalFiles_p, nextRxCalFiles_p, workingRxCalFiles_p; 00277 00278 String itsDCRFile, itsHOLOFile, itsSPFile, itsNextDCRFile, 00279 itsNextHOLOFile, itsNextSPFile; 00280 00281 Vector<String> itsACSFiles, itsNextACSFiles; 00282 00283 mutable Block<String> allFiles_p; 00284 Block<String> nextAllFiles_p; 00285 00286 // these counts apply only to the working* blocks. 00287 Int backendCount_p, dapCount_p, rxCalCount_p; 00288 00289 Bool dowarn_p; 00290 00291 // the rownr corresponding to the start of this scan 00292 // -1 if nothing started yet 00293 Int thisStartRow_p; 00294 // the rownr corresponding to the start of the next scan 00295 // -1 if nothing started yet 00296 Int nextStartRow_p; 00297 00298 Record *currow_p; 00299 RecordFieldPtr<Double> dmjdField_p; 00300 RecordFieldPtr<Int> scanField_p; 00301 RecordFieldPtr<String> filePathField_p; 00302 RecordFieldPtr<String> dateObsField_p; 00303 00304 String ifManagerFile_p, nextIFManagerFile_p, 00305 antennaFile_p, nextAntennaFile_p; 00306 00307 String startingLine_p, nextStartingLine_p; 00308 String finishedLine_p, nextFinishedLine_p; 00309 00310 mutable GBTStateTable state_p; 00311 mutable Bool masterStateSet_p; 00312 mutable String stateName_p; 00313 00314 mutable GBTGOFile goFile_p; 00315 String goFileName_p, nextGoFileName_p; 00316 mutable Bool goFileSet_p; 00317 00318 mutable GBTLO1File itsLO1A_p, itsLO1B_p; 00319 String lo1Aname_p, nextLO1Aname_p, nextLO1Bname_p; 00320 mutable Bool lo1Aset_p, lo1Bset_p, lo1Bchecked_p; 00321 mutable String lo1Bname_p; 00322 00323 Int itsBaseVer, itsDeviceVer; 00324 00325 // initialize things after scanLog_p exists 00326 Bool init(Int startrow=0); 00327 00328 // this is the thing which actually fills out all of the information 00329 void digestScan(); 00330 00331 // set the state table given a file name 00332 void setStateTable(const String &fileName) const; 00333 00334 // ensure that minScan_p <= maxScan_p 00335 void doScanCheck(); 00336 00337 // attach the GO file - only done as needed 00338 void attachGO() const; 00339 00340 // attach the LO1A file - only done as needed 00341 void attachLO1A() const; 00342 00343 // attach the LO1B file - only done as needed 00344 void attachLO1B() const; 00345 00346 // check for the existance of an un-named LO1B file 00347 void checkLO1Bname() const; 00348 00349 // attach master state table - only done as needed 00350 void attachMasterState() const; 00351 00352 // unset and unavailable 00353 GBTScanLogReader(); 00354 GBTScanLogReader(const GBTScanLogReader &); 00355 GBTScanLogReader &operator=(const GBTScanLogReader &); 00356 }; 00357 00358 #endif 00359 00360