SIIterBot.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 #ifndef SYNTHESIS_SIITERBOT
00024 #define SYNTHESIS_SIITERBOT
00025
00026 #include <casadbus/utilities/BusAccess.h>
00027
00028 #include <casa/System/AipsrcValue.h>
00029
00030
00031 #include <casa/OS/HostInfo.h>
00032 #include <sys/time.h>
00033 #if defined(DBUS_CPP)
00034 #include <dbus-cpp/dbus.h>
00035 #else
00036 #include <dbus-c++/dbus.h>
00037 #endif
00038
00039
00040
00041 #include <mutex>
00042 #include <condition_variable>
00043
00044
00045
00046
00047 #ifdef INTERACTIVE_ITERATION
00048 #include <casadbus/interfaces/SynthImager.adaptor.h>
00049 #endif
00050
00051 namespace casa {
00052
00053 class Record;
00054
00055 class SIIterBot_adaptor;
00056
00057 class SIIterBot_callback {
00058 public:
00059 SIIterBot_callback( ) : adaptor(0) { }
00060 ~SIIterBot_callback( ) { }
00061 void interactionRequired(bool);
00062
00063 void addHandler( SIIterBot_adaptor* );
00064 void removeHandler( SIIterBot_adaptor* );
00065
00066 private:
00067 std::recursive_mutex mutex;
00068 SIIterBot_adaptor *adaptor;
00069
00070 };
00071
00072 class SIIterBot_state {
00073 private:
00074
00075 SIIterBot_state( const SIIterBot_state & );
00076 SIIterBot_state &operator=( const SIIterBot_state & );
00077
00078 public:
00079 SIIterBot_state( SHARED_PTR<SIIterBot_callback> );
00080 ~SIIterBot_state( );
00081
00082
00083
00084
00085
00086 void acceptCallbacks( SIIterBot_adaptor *siba ) { callback->addHandler(siba); }
00087 void denyCallbacks( SIIterBot_adaptor *siba ) { callback->removeHandler(siba); }
00088
00089
00090 virtual bool interactiveInputRequired();
00091 virtual void waitForInteractiveInput();
00092
00093
00094
00095 virtual int cleanComplete();
00096
00097
00098 virtual Record getMinorCycleControls();
00099 virtual void mergeCycleInitializationRecord(Record&);
00100 virtual void mergeCycleExecutionRecord(Record&);
00101
00102
00103
00104
00105
00106
00107
00108 void changeNiter( Int niter );
00109 void changeCycleNiter( Int cycleniter );
00110 void changeInteractiveNiter(Int interactiveniter );
00111
00112 void changeThreshold( Float threshold );
00113 void changeCycleThreshold( Float cyclethreshold );
00114 void changeInteractiveThreshold( Float cyclethreshold );
00115
00116 void changeLoopGain(Float loopgain );
00117 void changeCycleFactor( Float cyclefactor);
00118
00119 void changeMinPsfFraction(Float minpsffraction);
00120 void changeMaxPsfFraction(Float maxpsffraction);
00121
00122 void changeInteractiveMode(const bool& interactiveEnabled);
00123 void changePauseFlag(const bool& pauseEnabled);
00124 void changeStopFlag(const bool& stopEnabled);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void setControlsFromRecord(Record &recordIn);
00138 Float readThreshold( Record recordIn, String id );
00139
00140 virtual Record getDetailsRecord();
00141
00142
00143
00144
00145
00146
00147
00148 void incrementMajorCycleCount();
00149
00150 Int getMajorCycleCount();
00151
00152
00153
00154
00155
00156 void updateCycleThreshold();
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 void addSummaryMajor();
00171
00172
00173
00174
00175 void pushDetails();
00176
00177
00178 void pushSummary();
00179
00180
00181 bool incrementController();
00182 bool decrementController();
00183 int getNumberOfControllers();
00184
00185 std::string getDescription( );
00186 void setDescription( const std::string &value );
00187
00188 #ifdef INTERACTIVE_ITERATION
00189 std::map<std::string,DBus::Variant> getDetails();
00190 #endif
00191 DBus::Variant getSummary();
00192
00193 void interactionComplete();
00194
00195 #ifdef INTERACTIVE_ITERATION
00196 void controlUpdate(const std::map<std::string, DBus::Variant>& parameters);
00197 #endif
00199
00200
00201
00202
00203
00204
00205
00206
00207 virtual Record getSummaryRecord();
00208
00209 protected:
00210
00211 virtual void mergeMinorCycleSummary(const Array<Double>& summary);
00212
00213
00214 void printOut(String prefix, Bool verbose);
00215
00216 std::string itsDescription;
00217
00218 Float itsMinPsfFraction;
00219 Float itsMaxPsfFraction;
00220 Float itsMaxPsfSidelobe;
00221 Float itsPeakResidual;
00222 Float itsPrevPeakResidual;
00223
00224
00225 int itsControllerCount;
00226
00227
00228
00229
00230
00231 std::recursive_mutex recordMutex;
00232 std::recursive_mutex descriptionMutex;
00234
00235 Int itsNiter;
00236 Int itsCycleNiter;
00237 Int itsInteractiveNiter;
00238
00239 Float itsThreshold;
00240 Float itsCycleThreshold;
00241 Float itsInteractiveThreshold;
00242
00243 Bool itsIsCycleThresholdAuto;
00244
00245 Float itsCycleFactor;
00246 Float itsLoopGain;
00247
00248 Bool itsStopFlag;
00249 Bool itsPauseFlag;
00250 Bool itsInteractiveMode;
00251 Bool itsUpdatedModelFlag;
00252
00253 Int itsIterDone;
00254 Int itsInteractiveIterDone;
00255 Int itsMaxCycleIterDone;
00256 Int itsMajorDone;
00257 Int itsStopCode;
00258
00259
00260
00261
00262
00263 bool interactionPending;
00264 bool updateNeeded;
00265 std::condition_variable interactionCond;
00266 std::mutex interactionMutex;
00267
00268
00269
00270 Int itsNSummaryFields;
00271 Array<Double> itsSummaryMinor;
00272 Array<Int> itsSummaryMajor;
00273
00274 SHARED_PTR<SIIterBot_callback> callback;
00275 };
00276
00277 class SIIterBot_adaptor
00278 #ifdef INTERACTIVE_ITERATION
00279 : private dbus::address,
00280 private edu::nrao::casa::SynthesisImager_adaptor,
00281 public DBus::IntrospectableAdaptor,
00282 public DBus::ObjectAdaptor
00283 #endif
00284 {
00285 public:
00286 SIIterBot_adaptor( SHARED_PTR<SIIterBot_state> state, const std::string &bus_name, const std::string &object_path );
00287 ~SIIterBot_adaptor();
00288
00289 bool incrementController( ) { return state->incrementController( ); }
00290 bool decrementController( ) { return state->decrementController( ); }
00291
00292 void interactionRequired( const bool &val ) {
00293 #ifdef INTERACTIVE_ITERATION
00294 edu::nrao::casa::SynthesisImager_adaptor::interactionRequired( val );
00295 #else
00296 (void)val;
00297 #endif
00298 }
00299 void controlUpdate(const std::map< std::string, ::DBus::Variant >& newParams)
00300 {
00301 #ifdef INTERACTIVE_ITERATION
00302 state->controlUpdate(newParams);
00303 #else
00304 (void)newParams;
00305
00306 #endif
00307 }
00308 void interactionComplete( )
00309 { state->interactionComplete( ); }
00310 void changePauseFlag(const bool& pauseState)
00311 { state->changePauseFlag(pauseState); }
00312 void changeStopFlag(const bool& stopState)
00313 { state->changeStopFlag(stopState); }
00314 void changeInteractiveMode(const bool& interactiveMode)
00315 { state->changeInteractiveMode(interactiveMode); }
00316 std::string getDescription( )
00317 { return state->getDescription( ); }
00318 std::map< std::string, ::DBus::Variant > getDetails( )
00319 {
00320 #ifdef INTERACTIVE_ITERATION
00321 return state->getDetails( );
00322 #else
00323 return std::map< std::string, ::DBus::Variant >( );
00324 #endif
00325 }
00326 ::DBus::Variant getSummary( )
00327 { return state->getSummary( ); }
00328
00329 private:
00330 SHARED_PTR<SIIterBot_state> state;
00331
00332 };
00333
00334 }
00335
00336 #endif