TECA
teca_programmable_reduce.h
1 #ifndef teca_programmable_reduce_h
2 #define teca_programmable_reduce_h
3 
4 #include "teca_programmable_reduce_fwd.h"
5 #include "teca_programmable_algorithm_fwd.h"
6 #include "teca_index_reduce.h"
7 #include "teca_dataset_fwd.h"
8 #include "teca_metadata.h"
9 
10 #include <string>
11 #include <vector>
12 
13 // callbacks implement a user defined reduction over time steps
22 {
23 public:
24  TECA_ALGORITHM_STATIC_NEW(teca_programmable_reduce)
25  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_programmable_reduce)
27 
28  // set the implementation name, this is used in logging to
29  // identify the specific instance of programmable redeuce
30  int set_name(const std::string &name);
31 
32  const char *get_class_name() const override
33  { return this->class_name; }
34 
35  // set the callback that initializes the output metadata during
36  // report phase of the pipeline. The callback must be a callable
37  // with the signature:
38  //
39  // teca_metadata report_callback(unsigned int port,
40  // const std::vector<teca_metadata> &input_md);
41  //
42  // the default implementation forwards downstream
43  TECA_ALGORITHM_CALLBACK_PROPERTY(report_callback_t, report_callback)
44 
45  // set the callback that initializes the upstream request.
46  // The callback must be a callable with the signature:
47  //
48  // std::vector<teca_metadata> request(
49  // unsigned int port, const std::vector<teca_metadata> &input_md,
50  // const teca_metadata &request) override;
51  //
52  // the default implementation forwards upstream
53  TECA_ALGORITHM_CALLBACK_PROPERTY(request_callback_t, request_callback)
54 
55  // set the callback that performs the reduction on 2 datasets
56  // returning the reduced dataset. The callback must be a callable
57  // with the signature:
58  //
59  // p_teca_dataset reduce(const const_p_teca_dataset &left,
60  // const const_p_teca_dataset &right);
61  //
62  // the default implementation returns a nullptr
63  TECA_ALGORITHM_CALLBACK_PROPERTY(reduce_callback_t, reduce_callback)
64 
65  // set the callback that finalizes the reduction.
66  // The callback must be a callable with the signature:
67  //
68  // p_teca_dataset reduce(const const_p_teca_dataset &ds);
69  //
70  // the default implementation passes the input dataset
71  // through
72  TECA_ALGORITHM_CALLBACK_PROPERTY(finalize_callback_t, finalize_callback)
73 
74 protected:
76 
77  // overrides
78  p_teca_dataset reduce(const const_p_teca_dataset &left,
79  const const_p_teca_dataset &right) override;
80 
81  p_teca_dataset finalize(const const_p_teca_dataset &input) override;
82 
83  std::vector<teca_metadata> initialize_upstream_request(
84  unsigned int port, const std::vector<teca_metadata> &input_md,
85  const teca_metadata &request) override;
86 
87  teca_metadata initialize_output_metadata(unsigned int port,
88  const std::vector<teca_metadata> &input_md) override;
89 
90 private:
91  reduce_callback_t reduce_callback;
92  finalize_callback_t finalize_callback;
93  request_callback_t request_callback;
94  report_callback_t report_callback;
95  char class_name[64];
96 };
97 
98 #endif
teca_programmable_reduce
Definition: teca_programmable_reduce.h:22
teca_metadata
Definition: teca_metadata.h:17
teca_index_reduce
Definition: teca_index_reduce.h:37