TECA
teca_threaded_programmable_algorithm.h
1 #ifndef teca_threaded_programmable_algorithm_h
2 #define teca_threaded_programmable_algorithm_h
3 
4 #include "teca_metadata.h"
5 #include "teca_threaded_algorithm.h"
6 #include "teca_dataset_fwd.h"
7 
8 #include "teca_programmable_algorithm_fwd.h"
9 
11 
67 {
68 public:
69  TECA_ALGORITHM_STATIC_NEW(teca_threaded_programmable_algorithm)
70  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_threaded_programmable_algorithm)
72 
73  // set/get the class name.
74  virtual int set_name(const std::string &name);
75 
76  const char *get_class_name() const override
77  { return this->class_name; }
78 
79  // set the number of input and outputs
80  using teca_algorithm::set_number_of_input_connections;
81  using teca_algorithm::set_number_of_output_ports;
82 
83  // set the number of threads. The default is -1.
84  using teca_threaded_algorithm::set_thread_pool_size;
85 
86  // set the stream size. the default -1 disables streaming.
87  // you should set this (2 is a good choice) if your algorithm
88  // can stream data.
89  using teca_threaded_algorithm::set_stream_size;
90 
91  // install the default implementation
92  void use_default_report_action();
93  void use_default_request_action();
94  void use_default_execute_action();
95 
96  // set callback that responds to reporting stage
97  // of pipeline execution. the report callback must
98  // be callable with signature:
99  //
100  // teca_metadata (unsigned int,
101  // const std::vector<teca_metadata> &)
102  //
103  // the default implementation forwards downstream
104  TECA_ALGORITHM_CALLBACK_PROPERTY(
105  report_callback_t, report_callback)
106 
107  // set the callback that responds to the requesting
108  // stage of pipeline execution. the request callback
109  // must be callable with the signature:
110  //
111  // std::vector<teca_metadata> (
112  // unsigned int,
113  // const std::vector<teca_metadata> &,
114  // const teca_metadata &)
115  //
116  // the default implementation forwards upstream
117  TECA_ALGORITHM_CALLBACK_PROPERTY(
118  request_callback_t, request_callback)
119 
120  // set the callback that responds to the execution stage
121  // of pipeline execution. the execute callback must be
122  // callable with the signature:
123  //
124  // const_p_teca_dataset (
125  // unsigned int, const std::vector<const_p_teca_dataset> &,
126  // const teca_metadata &, int)
127  //
128  // the default implementation returns a nullptr
129  TECA_ALGORITHM_CALLBACK_PROPERTY(
130  threaded_execute_callback_t, execute_callback)
131 
132 protected:
134 
135 private:
136  teca_metadata get_output_metadata(unsigned int port,
137  const std::vector<teca_metadata> &input_md) override;
138 
139  std::vector<teca_metadata> get_upstream_request(
140  unsigned int port,
141  const std::vector<teca_metadata> &input_md,
142  const teca_metadata &request) override;
143 
144  const_p_teca_dataset execute(unsigned int port,
145  const std::vector<const_p_teca_dataset> &input_data,
146  const teca_metadata &request, int streaming) override;
147 
148 protected:
149  report_callback_t report_callback;
150  request_callback_t request_callback;
151  threaded_execute_callback_t execute_callback;
152  char class_name[64];
153 };
154 
155 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_threaded_programmable_algorithm
an algorithm implemented with user provided callbacks
Definition: teca_threaded_programmable_algorithm.h:67
teca_threaded_algorithm
Definition: teca_threaded_algorithm.h:34