VLAT2.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef VLAT2_H_
00030 #define VLAT2_H_
00031
00032 #include "AsynchronousTools2.h"
00033 #include "UtilJ.h"
00034
00035 #include <tuple>
00036 #include <msvis/MSVis/AsynchronousInterface2.h>
00037 #include <msvis/MSVis/VisBuffer2.h>
00038 #include <msvis/MSVis/VisBufferImplAsync2.h>
00039 #include <msvis/MSVis/VisibilityIterator2.h>
00040 #include <msvis/MSVis/VisibilityIteratorImplAsync2.h>
00041
00042 #include <map>
00043
00044
00045 using casa::asyncio::RoviaModifiers;
00046 using casa::utilj::ThreadTimes;
00047 using casa::utilj::DeltaThreadTimes;
00048
00049 namespace casa {
00050
00051 template<typename T> class Block;
00052 class MeasurementSet;
00053 class VisBuffer;
00054
00055 namespace vi {
00056
00057 class AsynchronousInterface;
00058 class InterfaceController;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 class VlatFunctor {
00069
00070 public:
00071
00072
00073 VlatFunctor (const String & name, Int precedence = 0)
00074 : id_p (VisBufferComponents::N_VisBufferComponents), name_p (name), precedence_p (precedence)
00075 {}
00076 VlatFunctor (Int precedence = 0)
00077 : id_p (VisBufferComponents::N_VisBufferComponents), name_p ("NotSpecified"), precedence_p (precedence)
00078 {}
00079 virtual ~VlatFunctor () {}
00080
00081 virtual void operator() (VisBuffer *);
00082 virtual VlatFunctor * clone () { return new VlatFunctor (* this);}
00083
00084 VisBufferComponents::EnumType getId () const { return id_p;}
00085 void setId (VisBufferComponents::EnumType id) { id_p = id;}
00086 void setPrecedence (Int precedence) { precedence_p = precedence; }
00087
00088 static Bool byDecreasingPrecedence (const VlatFunctor * a, const VlatFunctor * b)
00089 {
00090 Bool result = (a->precedence_p > b->precedence_p) ||
00091 (a->precedence_p == b->precedence_p && a->id_p < b->id_p);
00092 return result;
00093 }
00094 private:
00095
00096 VisBufferComponents::EnumType id_p;
00097 String name_p;
00098 Int precedence_p;
00099
00100 };
00101
00102 template <typename Ret, typename VbType>
00103 class VlatFunctor0 : public VlatFunctor {
00104
00105 public:
00106
00107 typedef Ret (VbType::* Nullary) ();
00108
00109 VlatFunctor0 (Nullary nullary, Int precedence = 0) : VlatFunctor (precedence), f_p (nullary) {}
00110 virtual ~VlatFunctor0 () {}
00111
00112 void operator() (VisBuffer * c) { (dynamic_cast<VbType *> (c)->*f_p)(); }
00113 virtual VlatFunctor * clone () { return new VlatFunctor0 (* this); }
00114
00115 private:
00116
00117 Nullary f_p;
00118 };
00119
00120 template <typename Ret, typename VbType>
00121 VlatFunctor0<Ret, VbType> * vlatFunctor0 (Ret (VbType::* f) ())
00122 { return new VlatFunctor0<Ret, VbType> (f);}
00123
00124 template <typename Ret, typename Arg>
00125 class VlatFunctor1 : public VlatFunctor {
00126
00127 public:
00128
00129 typedef Ret (VisBuffer::* Unary) (Arg);
00130
00131 VlatFunctor1 (Unary unary, Arg arg, Int precedence = 0) : VlatFunctor (precedence) { f_p = unary; arg_p = arg;}
00132 virtual ~VlatFunctor1 () {}
00133
00134 void operator() (VisBuffer * c) { (c->*f_p)(arg_p); }
00135 virtual VlatFunctor * clone () { return new VlatFunctor1 (* this); }
00136
00137 private:
00138
00139 Unary f_p;
00140 Arg arg_p;
00141 };
00142
00143 template <typename Ret, typename Arg>
00144 VlatFunctor1<Ret, Arg> * vlatFunctor1 (Ret (VisBuffer::* f) (Arg), Arg i)
00145 { return new VlatFunctor1<Ret, Arg> (f, i);}
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 class VLAT : public casa::async::Thread {
00214
00215 public:
00216
00217 VLAT (AsynchronousInterface *);
00218 ~VLAT ();
00219
00220 void clearFillTerminationRequest ();
00221 void initialize (const ROVisibilityIterator & rovi);
00222 void initialize (const Block<MeasurementSet> & mss,
00223 const Block<Int> & sortColumns,
00224 Bool addDefaultSortCols,
00225 Double timeInterval,
00226 Bool writable);
00227 Bool isTerminated () const;
00228 void setModifiers (RoviaModifiers & modifiers);
00229 void setPrefetchColumns (const PrefetchColumns & prefetchColumns);
00230 void requestSweepTermination ();
00231 void terminate ();
00232
00233 protected:
00234
00235 class FillerDictionary : public std::map<VisBufferComponents::EnumType, VlatFunctor *> {
00236
00237 public:
00238
00239 void add (VisBufferComponents::EnumType id, VlatFunctor * f)
00240 {
00241 f->setId (id);
00242 assert (find(id) == end());
00243 (* this)[id] = f;
00244 }
00245
00246
00247 };
00248 typedef vector<VlatFunctor *> Fillers;
00249
00250 void applyModifiers (ROVisibilityIterator * rovi, VisibilityIterator * vi);
00251 void alignWriteIterator (SubChunkPair subchunk);
00252 void checkFiller (VisBufferComponents::EnumType id);
00253 void createFillerDictionary ();
00254 void fillDatum (VlaDatum * datum);
00255 void fillDatumMiscellanyAfter (VlaDatum * datum);
00256 void fillDatumMiscellanyBefore (VlaDatum * datum);
00257 void fillLsrInfo (VlaDatum * datum);
00258 void flushWrittenData ();
00259 void handleWrite ();
00260 void * run ();
00261 Bool sweepTerminationRequested () const;
00262 void sweepVi ();
00263 void throwIfSweepTerminated ();
00264 Bool waitForViReset ();
00265 void waitUntilFillCanStart ();
00266
00267 private:
00268
00269 class SweepTerminated : public std::exception {};
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 const InterfaceController * controller_p;
00319 FillerDictionary fillerDictionary_p;
00320 Fillers fillers_p;
00321 AsynchronousInterface * interface_p;
00322 Block<MeasurementSet> measurementSets_p;
00323 SubChunkPair readSubchunk_p;
00324 RoviaModifiers roviaModifiers_p;
00325 volatile Bool sweepTerminationRequested_p;
00326 Bool threadTerminated_p;
00327 ROVisibilityIterator * visibilityIterator_p;
00328 VlaData * vlaData_p;
00329 VisibilityIterator * writeIterator_p;
00330 SubChunkPair writeSubchunk_p;
00331
00332 };
00333
00334 class VlatAndData {
00335
00336 friend class ViReadImplAsync;
00337
00338 public:
00339
00340 protected:
00341
00342 VlatAndData ();
00343 ~VlatAndData (){}
00344
00345 private:
00346
00347 VlaData * vlaData_p;
00348 VLAT * vlat_p;
00349 };
00350
00351 }
00352
00353 }
00354
00355
00356
00357 #endif