casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayTimeInterval.h
Go to the documentation of this file.
1 /*
2  * ALMA - Atacama Large Millimeter Array
3  * (c) European Southern Observatory, 2002
4  * (c) Associated Universities Inc., 2002
5  * Copyright by ESO (in the framework of the ALMA collaboration),
6  * Copyright by AUI (in the framework of the ALMA collaboration),
7  * All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY, without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  *
24  * File ArrayTimeInterval.h
25  */
26 
27 #ifndef ArrayTimeInterval_CLASS
28 #define ArrayTimeInterval_CLASS
29 
30 #include <stdint.h>
31 #include <alma/ASDM/LongWrapper.h>
32 #include <alma/ASDM/ArrayTime.h>
33 #include <alma/ASDM/Interval.h>
34 
35 #ifndef WITHOUT_ACS
36 #include <asdmIDLTypesC.h>
37 #endif
38 
39 namespace asdm {
40 
48  friend std::ostream & operator << ( std::ostream &, ArrayTimeInterval& );
49  friend std::istream & operator >> ( std::istream &, ArrayTimeInterval& );
50  private:
51 
54 
57 
58  public:
59 
60 
61  // Constructors
65 
66  ArrayTimeInterval(double startInMJD,
67  double durationInDays);
68 
69  ArrayTimeInterval(int64_t startInNanoSeconds,
70  int64_t durationInNanoSeconds);
71 
73  ArrayTimeInterval(double startInMJD);
74  ArrayTimeInterval(int64_t startInNanoSeconds);
75 
76 #ifndef WITHOUT_ACS
77  ArrayTimeInterval (asdmIDLTypes::IDLArrayTimeInterval t);
78 #endif
79  // Setters
80  void setStart(ArrayTime start);
81  void setStart(double start);
82  void setStart(int64_t start);
83 
85  void setDuration(int64_t nanoSeconds);
86  void setDuration(double days);
87 
88  // Getters
89  ArrayTime getStart() const ;
90  ArrayTime getMidPoint() const ;
91  double getStartInMJD() const ;
92  int64_t getStartInNanoSeconds() const ;
93 
94  Interval getDuration() const ;
95  int64_t getDurationInNanoSeconds() const ;
96  double getDurationInDays() const ;
97 
98  // Checkers
99  bool equals(ArrayTimeInterval ati);
100  bool overlaps(ArrayTimeInterval ati);
101  bool contains(ArrayTimeInterval ati);
102  bool contains(ArrayTime at);
103 
104  // Operators
107 
108 #ifndef WITHOUT_ACS
109  // To IDL conversion
110  const asdmIDLTypes::IDLArrayTimeInterval toIDLArrayTimeInterval() const;
111 #endif
112 
120  static void readStartTimeDurationInBin(bool b);
121 
128  static bool readStartTimeDurationInBin();
129 
138  static void readStartTimeDurationInXML(bool b);
139 
146  static bool readStartTimeDurationInXML();
147 
152  void toBin(EndianOSStream& eoss) const ;
153 
159  static void toBin(const std::vector<ArrayTimeInterval>& arrayTimeInterval, EndianOSStream& eoss);
160 
166  static void toBin(const std::vector<std::vector<ArrayTimeInterval> >& arrayTimeInterval, EndianOSStream& eoss);
167 
173  static void toBin(const std::vector<std::vector<std::vector<ArrayTimeInterval> > >& arrayTimeInterval, EndianOSStream& eoss);
174 
182 
189  static std::vector<ArrayTimeInterval> from1DBin(EndianIStream & eis);
190 
197  static std::vector<std::vector<ArrayTimeInterval> > from2DBin(EndianIStream & eis);
198 
205  static std::vector<std::vector<std::vector<ArrayTimeInterval> > > from3DBin(EndianIStream & eis);
206 
210  std::string toString() const ;
211  };
212 
213 
214  // inline constructors
215 
216  inline ArrayTimeInterval::ArrayTimeInterval(): start((int64_t)0), duration(0) {}
218  start = start_;
219  duration = Interval(std::min(duration_.get(), Long::MAX_VALUE - start.get()));
220  }
221 
222  inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD, double durationInDays) :
223  start(startInMJD),
224  duration((int64_t) (ArrayTime::unitsInADay * durationInDays)){}
225 
226  inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds,
227  int64_t durationInNanoSeconds){
228  start = startInNanoSeconds;
229  duration = std::min(durationInNanoSeconds, Long::MAX_VALUE - startInNanoSeconds);
230  }
231 
233  start(start_) {
235  }
236 
237  inline ArrayTimeInterval::ArrayTimeInterval(double startInMJD):
238  start(startInMJD) {
240  }
241 
242  inline ArrayTimeInterval::ArrayTimeInterval(int64_t startInNanoSeconds):
243  start(startInNanoSeconds) {
245  }
246 
247  // Inline setters
249  this->start = ArrayTime(start);
250  }
251 
252  inline void ArrayTimeInterval::setStart(double start) {
253  this->start = ArrayTime(start);
254  }
255 
256  inline void ArrayTimeInterval::setStart(int64_t start) {
257  this->start = ArrayTime(start);
258  }
259 
260  inline void ArrayTimeInterval::setDuration(Interval duration) {
261  this->duration = Interval(duration);
262  }
263 
264 
265  inline void ArrayTimeInterval::setDuration(double duration) {
266  this->duration = Interval((int64_t) (ArrayTime::unitsInADay * duration));
267  }
268 
269  inline void ArrayTimeInterval::setDuration(int64_t duration) {
270  this->duration = Interval(duration);
271  }
272 
273  // inline getters
275  return start;
276  }
277 
279  return ArrayTime(start.get() + duration.get() / 2);
280  }
281 
282  inline double ArrayTimeInterval::getStartInMJD() const {
283  return start.getMJD();
284  }
285 
287  return start.get();
288  }
289 
291  return duration;
292  }
293 
294  inline double ArrayTimeInterval::getDurationInDays() const {
295  return (((double) duration.get()) / ArrayTime::unitsInADay);
296  }
297 
299  return duration.get();
300  }
301 
302  // inline checkers
304  return ((start.get() == ati.getStart().get()) &&
305  (duration.get() == ati.getDuration().get()));
306  }
307 
309  int64_t start1 = start.get();
310  int64_t end1 = start1 + duration.get();
311 
312 
313  int64_t start2 = ati.getStart().get();
314  int64_t end2 = start2 + ati.getDuration().get();
315 
316  return (start2 <= start1 && end2 >= start1) ||
317  (start2 >= start1 && start2 <= end1);
318  }
319 
321  int64_t start1 = start.get();;
322  int64_t end1 = start1 + duration.get();
323 
324  int64_t start2 = ati.getStart().get();
325  int64_t end2 = start2 + ati.getDuration().get();
326 
327  return (start2>=start1 && end2<=end1);
328  }
329 
331  int64_t start1 = start.get();
332  int64_t end1 = start1 + duration.get();
333 
334  int64_t time = ati.get();
335  return (time >= start1 && time < end1);
336  }
337 
339  return (start == ati.start) && (duration == ati.duration);
340  }
341 
343  return (start != ati.start) || (duration != ati.duration);
344  }
345 
346  inline std::ostream & operator << ( std::ostream &o, ArrayTimeInterval &ati ) {
347  o << "(start=" << ati.getStart().get() << ",duration=" << ati.getDuration().get() << ")";
348  return o;
349  }
350 
351  inline std::istream & operator >> ( std::istream &i, ArrayTimeInterval &ati) {
352  i >> ati.start;
353  i >> ati.duration;
354  return i;
355  }
356 } // End namespace asdm
357 #endif // ArrayTimeInterval_CLASS
static bool readStartTimeDurationInXML()
Returns a boolean value whose meaning is defined as follows: true &lt;=&gt; the representation of ArrayTime...
The Interval class implements an interval of time in units of nanoseconds.
Definition: Interval.h:58
friend std::ostream & operator<<(std::ostream &, ArrayTimeInterval &)
void setStart(ArrayTime start)
Setters.
bool equals(ArrayTimeInterval ati)
Checkers.
ArrayTime getMidPoint() const
The ArrayTimeInterval class aggregates an instance of ArrayTime and an instance of Interval...
#define min(a, b)
Definition: hio.h:45
std::istream & operator>>(std::istream &, EntityId &)
Definition: EntityId.h:164
int64_t getDurationInNanoSeconds() const
std::string toString() const
Returns a string representation of this.
static std::vector< std::vector< ArrayTimeInterval > > from2DBin(EndianIStream &eis)
Read the binary representation of a vector of vector of ArrayTimeInterval from an EndianIStream and u...
static std::vector< ArrayTimeInterval > from1DBin(EndianIStream &eis)
Read the binary representation of a vector of ArrayTimeInterval from an EndianIStream and use the rea...
ABSTRACT TOOL CLASSES A PlotTool is a higher level event handler for a PlotCanvas The idea is to take common tasks which may require multiple events and put them in one place PlotTools also provide additional functionality in that they can be active and blocking non blocking The PlotCanvas will only send events to active and will not send events to later tools or event handlers if the latest tool was blocking In this way a single tool can be used to handle ALL user interaction via the GUI at one time
Definition: PlotTool.h:43
ArrayTimeInterval()
Constructors.
static const int64_t MAX_VALUE
The maximum value for a int64_t.
Definition: LongWrapper.h:65
static bool readStartTimeDurationInBin()
Returns a boolean value whose meaning is defined as follows: true &lt;=&gt; the representation of ArrayTime...
static bool readStartTimeDurationInBin_
ArrayTime getStart() const
Getters.
static bool readStartTimeDurationInXML_
int64_t get() const
Definition: Interval.h:295
bool operator!=(ArrayTimeInterval &)
double getStartInMJD() const
static double getMJD(double jd)
std::ostream & operator<<(std::ostream &, const EntityId &)
Friend functions.
Definition: EntityId.h:159
void toBin(EndianOSStream &eoss) const
Write the binary representation of this to a EndianOSStream.
bool contains(ArrayTimeInterval ati)
static ArrayTimeInterval fromBin(EndianIStream &eis)
Read the binary representation of an ArrayTimeInterval from a EndianIStream and use the read value to...
bool overlaps(ArrayTimeInterval ati)
bool operator==(ArrayTimeInterval &)
Operators.
static const double unitsInADay
Definition: ArrayTime.h:97
The ArrayTime class implements the concept of a point in time, implemented as an Interval of time sin...
Definition: ArrayTime.h:89
const asdmIDLTypes::IDLArrayTimeInterval toIDLArrayTimeInterval() const
To IDL conversion.
int64_t getStartInNanoSeconds() const
Interval getDuration() const
double getDurationInDays() const
void setDuration(Interval duration)
static std::vector< std::vector< std::vector< ArrayTimeInterval > > > from3DBin(EndianIStream &eis)
Read the binary representation of a vector of vector of vector of ArrayTimeInterval from an EndianISt...
friend std::istream & operator>>(std::istream &, ArrayTimeInterval &)