COPASI API  4.16.103
CCopasiTask.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CCopasiTask class.
17  * This class is used to describe a task in COPASI. This class is
18  * intended to be used as the parent class for all tasks whithin COPASI.
19  *
20  * Created for Copasi by Stefan Hoops 2003
21  */
22 
23 #ifndef COPASI_CCopasiTask
24 #define COPASI_CCopasiTask
25 
26 #include <string>
27 
29 
31 #include "report/CReport.h"
32 
33 class CCopasiProblem;
34 class CCopasiMethod;
36 class CProcessReport;
37 class CState;
38 
40 {
41 public:
42  /**
43  * Enumeration of the types of tasks known to COPASI.
44  */
45  enum Type
46  {
53  mca,
59  lna,
61  };
62 
63  /**
64  * String literals for the GUI to display type names of tasks known
65  * to COPASI.
66  */
67  static const std::string TypeName[];
68 
69  /**
70  * XML type names of tasks known to COPASI.
71  */
72  static const char* XMLType[];
73 
74  /**
75  * The methods which can be selected for performing this task.
76  */
77  static const unsigned int ValidMethods[];
78 
79  /**
80  * Check whether the given method is in the list of valid methods
81  * This list must end with CCopasiMethod::unset
82  * @param const unsigned int & method
83  * @param const unsigned int * validMethods
84  * @return bool isValid
85  */
86  static bool isValidMethod(const unsigned int & method,
87  const unsigned int * validMethods);
88 
90  {
91  INITIALIZE = 0x01,
92  STREAM = 0x02,
93  FINISH = 0x04,
94  REPORT = 0x10,
95  PLOT = 0x20,
96  TIME_SERIES = 0x40
97  };
98 
100  {
101  //do no output
105  //do output except time series, but do not initialize/finish
107  //do output, including initialization and closing
110  // only do time series
112  };
113 
115  {
116  public:
117  /**
118  * Default constructor
119  */
120  CDescription(const CCopasiContainer * pParent = NULL);
121 
122  /**
123  * Copy constructor
124  * @param const CDescription & src
125  * @param const CCopasiContainer * pParent (default: NULL)
126  */
127  CDescription(const CDescription & src,
128  const CCopasiContainer * pParent = NULL);
129 
130  /**
131  * Destructor
132  */
133  virtual ~CDescription();
134 
135  /**
136  * This is the output method for any object. The default implementation
137  * provided with CCopasiObject uses the ostream operator<< of the object
138  * to print the object.To overide this default behaviour one needs to
139  * reimplement the virtual print function.
140  * @param std::ostream * ostream
141  */
142  virtual void print(std::ostream * ostream) const;
143 
144  /**
145  * Output stream operator
146  * @param ostream & os
147  * @param const CDescription & A
148  * @return ostream & os
149  */
150  friend std::ostream &operator<<(std::ostream &os, const CDescription & o);
151  };
152 
153  class CResult: public CCopasiObject
154  {
155  public:
156  /**
157  * Default constructor
158  */
159  CResult(const CCopasiContainer * pParent = NULL);
160 
161  /**
162  * Copy constructor
163  * @param const CResult & src
164  * @param const CCopasiContainer * pParent (default: NULL)
165  */
166  CResult(const CResult & src,
167  const CCopasiContainer * pParent = NULL);
168 
169  /**
170  * Destructor
171  */
172  virtual ~CResult();
173 
174  /**
175  * This is the output method for any object. The default implementation
176  * provided with CCopasiObject uses the ostream operator<< of the object
177  * to print the object.To overide this default behaviour one needs to
178  * reimplement the virtual print function.
179  * @param std::ostream * ostream
180  */
181  virtual void print(std::ostream * ostream) const;
182 
183  /**
184  * Output stream operator
185  * @param ostream & os
186  * @param const CResult & A
187  * @return ostream & os
188  */
189  friend std::ostream &operator<<(std::ostream &os, const CResult & o);
190  };
191 
192  // Attributes
193 protected:
194  /**
195  * The type of the task
196  */
198 
199  /**
200  * The key of the task
201  */
202  std::string mKey;
203 
204  /**
205  * The description of the task.
206  */
208 
209  /**
210  * The result of the task.
211  */
213 
214  /**
215  * Tells whether the task is scheduled for execution
216  */
218 
219  /**
220  * Tells whether the task shall update the model with the result.
221  * The restore method must act accordingly.
222  */
224 
225  /**
226  * The state of the model before execution of the task. If mUpdateModel
227  * is false this state is restored.
228  */
230 
231  /**
232  * The problem of the task
233  */
235 
236  /**
237  * The method used to solve the problem.
238  */
240 
241  /**
242  * The report that belongs to this specific task
243  */
245 
246  /**
247  * progress bar handler
248  */
250 
251  /**
252  * Pointer to group of sliders associated with the task.
253  */
255 
256 public:
257  /**
258  * Default constructor
259  */
260  CCopasiTask(const std::string & name = "NoName",
261  const CCopasiContainer * pParent = NULL,
262  const std::string & type = "Task");
263 
264  /**
265  * Specific constructor
266  * @param const Type & taskType
267  * @param const CCopasiContainer * pParent (default: NULL)
268  * @param const std::string & type (default: "Task")
269  */
270  CCopasiTask(const Type & taskType,
271  const CCopasiContainer * pParent = NULL,
272  const std::string & type = "Task");
273 
274  /**
275  * Copy constructor
276  * @param const CCopasiTask & src
277  * @param const CCopasiContainer * pParent (default: NULL)
278  */
279  CCopasiTask(const CCopasiTask & src,
280  const CCopasiContainer * pParent = NULL);
281 
282  /**
283  * Destructor
284  */
285  virtual ~CCopasiTask();
286 
287  /**
288  * Retrieve the type of the task
289  * @return CCopasiTask::Type type
290  */
291  Type getType() const;
292 
293  /**
294  * Set the type of the task
295  * @param CCopasiTask::Type & type
296  */
297  void setType(const Type & type);
298 
299  /**
300  * Retrieve the key for the task.
301  * @return std::string key
302  */
303  virtual const std::string & getKey() const;
304 
305  /**
306  * Set whether the task is scheduled
307  * @param const bool & scheduled
308  */
309  void setScheduled(const bool & scheduled);
310 
311  /**
312  * Check whether the task is scheduled
313  * @return const bool & scheduled
314  */
315  const bool & isScheduled() const;
316 
317  /**
318  * Set whether the task must update the model
319  * @param const bool & updateModel
320  */
321  void setUpdateModel(const bool & updateModel);
322 
323  /**
324  * Check whether the task must update the model
325  * @return const bool & updateModel
326  */
327  const bool & isUpdateModel() const;
328 
329  /**
330  * Set the call back of the task
331  * @param CProcessReport * pCallBack
332  * @result bool success
333  */
334  virtual bool setCallBack(CProcessReport * pCallBack);
335 
336  CProcessReport * getCallBack() const;
337 
338  /**
339  * Resizes result matrices and updates array annotations for a specific task.
340  * For now this will be hard coded in the respective derived classes.
341  * We may introduce a more generic mechanism for this in the future.
342  * This is used when we need to know about the data structures of a task result
343  * without actually performing the task, e.g. when selecting objects for output.
344  * For now we assume that this functionality is also performed when
345  * initialize() is called.
346  */
347  virtual bool updateMatrices() {return true;};
348 
349  /**
350  * Initialize the task. If an ostream is given this ostream is used
351  * instead of the target specified in the report. This allows nested
352  * tasks to share the same output device.
353  * @param const OutputFlag & of
354  * @param COutputHandler * pOutputHandler
355  * @param std::ostream * pOstream (default: NULL)
356  * @return bool success
357  */
358  virtual bool initialize(const OutputFlag & of,
359  COutputHandler * pOutputHandler,
360  std::ostream * pOstream);
361 
362  /**
363  * Process the task with or without initializing to the initial state.
364  * @param const bool & useInitialValues
365  * @return bool success
366  */
367  virtual bool process(const bool & useInitialValues);
368 
369 #ifndef SWIG
370  // used by language bindings to hold last process warnings / errors
371  // however, swig stumbles over this if it sees it here
372  std::string Error;
373  std::string Warning;
374 #endif // SWIG
375 
376  /**
377  * Perform necessary cleanup procedures
378  */
379  virtual bool restore();
380 
381  /**
382  * Retrieve the problem
383  */
385 
386  /**
387  * Retrieve the problem
388  */
389  const CCopasiProblem * getProblem() const;
390 
391  /**
392  * Set the method type applied to solve the task
393  * @param const CCopasiMethod::SubType & type
394  * @return bool success
395  */
396  virtual bool setMethodType(const int & type);
397 
398  /**
399  * Create a method of the specified type to solve the task.
400  * It is the duty of the caller to release the CCopasiMethod.
401  * @param const CCopasiMethod::SubType & type
402  * @return CCopasiMethod *
403  */
404  virtual CCopasiMethod * createMethod(const int & type) const;
405 
406  /**
407  * Retrieve the method
408  */
410 
411  /**
412  * Retrieve the method
413  */
414  const CCopasiMethod * getMethod() const;
415 
416  /**
417  * Retrieve the report
418  */
419  CReport & getReport();
420 
421  /**
422  * Retrieve the description
423  */
424  const CDescription & getDescription() const;
425 
426  /**
427  * Retrieve the result
428  */
429  const CResult & getResult() const;
430 
431  /**
432  * Cleanup function
433  **/
434  void cleanup();
435 
436  /**
437  * Retrieve a pointer to the group of sliders.
438  * @return CCopasiParameterGroup * pSliders
439  */
441 
442  //the following methods are wrappers for doing output. They are intended
443  //to hide the fact that output is done using different mechanisms, e.g. reports and plots
444 
445  /**
446  * Perform an output event for the current activity
447  * @param const Activity & activity
448  */
449  virtual void output(const COutputInterface::Activity & activity);
450 
451  /**
452  * Introduce an additional separator into the output
453  * @param const Activity & activity
454  */
455  virtual void separate(const COutputInterface::Activity & activity);
456 
457  inline const OutputFlag & getOutputMode() const
458  {return mDoOutput;};
459 
461 
462 protected:
466 
467 private:
468  void initObjects();
469 };
470 
471 #endif // COPASI_CCopasiTask
CResult mResult
Definition: CCopasiTask.h:212
virtual ~CCopasiTask()
virtual bool setCallBack(CProcessReport *pCallBack)
CCopasiMethod * mpMethod
Definition: CCopasiTask.h:239
friend std::ostream & operator<<(std::ostream &os, const CDescription &o)
virtual void print(std::ostream *ostream) const
void setScheduled(const bool &scheduled)
virtual void separate(const COutputInterface::Activity &activity)
static const std::string TypeName[]
Definition: CCopasiTask.h:67
CCopasiProblem * getProblem()
virtual bool initialize(const OutputFlag &of, COutputHandler *pOutputHandler, std::ostream *pOstream)
static const unsigned int ValidMethods[]
Definition: CCopasiTask.h:77
const bool & isUpdateModel() const
CDescription(const CCopasiContainer *pParent=NULL)
bool mScheduled
Definition: CCopasiTask.h:217
void cleanup()
CCopasiTask(const std::string &name="NoName", const CCopasiContainer *pParent=NULL, const std::string &type="Task")
CProcessReport * mpCallBack
Definition: CCopasiTask.h:249
void setType(const Type &type)
Definition: CState.h:305
CCopasiParameterGroup * getSliders()
const bool & isScheduled() const
CProcessReport * getCallBack() const
virtual void output(const COutputInterface::Activity &activity)
CReport mReport
Definition: CCopasiTask.h:244
#define C_INT32
Definition: copasi.h:90
CState * mpInitialState
Definition: CCopasiTask.h:229
CCopasiProblem * mpProblem
Definition: CCopasiTask.h:234
static const char * XMLType[]
Definition: CCopasiTask.h:72
OutputFlag mDoOutput
Definition: CCopasiTask.h:463
std::string mKey
Definition: CCopasiTask.h:202
virtual bool updateMatrices()
Definition: CCopasiTask.h:347
const CDescription & getDescription() const
std::string Error
Definition: CCopasiTask.h:372
virtual bool setMethodType(const int &type)
bool mUpdateModel
Definition: CCopasiTask.h:223
Header file of class CCopasiContainer.
unsigned C_INT32 mOutputCounter
Definition: CCopasiTask.h:465
CCopasiParameterGroup * mpSliders
Definition: CCopasiTask.h:254
CDescription mDescription
Definition: CCopasiTask.h:207
const OutputFlag & getOutputMode() const
Definition: CCopasiTask.h:457
virtual bool process(const bool &useInitialValues)
CCopasiMethod * getMethod()
CReport & getReport()
const CResult & getResult() const
virtual const std::string & getKey() const
std::string Warning
Definition: CCopasiTask.h:373
virtual void print(std::ostream *ostream) const
Type getType() const
static bool isValidMethod(const unsigned int &method, const unsigned int *validMethods)
Definition: CCopasiTask.cpp:89
virtual CCopasiMethod * createMethod(const int &type) const
COutputHandler * getOutputHandler() const
CResult(const CCopasiContainer *pParent=NULL)
friend std::ostream & operator<<(std::ostream &os, const CResult &o)
COutputHandler * mpOutputHandler
Definition: CCopasiTask.h:464
virtual bool restore()
void setUpdateModel(const bool &updateModel)
void initObjects()