casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VLAT2.h
Go to the documentation of this file.
1 //# VLAT.h: Visibility lookahead concurrency definitions (classes VlaDatum, VlaData, VLAT)
2 //# Copyright (C) 2011
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning CASA should be addressed as follows:
20 //# Internet email: CASA-request@nrao.edu.
21 //# Postal address: CASA Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef VLAT2_H_
30 #define VLAT2_H_
31 
32 #include "AsynchronousTools2.h"
33 #include "UtilJ.h"
34 
35 #include <tuple>
37 #include <msvis/MSVis/VisBuffer2.h>
41 
42 #include <map>
43 
44 namespace casacore{
45 
46 template<typename T> class Block;
47 class MeasurementSet;
48 }
49 
50 //using namespace casa::async;
54 
55 
56 class VisBuffer;
57 
58 namespace vi {
59 
60 class AsynchronousInterface;
61 class InterfaceController;
62 
63 // VlatFunctor is an abstract class for functor objects used to encapsulate the various
64 // filling methods (e.g., fillVis, fillAnt1, etc.). This allows the various functions
65 // to be put into a list of fill methods that are used by the VLAT everytime the VLAT's
66 // visibliity iterator is advanced. There are two subclasses VlatFunctor0 and VlatFunctor1
67 // which support nullar and unary fill methods. The fillers for visibility-related data
68 // (e.g., fillVis and fillVisCube) take a parameter to indicate which sort of visibility
69 // (e.g., actual, model, corrected) is to be filled.
70 
71 class VlatFunctor {
72 
73 public:
74 
75 
76  VlatFunctor (const casacore::String & name, casacore::Int precedence = 0)
77  : id_p (VisBufferComponents::N_VisBufferComponents), name_p (name), precedence_p (precedence)
78  {}
79  VlatFunctor (casacore::Int precedence = 0)
80  : id_p (VisBufferComponents::N_VisBufferComponents), name_p ("NotSpecified"), precedence_p (precedence)
81  {}
82  virtual ~VlatFunctor () {}
83 
84  virtual void operator() (VisBuffer *); // Throws an error if not overridden
85  virtual VlatFunctor * clone () { return new VlatFunctor (* this);}
86 
87  VisBufferComponents::EnumType getId () const { return id_p;}
88  void setId (VisBufferComponents::EnumType id) { id_p = id;}
89  void setPrecedence (casacore::Int precedence) { precedence_p = precedence; }
90 
92  { // First by increasing precedence and then by decreasing id (make deterministic)
93  casacore::Bool result = (a->precedence_p > b->precedence_p) ||
94  (a->precedence_p == b->precedence_p && a->id_p < b->id_p);
95  return result;
96  }
97 private:
98 
99  VisBufferComponents::EnumType id_p;
102 
103 };
104 
105 template <typename Ret, typename VbType>
106 class VlatFunctor0 : public VlatFunctor {
107 
108 public:
109 
110  typedef Ret (VbType::* Nullary) ();
111 
112  VlatFunctor0 (Nullary nullary, casacore::Int precedence = 0) : VlatFunctor (precedence), f_p (nullary) {}
113  virtual ~VlatFunctor0 () {}
114 
115  void operator() (VisBuffer * c) { (dynamic_cast<VbType *> (c)->*f_p)(); }
116  virtual VlatFunctor * clone () { return new VlatFunctor0 (* this); }
117 
118 private:
119 
121 };
122 
123 template <typename Ret, typename VbType>
124 VlatFunctor0<Ret, VbType> * vlatFunctor0 (Ret (VbType::* f) ())
125 { return new VlatFunctor0<Ret, VbType> (f);}
126 
127 template <typename Ret, typename Arg>
128 class VlatFunctor1 : public VlatFunctor {
129 
130 public:
131 
132  typedef Ret (VisBuffer::* casacore::Unary) (Arg);
133 
134  VlatFunctor1 (casacore::Unary unary, Arg arg, casacore::Int precedence = 0) : VlatFunctor (precedence) { f_p = unary; arg_p = arg;}
135  virtual ~VlatFunctor1 () {}
136 
137  void operator() (VisBuffer * c) { (c->*f_p)(arg_p); }
138  virtual VlatFunctor * clone () { return new VlatFunctor1 (* this); }
139 
140 private:
141 
142  casacore::Unary f_p;
143  Arg arg_p;
144 };
145 
146 template <typename Ret, typename Arg>
147 VlatFunctor1<Ret, Arg> * vlatFunctor1 (Ret (VisBuffer::* f) (Arg), Arg i)
148 { return new VlatFunctor1<Ret, Arg> (f, i);}
149 
150 // <summary>
151 // VLAT is the Visibility LookAhead Thread. This thread advances a visibility iterator
152 // and fills the data indicated by the visibility iterator into the VlaData buffer ring.
153 // </summary>
154 
155 // <use visibility=local>
156 
157 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
158 // </reviewed>
159 
160 // <prerequisite>
161 // <li> VisBuffer
162 // <li> VisBufferAsync
163 // <li> ROVisibilityIteratorAsync
164 // <li> VlaData
165 // <li> VLAT
166 // </prerequisite>
167 //
168 // <etymology>
169 // VLAT is the Visibility LookAhead Thread. It is not related to the more common NRAO
170 // acronym VLA.
171 // </etymology>
172 //
173 // <synopsis>
174 //
175 // The VLAT is a thread object that buffers up data from successive visibility iterator positions
176 // in a MeasurementSet. It is part of the backend to a ROVisibilityIteratorAsync (ROVIA)
177 // object used by the main thread to replace the normal, synchronous ROVisibilityIterator.
178 // When the user creates a ROVIA object the information normally used to create a ROVisibilityIterator
179 // is passed to the VLAT which uses it to create a ROVisibilityIterator local to itself. The VLAT then
180 // uses this ROVisibilityIterator to fill buffers in the VlaData-managed buffer ring (this interaction
181 // is described in VlaData). Filling consists of attaching VLAT's ROVisibilityIterator to the
182 // VisBufferAsync object associated with a buffer and then calling the fill operations for the data
183 // items (e.g., visCube, Ant1, etc.) which the user has requested be prefetched. The fill operations
184 // will likely result in synchronous I/O operations being performed by the column access methods
185 // related to the casacore::Table system (memory-resident tables, columns, etc., may be able to satisfy a fill
186 // operation without performing I/O).
187 //
188 // The thread may be terminated by calling the terminate method. This will cause the VLAT to terminate
189 // when it notices the termination request. The termination may not be immediate since the VLAT may
190 // be engaged in a syncrhonous I/O operation and is uanble to detect the termination request until
191 // that I/O has completed.
192 //
193 // Normally the VLAT sweeps the VI to the end of the measurement set and then awaits further instructions.
194 // The main thread may stop the sweep early by calling VlaData::terminateSweep which will eventually be
195 // detected by the VLAT and result in a coordinated reset of the sweep. When the sweep reset is applied
196 // the VLAT will also detect visibility iterator modification requests (e.g., setRowBlocking, selectChannel,
197 // setInterval, etc.) that were queued up in VlaData; for the set of available VI modification requests
198 // supported see ROVisibilityIteratorAsync.
199 //
200 // </synopsis>
201 //
202 // <example>
203 // </example>
204 //
205 // <motivation>
206 // </motivation>
207 //
208 // <thrown>
209 // <li> casacore::AipsError for unrecoverable errors. These will not be caught (in C++ anyway) and cause
210 // application termination.
211 // </thrown>
212 //
213 // <todo asof="yyyy/mm/dd">
214 // </todo>
215 
216 class VLAT : public casa::async::Thread {
217 
218 public:
219 
220  VLAT (AsynchronousInterface *);
221  ~VLAT ();
222 
224  void initialize (const ROVisibilityIterator & rovi);
226  const casacore::Block<casacore::Int> & sortColumns,
227  casacore::Bool addDefaultSortCols,
228  casacore::Double timeInterval,
229  casacore::Bool writable);
230  casacore::Bool isTerminated () const;
231  void setModifiers (RoviaModifiers & modifiers);
232  void setPrefetchColumns (const PrefetchColumns & prefetchColumns);
233  void requestSweepTermination ();
234  void terminate ();
235 
236 protected:
237 
238  class FillerDictionary : public std::map<VisBufferComponents::EnumType, VlatFunctor *> {
239 
240  public:
241 
242  void add (VisBufferComponents::EnumType id, VlatFunctor * f)
243  {
244  f->setId (id);
245  assert (find(id) == end()); // shouldn't already have one for this ID
246  (* this)[id] = f;
247  }
248 
249  //void setPrecedences (const FillerDependencies & dependencies);
250  };
251  typedef std::vector<VlatFunctor *> Fillers;
252 
253  void applyModifiers (ROVisibilityIterator * rovi, VisibilityIterator * vi);
254  void alignWriteIterator (SubChunkPair subchunk);
255  void checkFiller (VisBufferComponents::EnumType id);
256  void createFillerDictionary ();
257  void fillDatum (VlaDatum * datum);
258  void fillDatumMiscellanyAfter (VlaDatum * datum);
259  void fillDatumMiscellanyBefore (VlaDatum * datum);
260  void fillLsrInfo (VlaDatum * datum);
261  void flushWrittenData ();
262  void handleWrite ();
263  void * run ();
265  void sweepVi ();
266  void throwIfSweepTerminated ();
268  void waitUntilFillCanStart ();
269 
270 private:
271 
272  class SweepTerminated : public std::exception {};
273 
274 // class NullaryPredicate {
275 // public:
276 //
277 // virtual ~NullaryPredicate () {}
278 // virtual casacore::Bool operator () () const = 0;
279 // };
280 //
281 // class FillCanStartOrSweepTermination : public NullaryPredicate {
282 //
283 // public:
284 //
285 // FillCanStartOrSweepTermination (VlaData * vlaData, AsynchronousInterface * interface)
286 // : interface_p (interface),
287 // vlaData_p (vlaData)
288 // {}
289 //
290 // casacore::Bool operator() () const
291 // {
292 // return vlaData_p->fillCanStart () || interface_p->isSweepTerminationRequested ();
293 // }
294 //
295 // private:
296 //
297 // AsynchronousInterface * interface_p;
298 // VlaData * vlaData_p;
299 // };
300 //
301 // class ViResetOrLookaheadTermination : public NullaryPredicate {
302 //
303 // public:
304 //
305 // ViResetOrLookaheadTermination (AsynchronousInterface * interface)
306 // : interface_p (interface)
307 // {}
308 //
309 // casacore::Bool operator() () const
310 // {
311 // casacore::Bool viWasReset_p = interface_p->viResetRequested;
312 //
313 // return viWasReset_p || interface_p->isLookaheadTerminationRequested ();
314 // }
315 //
316 // private:
317 //
318 // AsynchronousInterface * interface_p;
319 // };
320 
321  const InterfaceController * controller_p; // [use]
324  AsynchronousInterface * interface_p; // [use]
326  SubChunkPair readSubchunk_p;
330  ROVisibilityIterator * visibilityIterator_p; // [own]
331  VlaData * vlaData_p; // [use]
332  VisibilityIterator * writeIterator_p; // [own]
333  SubChunkPair writeSubchunk_p;
334 
335 };
336 
337 class VlatAndData {
338 
339  friend class ViReadImplAsync;
340 
341 public:
342 
343 protected:
344 
345  VlatAndData ();
347 
348 private:
349 
350  VlaData * vlaData_p;
352 };
353 
354 } // end namespace vi
355 
356 
357 
358 
359 #endif /* VLAT_H_ */
void terminate()
int Int
Definition: aipstype.h:50
virtual ~VlatFunctor1()
Definition: VLAT2.h:135
VLAT(AsynchronousInterface *)
casacore::Block< casacore::MeasurementSet > measurementSets_p
Definition: VLAT2.h:325
LatticeExprNode arg(const LatticeExprNode &expr)
void flushWrittenData()
virtual void operator()(VisBuffer *)
virtual ~VlatFunctor0()
Definition: VLAT2.h:113
VlaData * vlaData_p
Definition: VLAT2.h:331
VlaData * vlaData_p
Definition: VLAT2.h:350
VlatFunctor is an abstract class for functor objects used to encapsulate the various filling methods ...
Definition: VLAT2.h:71
void setId(VisBufferComponents::EnumType id)
Definition: VLAT2.h:88
UnaryFunctor< D, R > unary(R(*f)(D))
Definition: UtilJ.h:614
VlatFunctor0< Ret, VbType > * vlatFunctor0(Ret(VbType::*f)())
Definition: VLAT2.h:124
casacore::Bool sweepTerminationRequested() const
void initialize(const ROVisibilityIterator &rovi)
casacore::Bool waitForViReset()
std::vector< VlatFunctor * > Fillers
Definition: VLAT2.h:251
SubChunkPair readSubchunk_p
Definition: VLAT2.h:326
casacore::Bool isTerminated() const
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
virtual VlatFunctor * clone()
Definition: VLAT2.h:85
void waitUntilFillCanStart()
const_iterator end() const
void requestSweepTermination()
const InterfaceController * controller_p
class NullaryPredicate { public:
Definition: VLAT2.h:321
static casacore::Bool byDecreasingPrecedence(const VlatFunctor *a, const VlatFunctor *b)
Definition: VLAT2.h:91
VlatFunctor(const casacore::String &name, casacore::Int precedence=0)
Definition: VLAT2.h:76
VlatFunctor1< Ret, Arg > * vlatFunctor1(Ret(VisBuffer::*f)(Arg), Arg i)
Definition: VLAT2.h:147
casacore::Int precedence_p
Definition: VLAT2.h:101
void fillDatumMiscellanyAfter(VlaDatum *datum)
void setModifiers(RoviaModifiers &modifiers)
VLAT is the Visibility LookAhead Thread. This thread advances a visibility iterator and fills the dat...
Definition: VLAT2.h:216
VlatFunctor(casacore::Int precedence=0)
Definition: VLAT2.h:79
void applyModifiers(ROVisibilityIterator *rovi, VisibilityIterator *vi)
void clearFillTerminationRequest()
VisibilityIterator * writeIterator_p
Definition: VLAT2.h:332
double Double
Definition: aipstype.h:55
VLAT * vlat_p
Definition: VLAT2.h:351
void setPrecedence(casacore::Int precedence)
Definition: VLAT2.h:89
void add(VisBufferComponents::EnumType id, VlatFunctor *f)
Definition: VLAT2.h:242
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void setPrefetchColumns(const PrefetchColumns &prefetchColumns)
virtual VlatFunctor * clone()
Definition: VLAT2.h:116
void handleWrite()
ROVisibilityIterator * visibilityIterator_p
Definition: VLAT2.h:330
FillerDictionary fillerDictionary_p
Definition: VLAT2.h:322
void createFillerDictionary()
casacore::Bool threadTerminated_p
Definition: VLAT2.h:329
void operator()(VisBuffer *c)
Definition: VLAT2.h:115
VisBufferComponents::EnumType getId() const
Definition: VLAT2.h:87
casacore::String name_p
Definition: VLAT2.h:100
VlatFunctor0(Nullary nullary, casacore::Int precedence=0)
Definition: VLAT2.h:112
virtual ~VlatFunctor()
Definition: VLAT2.h:82
VlatFunctor1(casacore::Unary unary, Arg arg, casacore::Int precedence=0)
Definition: VLAT2.h:134
casacore::Unary f_p
Definition: VLAT2.h:142
void fillLsrInfo(VlaDatum *datum)
const Double c
Fundamental physical constants (SI units):
Nullary f_p
Definition: VLAT2.h:120
String: the storage and methods of handling collections of characters.
Definition: String.h:223
VisBufferComponents::EnumType id_p
Definition: VLAT2.h:99
void throwIfSweepTerminated()
void operator()(VisBuffer *c)
Definition: VLAT2.h:137
friend class ViReadImplAsync
Definition: VLAT2.h:339
Ret(VbType::* Nullary)()
Definition: VLAT2.h:110
AsynchronousInterface * interface_p
Definition: VLAT2.h:324
virtual VlatFunctor * clone()
Definition: VLAT2.h:138
void fillDatumMiscellanyBefore(VlaDatum *datum)
void * run()
RoviaModifiers roviaModifiers_p
Definition: VLAT2.h:327
void checkFiller(VisBufferComponents::EnumType id)
void sweepVi()
SubChunkPair writeSubchunk_p
Definition: VLAT2.h:333
Fillers fillers_p
Definition: VLAT2.h:323
volatile casacore::Bool sweepTerminationRequested_p
Definition: VLAT2.h:328
void alignWriteIterator(SubChunkPair subchunk)
void fillDatum(VlaDatum *datum)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42