Operation.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2002 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // dspsr/Kernel/Classes/dsp/Operation.h
10 
11 #ifndef __Operation_h
12 #define __Operation_h
13 
14 #include "dsp/dsp.h"
15 
16 #include "RealTimer.h"
17 #include "OwnStream.h"
18 #include "environ.h"
19 
20 #include <string>
21 #include <vector>
22 
23 namespace dsp {
24 
25  class Scratch;
26  class Extensions;
27 
29 
32  class Operation : public OwnStream {
33 
34  public:
35 
37  static bool record_time;
38 
40  static bool report_time;
41 
43  static bool verbose;
44 
46  static int operation_status;
47 
49  static bool check_state;
50 
53  static int instantiation_count;
54 
56  Operation (const char* name);
57 
59  Operation (const Operation&);
60 
62  virtual ~Operation ();
63 
66  virtual bool operate ();
67 
69 
70  virtual void prepare ();
71 
73 
74  virtual void reserve ();
75 
77  virtual void add_extensions (Extensions*);
78 
80 
81  virtual void combine (const Operation*);
82 
84  virtual void report () const;
85 
87  virtual void reset ();
88 
90  std::string get_name() const { return name; }
91 
93  double get_total_time () const;
94 
96  double get_elapsed_time() const;
97 
99  virtual uint64_t get_total_weights () const;
100 
102  virtual uint64_t get_discarded_weights () const;
103 
105  int get_id() { return id; }
106 
108  enum Function
109  {
110  Producer,
111  Procedural,
112  Structural
113  };
114 
116  virtual Function get_function () const { return Procedural; }
117 
119  virtual double get_delay_time () const { return 0.0; }
120 
122  virtual void set_scratch (Scratch*);
123  bool scratch_was_set () const;
124 
126  virtual uint64_t bytes_storage() const { return 0; }
127 
129 
130  virtual uint64_t bytes_scratch () const { return 0; }
131 
132  protected:
133 
136  bool set_scratch_called;
137 
139  virtual bool can_operate();
140 
142  virtual void operation () = 0;
143 
145  virtual void set_name (const std::string& _name){ name = _name; }
146 
148  std::string name;
149 
151  uint64_t discarded_weights;
152 
154  uint64_t total_weights;
155 
157  int timers_index (const std::string& op_name);
158 
160  RealTimer optime;
161 
163  int id;
164 
166  bool prepared;
167 
168  };
169 
170 }
171 
172 #endif
static int instantiation_count
Counts how many Operation instantiations there have been Used for setting the unique instantiation ID...
Definition: Operation.h:58
virtual void reset()
Reset accumulated results to intial values.
Definition: Operation.C:161
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual uint64_t bytes_storage() const
The number of bytes of additional storage used by the operation.
Definition: Operation.h:131
virtual bool can_operate()
Return false if the operation doesn't have enough data to proceed.
Definition: Operation.C:72
virtual void combine(const Operation *)
Combine accumulated results with another operation.
Definition: Operation.C:149
virtual void add_extensions(Extensions *)
Add any extensions.
Definition: Operation.C:86
virtual uint64_t get_total_weights() const
Return the total number of timesample weights encountered.
Definition: Operation.C:132
virtual Function get_function() const
Get the function classification of this operation.
Definition: Operation.h:121
uint64_t discarded_weights
Number of time sample weights encountered that are flagged invalid.
Definition: Operation.h:156
int timers_index(const std::string &op_name)
Returns the index in the 'timers' array of a particular timer.
virtual ~Operation()
Virtual destructor.
Definition: Operation.C:66
Operation(const char *name)
All sub-classes must specify a unique name.
Definition: Operation.C:46
virtual void report() const
Report operation statistics.
Definition: Operation.C:168
std::string name
Operation name.
Definition: Operation.h:153
Scratch * scratch
Shared scratch space, if needed.
Definition: Operation.h:140
static bool record_time
Global flag enables stopwatch to record the time spent operating.
Definition: Operation.h:42
Scratch space that can be shared between Operations.
Definition: Scratch.h:27
virtual void set_scratch(Scratch *)
Set the scratch space.
Definition: Operation.C:137
virtual void set_name(const std::string &_name)
Set the name!
Definition: Operation.h:150
std::string get_name() const
Return the unique name of this operation.
Definition: Operation.h:95
virtual double get_delay_time() const
Get the time delay of this operation, if any, in seconds.
Definition: Operation.h:124
Defines the interface by which operations are performed on data.
Definition: Operation.h:37
static bool report_time
Global flag enables report of time spent in operation on descruction.
Definition: Operation.h:45
uint64_t total_weights
Total number of time sample weights encountered.
Definition: Operation.h:159
virtual bool operate()
Call this method to operate on data Returns false on failure.
Definition: Operation.C:90
virtual void operation()=0
Perform operation on data. Defined by derived classes.
virtual uint64_t get_discarded_weights() const
Return the number of invalid timesample weights encountered.
Definition: Operation.C:126
double get_elapsed_time() const
Get the time spent in the last invocation of operate()
Definition: Operation.C:120
virtual uint64_t bytes_scratch() const
The number of bytes of scratch space used by the operation.
Definition: Operation.h:135
static bool verbose
Global verbosity flag.
Definition: Operation.h:48
virtual void prepare()
Prepare for data operations.
Definition: Operation.C:77
virtual void reserve()
Reserve the maximum amount of memory required.
Definition: Operation.C:82
int id
Unique instantiation id.
Definition: Operation.h:168
@ Procedural
operations that produce data
Definition: Operation.h:116
RealTimer optime
Stop watch records the amount of time spent performing this operation.
Definition: Operation.h:165
@ Structural
operations that process data
Definition: Operation.h:117
static bool check_state
Operations should perform internal consistency checks.
Definition: Operation.h:54
bool prepared
Set true when preparation optimizations are completed.
Definition: Operation.h:171
int get_id()
Inquire the unique instantiation id.
Definition: Operation.h:110
Function
The function of the operator.
Definition: Operation.h:113
static int operation_status
Operations can set this to non-zero in operation() if they fail.
Definition: Operation.h:51
double get_total_time() const
Return the total time spent on this Operation in seconds.
Definition: Operation.C:115

Generated using doxygen 1.8.17