ArrayTimeInterval.h

Go to the documentation of this file.
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 <Long.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 
00058 private:
00059         ArrayTime start;
00060         Interval duration;
00061 
00062 public:
00063 
00064 
00065         // Constructors
00066         ArrayTimeInterval();
00067         ArrayTimeInterval(ArrayTime  start,
00068                                           Interval  duration);
00069                                           
00070         ArrayTimeInterval(double startInMJD,
00071                           double durationInDays);
00072                           
00073         ArrayTimeInterval(int64_t startInNanoSeconds,
00074                           int64_t durationInNanoSeconds);
00075                                           
00076         ArrayTimeInterval(ArrayTime start);
00077         ArrayTimeInterval(double startInMJD);
00078         ArrayTimeInterval(int64_t startInNanoSeconds);
00079         
00080 #ifndef WITHOUT_ACS
00081         ArrayTimeInterval (IDLArrayTimeInterval t); 
00082 #endif  
00083         // Setters
00084         void setStart(ArrayTime start);
00085         void setStart(double start);
00086         void setStart(int64_t start);
00087         
00088         void setDuration(Interval duration);
00089         void setDuration(int64_t nanoSeconds);
00090         void setDuration(double days);
00091                 
00092         // Getters      
00093         ArrayTime getStart() const ;
00094         double getStartInMJD() const ;
00095         int64_t getStartInNanoSeconds() const ;
00096         
00097         Interval getDuration() const ;
00098         int64_t getDurationInNanoSeconds() const ;
00099         double getDurationInDays() const ;
00100         
00101         // Checkers
00102         bool equals(ArrayTimeInterval ati);
00103         bool overlaps(ArrayTimeInterval ati);
00104         bool contains(ArrayTimeInterval ati);
00105         bool contains(ArrayTime at);
00106 
00107         // Operators
00108         bool operator == (ArrayTimeInterval&);
00109         bool operator != (ArrayTimeInterval&);
00110                 
00111 #ifndef WITHOUT_ACS
00112         // To IDL conversion
00113         const asdmIDLTypes::IDLArrayTimeInterval toIDLArrayTimeInterval() const; 
00114 #endif
00115 
00119         void toBin(EndianOSStream& eoss);
00120 
00126         static void toBin(const vector<ArrayTimeInterval>& arrayTimeInterval,  EndianOSStream& eoss);
00127         
00133         static void toBin(const vector<vector<ArrayTimeInterval> >& arrayTimeInterval,  EndianOSStream& eoss);
00134         
00140         static void toBin(const vector<vector<vector<ArrayTimeInterval> > >& arrayTimeInterval,  EndianOSStream& eoss);
00141 
00148         static ArrayTimeInterval fromBin(EndianISStream& eiss);
00149         
00156          static vector<ArrayTimeInterval> from1DBin(EndianISStream & eiss);
00157          
00164          static vector<vector<ArrayTimeInterval> > from2DBin(EndianISStream & eiss);
00165          
00172          static vector<vector<vector<ArrayTimeInterval> > > from3DBin(EndianISStream & eiss);
00173 
00177          string toString() const ;
00178 };
00179 
00180 
00181 // inline constructors
00182 
00183  inline ArrayTimeInterval::ArrayTimeInterval(): start((int64_t)0), duration(0) {}
00184  inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime start_, Interval duration_) {
00185    start = start_;
00186    duration = Interval(min(duration_.get(), Long::MAX_VALUE - start.get()));
00187  }
00188  
00189  inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD, double durationInDays) :
00190    start(startInMJD), 
00191    duration((int64_t) (ArrayTime::unitsInADay * durationInDays)){}
00192  
00193  inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds,
00194                                              int64_t durationInNanoSeconds){
00195    start = startInNanoSeconds;
00196    duration = min(durationInNanoSeconds, Long::MAX_VALUE - startInNanoSeconds);
00197  }                              
00198  
00199  inline ArrayTimeInterval::ArrayTimeInterval(ArrayTime  start_):
00200    start(start_) {
00201    duration = Interval(Long::MAX_VALUE - start.get());
00202  }
00203  
00204  inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD):
00205    start(startInMJD) {
00206    this->duration = Interval(Long::MAX_VALUE - start.get());
00207  }
00208  
00209  inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds):
00210    start(startInNanoSeconds) {
00211    this->duration = Interval(Long::MAX_VALUE - start.get());
00212  }
00213  
00214  // Inline setters
00215  inline void ArrayTimeInterval::setStart(ArrayTime start) {
00216    this->start = ArrayTime(start);
00217  }
00218  
00219  inline void ArrayTimeInterval::setStart(double start) {
00220    this->start = ArrayTime(start);
00221  }
00222  
00223  inline void ArrayTimeInterval::setStart(int64_t start) {
00224    this->start = ArrayTime(start);
00225  }
00226  
00227  inline void ArrayTimeInterval::setDuration(Interval duration) {
00228    this->duration = Interval(duration); 
00229  }
00230  
00231  
00232  inline void ArrayTimeInterval::setDuration(double duration) {
00233    this->duration = Interval((int64_t) (ArrayTime::unitsInADay * duration));
00234  }
00235  
00236  inline void ArrayTimeInterval::setDuration(int64_t duration) {
00237    this->duration = Interval(duration); 
00238  }
00239  
00240  // inline getters
00241  inline ArrayTime ArrayTimeInterval::getStart() const {
00242    return start;        
00243  }
00244  
00245  inline double ArrayTimeInterval::getStartInMJD() const {
00246    return start.getMJD();       
00247  }
00248  
00249  inline int64_t ArrayTimeInterval::getStartInNanoSeconds() const  {
00250    return start.get();  
00251  }
00252  
00253  inline Interval ArrayTimeInterval::getDuration() const {
00254    return duration;     
00255  }
00256  
00257  inline double ArrayTimeInterval::getDurationInDays() const {
00258    return (((double) duration.get()) / ArrayTime::unitsInADay); 
00259  }
00260  
00261  inline int64_t ArrayTimeInterval::getDurationInNanoSeconds() const {
00262    return duration.get();       
00263  }
00264  
00265  // inline checkers
00266  inline bool ArrayTimeInterval::equals(ArrayTimeInterval ati) {
00267    return ((start.get() == ati.getStart().get()) && 
00268            (duration.get() == ati.getDuration().get()));
00269  }
00270  
00271  inline bool ArrayTimeInterval::overlaps(ArrayTimeInterval ati) {
00272    int64_t start1 = start.get();
00273    int64_t end1 = start1 + duration.get();
00274    
00275    
00276    int64_t start2 = ati.getStart().get();
00277    int64_t end2   = start2 + ati.getDuration().get();
00278    
00279    return (start2 <= start1 && end2 >= start1) ||
00280      (start2 >= start1 && start2 <= end1);
00281  }
00282  
00283  inline bool ArrayTimeInterval::contains(ArrayTimeInterval ati) {
00284    int64_t start1 = start.get();;
00285    int64_t end1 = start1 + duration.get();
00286    
00287    int64_t start2 = ati.getStart().get();
00288    int64_t end2   = start2 + ati.getDuration().get();
00289    
00290    return (start2>=start1 && end2<=end1);
00291  }
00292  
00293  inline bool ArrayTimeInterval::contains(ArrayTime ati) {
00294    int64_t start1 = start.get();
00295    int64_t end1 = start1 + duration.get();
00296    
00297    int64_t time = ati.get();
00298    return (time >= start1 && time < end1);
00299  }
00300  
00301  inline bool ArrayTimeInterval::operator == (ArrayTimeInterval &ati){
00302    return (start == ati.start) && (duration == ati.duration);
00303  }
00304  
00305  inline bool ArrayTimeInterval::operator != (ArrayTimeInterval &ati){
00306    return (start != ati.start) || (duration != ati.duration);
00307  }
00308  
00309  inline ostream & operator << ( ostream &o, ArrayTimeInterval &ati ) {
00310    o << "(start=" << ati.getStart().get() << ",duration=" << ati.getDuration().get() << ")";
00311    return o;
00312         
00313  } // End namespace asdm
00314 } // ArrayTimeInterval_CLASS
00315 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines