casa
$Rev:20696$
|
00001 /* 00002 * ALMA - Atacama Large Millimeter Array 00003 * (c) European Southern Observatory, 2002 00004 * (c) Associated Universities Inc., 2002 00005 * Copyright by ESO (in the framework of the ALMA collaboration), 00006 * Copyright by AUI (in the framework of the ALMA collaboration), 00007 * All rights reserved. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free software Foundation; either 00012 * version 2.1 of the License, or (at your option) any later version. 00013 * 00014 * This library is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00022 * MA 02111-1307 USA 00023 * 00024 * File ArrayTimeInterval.h 00025 */ 00026 00027 #ifndef ArrayTimeInterval_CLASS 00028 #define ArrayTimeInterval_CLASS 00029 00030 #include <stdint.h> 00031 #include <LongWrapper.h> 00032 #include <ArrayTime.h> 00033 #include <Interval.h> 00034 00035 #ifndef WITHOUT_ACS 00036 #include <asdmIDLTypesC.h> 00037 #endif 00038 00039 using asdm::Long; 00040 using asdm::Interval; 00041 using asdm::ArrayTime; 00042 00043 #ifndef WITHOUT_ACS 00044 using asdmIDLTypes::IDLArrayTimeInterval; 00045 #endif 00046 00047 namespace asdm { 00048 00055 class ArrayTimeInterval { 00056 friend ostream & operator << ( ostream &, ArrayTimeInterval& ); 00057 friend istream & operator >> ( istream &, ArrayTimeInterval& ); 00058 private: 00059 00060 ArrayTime start; 00061 Interval duration; 00062 00063 static bool readStartTimeDurationInBin_; 00064 static bool readStartTimeDurationInXML_; 00065 00066 public: 00067 00068 00069 // Constructors 00070 ArrayTimeInterval(); 00071 ArrayTimeInterval(ArrayTime start, 00072 Interval duration); 00073 00074 ArrayTimeInterval(double startInMJD, 00075 double durationInDays); 00076 00077 ArrayTimeInterval(int64_t startInNanoSeconds, 00078 int64_t durationInNanoSeconds); 00079 00080 ArrayTimeInterval(ArrayTime start); 00081 ArrayTimeInterval(double startInMJD); 00082 ArrayTimeInterval(int64_t startInNanoSeconds); 00083 00084 #ifndef WITHOUT_ACS 00085 ArrayTimeInterval (IDLArrayTimeInterval t); 00086 #endif 00087 // Setters 00088 void setStart(ArrayTime start); 00089 void setStart(double start); 00090 void setStart(int64_t start); 00091 00092 void setDuration(Interval duration); 00093 void setDuration(int64_t nanoSeconds); 00094 void setDuration(double days); 00095 00096 // Getters 00097 ArrayTime getStart() const ; 00098 ArrayTime getMidPoint() const ; 00099 double getStartInMJD() const ; 00100 int64_t getStartInNanoSeconds() const ; 00101 00102 Interval getDuration() const ; 00103 int64_t getDurationInNanoSeconds() const ; 00104 double getDurationInDays() const ; 00105 00106 // Checkers 00107 bool equals(ArrayTimeInterval ati); 00108 bool overlaps(ArrayTimeInterval ati); 00109 bool contains(ArrayTimeInterval ati); 00110 bool contains(ArrayTime at); 00111 00112 // Operators 00113 bool operator == (ArrayTimeInterval&); 00114 bool operator != (ArrayTimeInterval&); 00115 00116 #ifndef WITHOUT_ACS 00117 // To IDL conversion 00118 const asdmIDLTypes::IDLArrayTimeInterval toIDLArrayTimeInterval() const; 00119 #endif 00120 00128 static void readStartTimeDurationInBin(bool b); 00129 00136 static bool readStartTimeDurationInBin(); 00137 00146 static void readStartTimeDurationInXML(bool b); 00147 00154 static bool readStartTimeDurationInXML(); 00155 00160 void toBin(EndianOSStream& eoss) const ; 00161 00167 static void toBin(const vector<ArrayTimeInterval>& arrayTimeInterval, EndianOSStream& eoss); 00168 00174 static void toBin(const vector<vector<ArrayTimeInterval> >& arrayTimeInterval, EndianOSStream& eoss); 00175 00181 static void toBin(const vector<vector<vector<ArrayTimeInterval> > >& arrayTimeInterval, EndianOSStream& eoss); 00182 00189 static ArrayTimeInterval fromBin(EndianIStream& eis); 00190 00197 static vector<ArrayTimeInterval> from1DBin(EndianIStream & eis); 00198 00205 static vector<vector<ArrayTimeInterval> > from2DBin(EndianIStream & eis); 00206 00213 static vector<vector<vector<ArrayTimeInterval> > > from3DBin(EndianIStream & eis); 00214 00218 string toString() const ; 00219 }; 00220 00221 00222 // inline constructors 00223 00224 inline ArrayTimeInterval::ArrayTimeInterval(): start((int64_t)0), duration(0) {} 00225 inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime start_, Interval duration_) { 00226 start = start_; 00227 duration = Interval(min(duration_.get(), Long::MAX_VALUE - start.get())); 00228 } 00229 00230 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD, double durationInDays) : 00231 start(startInMJD), 00232 duration((int64_t) (ArrayTime::unitsInADay * durationInDays)){} 00233 00234 inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds, 00235 int64_t durationInNanoSeconds){ 00236 start = startInNanoSeconds; 00237 duration = min(durationInNanoSeconds, Long::MAX_VALUE - startInNanoSeconds); 00238 } 00239 00240 inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime start_): 00241 start(start_) { 00242 duration = Interval(Long::MAX_VALUE - start.get()); 00243 } 00244 00245 inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD): 00246 start(startInMJD) { 00247 this->duration = Interval(Long::MAX_VALUE - start.get()); 00248 } 00249 00250 inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds): 00251 start(startInNanoSeconds) { 00252 this->duration = Interval(Long::MAX_VALUE - start.get()); 00253 } 00254 00255 // Inline setters 00256 inline void ArrayTimeInterval::setStart(ArrayTime start) { 00257 this->start = ArrayTime(start); 00258 } 00259 00260 inline void ArrayTimeInterval::setStart(double start) { 00261 this->start = ArrayTime(start); 00262 } 00263 00264 inline void ArrayTimeInterval::setStart(int64_t start) { 00265 this->start = ArrayTime(start); 00266 } 00267 00268 inline void ArrayTimeInterval::setDuration(Interval duration) { 00269 this->duration = Interval(duration); 00270 } 00271 00272 00273 inline void ArrayTimeInterval::setDuration(double duration) { 00274 this->duration = Interval((int64_t) (ArrayTime::unitsInADay * duration)); 00275 } 00276 00277 inline void ArrayTimeInterval::setDuration(int64_t duration) { 00278 this->duration = Interval(duration); 00279 } 00280 00281 // inline getters 00282 inline ArrayTime ArrayTimeInterval::getStart() const { 00283 return start; 00284 } 00285 00286 inline ArrayTime ArrayTimeInterval::getMidPoint() const { 00287 return ArrayTime(start.get() + duration.get() / 2); 00288 } 00289 00290 inline double ArrayTimeInterval::getStartInMJD() const { 00291 return start.getMJD(); 00292 } 00293 00294 inline int64_t ArrayTimeInterval::getStartInNanoSeconds() const { 00295 return start.get(); 00296 } 00297 00298 inline Interval ArrayTimeInterval::getDuration() const { 00299 return duration; 00300 } 00301 00302 inline double ArrayTimeInterval::getDurationInDays() const { 00303 return (((double) duration.get()) / ArrayTime::unitsInADay); 00304 } 00305 00306 inline int64_t ArrayTimeInterval::getDurationInNanoSeconds() const { 00307 return duration.get(); 00308 } 00309 00310 // inline checkers 00311 inline bool ArrayTimeInterval::equals(ArrayTimeInterval ati) { 00312 return ((start.get() == ati.getStart().get()) && 00313 (duration.get() == ati.getDuration().get())); 00314 } 00315 00316 inline bool ArrayTimeInterval::overlaps(ArrayTimeInterval ati) { 00317 int64_t start1 = start.get(); 00318 int64_t end1 = start1 + duration.get(); 00319 00320 00321 int64_t start2 = ati.getStart().get(); 00322 int64_t end2 = start2 + ati.getDuration().get(); 00323 00324 return (start2 <= start1 && end2 >= start1) || 00325 (start2 >= start1 && start2 <= end1); 00326 } 00327 00328 inline bool ArrayTimeInterval::contains(ArrayTimeInterval ati) { 00329 int64_t start1 = start.get();; 00330 int64_t end1 = start1 + duration.get(); 00331 00332 int64_t start2 = ati.getStart().get(); 00333 int64_t end2 = start2 + ati.getDuration().get(); 00334 00335 return (start2>=start1 && end2<=end1); 00336 } 00337 00338 inline bool ArrayTimeInterval::contains(ArrayTime ati) { 00339 int64_t start1 = start.get(); 00340 int64_t end1 = start1 + duration.get(); 00341 00342 int64_t time = ati.get(); 00343 return (time >= start1 && time < end1); 00344 } 00345 00346 inline bool ArrayTimeInterval::operator == (ArrayTimeInterval &ati){ 00347 return (start == ati.start) && (duration == ati.duration); 00348 } 00349 00350 inline bool ArrayTimeInterval::operator != (ArrayTimeInterval &ati){ 00351 return (start != ati.start) || (duration != ati.duration); 00352 } 00353 00354 inline ostream & operator << ( ostream &o, ArrayTimeInterval &ati ) { 00355 o << "(start=" << ati.getStart().get() << ",duration=" << ati.getDuration().get() << ")"; 00356 return o; 00357 } 00358 00359 inline istream & operator >> ( istream &i, ArrayTimeInterval &ati) { 00360 i >> ati.start; 00361 i >> ati.duration; 00362 return i; 00363 } 00364 } // End namespace asdm 00365 #endif // ArrayTimeInterval_CLASS