casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIIterBot.h
Go to the documentation of this file.
1 //# SIIterBot.h: This file contains the interface definition SIIterBot class
2 //#
3 //# CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
4 //# Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
5 //# Copyright (C) European Southern Observatory, 2011, All rights reserved.
6 //#
7 //# This library is free software; you can redistribute it and/or
8 //# modify it under the terms of the GNU Lesser General Public
9 //# License as published by the Free software Foundation; either
10 //# version 2.1 of the License, or (at your option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful,
13 //# but WITHOUT ANY WARRANTY, without even the implied warranty of
14 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 //# Lesser General Public License for more details.
16 //#
17 //# You should have received a copy of the GNU Lesser General Public
18 //# License along with this library; if not, write to the Free Software
19 //# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //# MA 02111-1307 USA
21 //# $Id: $
22 
23 #ifndef SYNTHESIS_SIITERBOT
24 #define SYNTHESIS_SIITERBOT
25 
26 #if ! defined(WITHOUT_DBUS)
28 #else
29 #include <stdcasa/variant.h>
30 #endif
31 // .casarc interface
33 
34 // System utilities (for profiling macros)
35 #include <casa/OS/HostInfo.h>
36 #include <sys/time.h>
37 #if ! defined(WITHOUT_DBUS)
38 #if defined(DBUS_CPP)
39 #include <dbus-cpp/dbus.h> /*for DBus::Variant... probably can be removed with *_adaptor class*/
40 #else
41 #include <dbus-c++/dbus.h>
42 #endif
43 #endif
44 
45 // Boost Libraries for mutex and noncopyable semantics
46 #include <map>
47 #include <mutex>
48 #include <condition_variable>
49 
50 // Include files for the DBus Service
51 //#include <casadbus/interfaces/SynthImager.adaptor.h>
52 
53 #ifdef INTERACTIVE_ITERATION
54 #include <casadbus/interfaces/SynthImager.adaptor.h>
55 #endif
56 
57 namespace casacore{
58 
59  class Record;
60 }
61 
62 namespace casa { //# NAMESPACE CASA - BEGIN
63 
64 
65  class SIIterBot_adaptor;
66 
68  public:
71  void interactionRequired(bool);
72 
75 
76  private:
77  std::recursive_mutex mutex;
79 
80  };
81 
83  private:
84  // make SIIterBot_state uncopyable...
87 
88  public:
89  SIIterBot_state( std::shared_ptr<SIIterBot_callback> );
91 
92  /****
93  ***** allow or deny callbacks which are funneled through dbus,
94  ***** a shared pointer is explicitly NOT used here to avoid a cycle.
95  ****/
96  void acceptCallbacks( SIIterBot_adaptor *siba ) { callback->addHandler(siba); }
97  void denyCallbacks( SIIterBot_adaptor *siba ) { callback->removeHandler(siba); }
98 
99  /* Wait for an Interactive Clean Cycle */
100  virtual bool interactiveInputRequired();
101  virtual void waitForInteractiveInput();
102 
103  // virtual bool majorCycleRequired(casacore::Float currentPeakResidual);
104 
105  virtual int cleanComplete(casacore::Bool lastcyclecheck=casacore::False);
106 
107  /* --- Functions for interacting with Minor Cycle Control --- */
111 
112 
113  //void mergeSubIterBot(SISubIterBot& subIterBot);
114 
115  /* ------ Begin functions for runtime parameter modification ------ */
116  /* These are the control variables. We can set them either through these
117  method or through the casacore::Record interface */
118  void changeNiter( casacore::Int niter );
119  void changeCycleNiter( casacore::Int cycleniter );
120  void changeInteractiveNiter(casacore::Int interactiveniter );
121 
122  void changeThreshold( casacore::Float threshold );
123  void changeCycleThreshold( casacore::Float cyclethreshold );
124  void changeInteractiveThreshold( casacore::Float cyclethreshold );
125 
126  void changeLoopGain(casacore::Float loopgain );
127  void changeCycleFactor( casacore::Float cyclefactor);
128 
129  void changeMinPsfFraction(casacore::Float minpsffraction);
130  void changeMaxPsfFraction(casacore::Float maxpsffraction);
131 
132  void changeInteractiveMode(const bool& interactiveEnabled);
133  void changePauseFlag(const bool& pauseEnabled);
134  void changeStopFlag(const bool& stopEnabled);
135 
136  /* expected not to change but for conviniece set nsimga here */
137  void changeNsigma( casacore::Float nsigma );
138 
139  /* As a convience the controls can also be updated from a Record.
140  The following fields are supported:
141  - niter
142  - cycleniter
143  - interactiveniter
144  - threshold
145  - cyclethreshold
146  - interactivethreshold
147  - loopgain
148  - cyclefactor
149  */
150  void setControlsFromRecord(casacore::Record &recordIn);
152 
154  //casacore::Record getSubIterBotRecord();
155 
156  /* ------ END Functions for runtime parameter modification -------*/
157 
158  /* Call these functions to keep track of cycles */
159 
160  /* Note: Incrementing the Major cycle will reset the cycleIterDone */
163 
165 
166 
167 
168  /* This will calculate and set a new cycle threshold based
169  on the Peak Residual and the current values of the PSF values.*/
170  void updateCycleThreshold();
171 
172  /* Values for the control of the cycle threshold */
173  /* void setMaxPsfSidelobe( casacore::Float maxpsfsidelobe ); */
174  /* casacore::Float getMaxPsfSidelobe(); */
175 
176  /* void setMaxPsfFraction(casacore::Float maxpsffraction ); */
177  /* casacore::Float getMaxPsfFraction(); */
178 
179  /* void setMinPsfFraction(casacore::Float minpsffraction ); */
180  /* casacore::Float getMinPsfFraction(); */
181  //casacore::Int getRemainingNiter();
182  //casacore::Int getCompletedNiter();
183 
184  void addSummaryMajor();
185 
186  /* -------- DBus Interface ------------- */
187 
188  /* Publish the current details from the Iterbot to all clients */
189  void pushDetails();
190 
191  /* Publish the current summary from the Iterbot to all clients */
192  void pushSummary();
193 
194  /* These are the fuctions we provide through the dbus interface */
195  bool incrementController();
196  bool decrementController();
198 
199  std::string getDescription( );
200  void setDescription( const std::string &value );
201 
202 #if defined(WITHOUT_DBUS)
203  std::map<std::string,casac::variant> getDetails( );
205  void controlUpdate(const std::map<std::string, casac::variant>& parameters);
206 #else
207 #ifdef INTERACTIVE_ITERATION
208  std::map<std::string,DBus::Variant> getDetails();
209  void controlUpdate(const std::map<std::string, DBus::Variant>& parameters);
210 #endif
211  DBus::Variant getSummary();
212 #endif
213  void interactionComplete();
214 
216 
217  /* Methods to get the state of the iterbot as a casacore::Record*/
218 
219  /* This record has all of the fields associated with the detail record
220  but adds
221  - summaryminor
222  - summarymajor
223  */
225 
226  protected:
227 
228  virtual void mergeMinorCycleSummary(const casacore::Array<casacore::Double>& summary);
229 
230  /* For testing/debugging. Print out the contents of the iterbot */
231  void printOut(casacore::String prefix, casacore::Bool verbose);
232 
233  std::string itsDescription;
234 
243 
247 
250 
252 
254 
256 
257  /* The number of Controllers Currently Connected */
259 
260 
261  /* A recursive mutex which provides access control to the
262  underlying state variables
263  */
264  std::recursive_mutex recordMutex;
265  std::recursive_mutex descriptionMutex;
267  /* Control Variables */
271 
275 
278 
281 
286 
292 
293  /*
294  A condition variable used when we're waiting for interaction to
295  complete
296  */
299  std::condition_variable interactionCond;
300  std::mutex interactionMutex;
301 
302 
303  /* Summary variables */
307 
308  std::shared_ptr<SIIterBot_callback> callback;
309  };
310 
312 #if defined(INTERACTIVE_ITERATION) && ! defined(WITHOUT_DBUS)
313  : private dbus::address,
314  private edu::nrao::casa::SynthesisImager_adaptor,
315  public DBus::IntrospectableAdaptor,
316  public DBus::ObjectAdaptor
317 #endif
318  {
319  public:
320  SIIterBot_adaptor( std::shared_ptr<SIIterBot_state> state, const std::string &bus_name, const std::string &object_path );
322 
323  bool incrementController( ) { return state->incrementController( ); }
324  bool decrementController( ) { return state->decrementController( ); }
325 
326  void interactionRequired( const bool &val ) {
327 #ifdef INTERACTIVE_ITERATION
328  edu::nrao::casa::SynthesisImager_adaptor::interactionRequired( val );
329 #else
330  (void)val; // To get the compiler to not warn...
331 #endif
332  }
333 #if defined(WITHOUT_DBUS)
334  void controlUpdate(const std::map< std::string, casac::variant >& newParams)
335  {
336  state->controlUpdate(newParams);
337  }
338 #else
339  void controlUpdate(const std::map< std::string, ::DBus::Variant >& newParams)
340  {
341 #ifdef INTERACTIVE_ITERATION
342  state->controlUpdate(newParams);
343 #else
344  (void)newParams;// to avoid compiler warning
345 
346 #endif
347  }
348 #endif
350  { state->interactionComplete( ); }
351  void changePauseFlag(const bool& pauseState)
352  { state->changePauseFlag(pauseState); }
353  void changeStopFlag(const bool& stopState)
354  { state->changeStopFlag(stopState); }
355  void changeInteractiveMode(const bool& interactiveMode)
356  { state->changeInteractiveMode(interactiveMode); }
357  std::string getDescription( )
358  { return state->getDescription( ); }
359 #if defined(WITHOUT_DBUS)
360  std::map< std::string, casac::variant > getDetails( )
361  {
362  return state->getDetails( );
363  }
364  casac::variant getSummary( )
365  { return state->getSummary( ); }
366 
367 #else
368  std::map< std::string, ::DBus::Variant > getDetails( )
369  {
370 #ifdef INTERACTIVE_ITERATION
371  return state->getDetails( );
372 #else
373  return std::map< std::string, ::DBus::Variant >( );
374 #endif
375  }
376  ::DBus::Variant getSummary( )
377  { return state->getSummary( ); }
378 
379 #endif
380  private:
381  std::shared_ptr<SIIterBot_state> state;
382 
383  };
384 
385 } //# NAMESPACE CASA - END
386 
387 #endif /* FLAGDATAHANDLER_H_ */
void changeNiter(casacore::Int niter)
void mergeSubIterBot(SISubIterBot&amp; subIterBot);
casacore::Int getMajorCycleCount()
casacore::Bool itsUpdatedModelFlag
Definition: SIIterBot.h:285
casacore::Float readThreshold(casacore::Record recordIn, casacore::String id)
casacore::Float itsMinPsfFraction
Definition: SIIterBot.h:235
virtual void mergeCycleInitializationRecord(casacore::Record &)
casacore::Float itsInteractiveThreshold
Definition: SIIterBot.h:274
casacore::Bool itsStopFlag
Definition: SIIterBot.h:282
int Int
Definition: aipstype.h:50
virtual casacore::Record getDetailsRecord()
virtual void mergeCycleExecutionRecord(casacore::Record &)
casacore::Bool itsInteractiveMode
Definition: SIIterBot.h:284
casacore::Float itsMaxPsfFraction
Definition: SIIterBot.h:236
std::condition_variable interactionCond
Definition: SIIterBot.h:299
#define private
Definition: miriad.h:68
casacore::Float itsNsigmaThreshold
Definition: SIIterBot.h:249
casacore::Float itsPrevPeakResidual
Definition: SIIterBot.h:239
void changeStopFlag(const bool &stopState)
Definition: SIIterBot.h:353
void changeStopFlag(const bool &stopEnabled)
casacore::Float itsNsigma
Definition: SIIterBot.h:248
casacore::Float itsPeakResidual
Definition: SIIterBot.h:238
casacore::Int itsIterDone
Definition: SIIterBot.h:287
std::recursive_mutex recordMutex
Definition: SIIterBot.h:264
void changeCycleThreshold(casacore::Float cyclethreshold)
void changeMinPsfFraction(casacore::Float minpsffraction)
casacore::Float itsCycleThreshold
Definition: SIIterBot.h:273
virtual void waitForInteractiveInput()
void addSummaryMajor()
casacore::Int getRemainingNiter(); casacore::Int getCompletedNiter();
casacore::Float itsInitPeakResidual
Definition: SIIterBot.h:240
void incrementMajorCycleCount()
casacore::Record getSubIterBotRecord();
void changeInteractiveNiter(casacore::Int interactiveniter)
if(msa.ok())
Definition: MsAverager.h:85
::DBus::Variant getSummary()
Definition: SIIterBot.h:376
void changeThreshold(casacore::Float threshold)
casacore::Bool itsIsCycleThresholdAuto
Definition: SIIterBot.h:276
casacore::Float itsMinPeakResidualNoMask
Definition: SIIterBot.h:246
casacore::Int itsCycleNiter
Definition: SIIterBot.h:269
void changePauseFlag(const bool &pauseState)
Definition: SIIterBot.h:351
casacore::Bool itsIsThresholdAuto
Definition: SIIterBot.h:277
casacore::Float itsMaxPsfSidelobe
Definition: SIIterBot.h:237
void changeCycleFactor(casacore::Float cyclefactor)
virtual bool interactiveInputRequired()
void setDescription(const std::string &value)
casacore::Float itsMaskSum
Definition: SIIterBot.h:253
casacore::Float itsMadRMS
Definition: SIIterBot.h:251
casacore::Int itsMaxCycleIterDone
Definition: SIIterBot.h:289
void changeInteractiveThreshold(casacore::Float cyclethreshold)
std::recursive_mutex descriptionMutex
Definition: SIIterBot.h:265
casacore::Float itsLoopGain
Definition: SIIterBot.h:280
void changePauseFlag(const bool &pauseEnabled)
casacore::Int itsNSummaryFields
Definition: SIIterBot.h:304
void setControlsFromRecord(casacore::Record &recordIn)
casacore::Int itsStopCode
Definition: SIIterBot.h:291
virtual int cleanComplete(casacore::Bool lastcyclecheck=casacore::False)
virtual bool majorCycleRequired(casacore::Float currentPeakResidual);
void controlUpdate(const std::map< std::string,::DBus::Variant > &newParams)
Definition: SIIterBot.h:339
SIIterBot_state & operator=(const SIIterBot_state &)
casacore::Float itsMinPeakResidual
Definition: SIIterBot.h:241
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
SIIterBot_adaptor * adaptor
Definition: SIIterBot.h:78
casacore::Int itsInteractiveIterDone
Definition: SIIterBot.h:288
float Float
Definition: aipstype.h:54
SIIterBot_state(const SIIterBot_state &)
make SIIterBot_state uncopyable...
const Bool False
Definition: aipstype.h:44
void printOut(casacore::String prefix, casacore::Bool verbose)
casacore::Array< casacore::Int > itsSummaryMajor
Definition: SIIterBot.h:306
std::string itsDescription
Definition: SIIterBot.h:233
virtual void mergeMinorCycleSummary(const casacore::Array< casacore::Double > &summary)
std::recursive_mutex mutex
Definition: SIIterBot.h:77
casacore::Float itsMinorCyclePeakResidual
Definition: SIIterBot.h:242
casacore::Int itsInteractiveNiter
Definition: SIIterBot.h:270
std::map< std::string,::DBus::Variant > getDetails()
Definition: SIIterBot.h:368
void changeNsigma(casacore::Float nsigma)
void acceptCallbacks(SIIterBot_adaptor *siba)
Definition: SIIterBot.h:96
void denyCallbacks(SIIterBot_adaptor *siba)
Definition: SIIterBot.h:97
void addHandler(SIIterBot_adaptor *)
casacore::Bool itsPauseFlag
Definition: SIIterBot.h:283
casacore::Float itsPeakResidualNoMask
Definition: SIIterBot.h:244
void changeMaxPsfFraction(casacore::Float maxpsffraction)
void changeInteractiveMode(const bool &interactiveEnabled)
casacore::Float itsThreshold
Definition: SIIterBot.h:272
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void changeInteractiveMode(const bool &interactiveMode)
Definition: SIIterBot.h:355
void changeLoopGain(casacore::Float loopgain)
casacore::Float itsPrevPeakResidualNoMask
Definition: SIIterBot.h:245
casacore::Float itsCycleFactor
Definition: SIIterBot.h:279
std::shared_ptr< SIIterBot_state > state
Definition: SIIterBot.h:381
std::shared_ptr< SIIterBot_callback > callback
Definition: SIIterBot.h:308
std::mutex interactionMutex
Definition: SIIterBot.h:300
casacore::Int itsPrevMajorCycleCount
Definition: SIIterBot.h:255
void removeHandler(SIIterBot_adaptor *)
std::string getDescription()
casacore::Int itsNiter
protects itsDescription
Definition: SIIterBot.h:268
void changeCycleNiter(casacore::Int cycleniter)
std::string getDescription()
Definition: SIIterBot.h:357
void interactionRequired(const bool &val)
Definition: SIIterBot.h:326
casacore::Array< casacore::Double > itsSummaryMinor
Definition: SIIterBot.h:305
virtual casacore::Record getMinorCycleControls()
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
START *virtual casacore::Record getSummaryRecord()
Functions for runtime parameter modification.
casacore::Int itsMajorDone
Definition: SIIterBot.h:290
void interactionRequired(bool)
DBus::Variant getSummary()
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42