|
TECA
The Toolkit for Extreme Climate Analysis
|
1 #ifndef teca_algorithm_h
2 #define teca_algorithm_h
4 #include "teca_config.h"
6 #include "teca_dataset.h"
7 #include "teca_algorithm_executive.h"
8 #include "teca_metadata.h"
15 #include <initializer_list>
18 class teca_algorithm_internals;
23 using teca_algorithm_output_port
24 = std::pair<p_teca_algorithm, unsigned int>;
28 p_teca_algorithm &
get_algorithm(teca_algorithm_output_port &op)
33 unsigned int &
get_port(teca_algorithm_output_port &op)
40 #define TECA_ALGORITHM_STATIC_NEW(T) \
45 return p_##T(new T); \
49 std::shared_ptr<T> shared_from_this() \
51 return std::static_pointer_cast<T>( \
52 teca_algorithm::shared_from_this()); \
56 std::shared_ptr<T const> shared_from_this() const \
58 return std::static_pointer_cast<T const>( \
59 teca_algorithm::shared_from_this()); \
62 #define TECA_ALGORITHM_CLASS_NAME(T) \
64 const char *get_class_name() const override \
72 #define TECA_ALGORITHM_DELETE_COPY_ASSIGN(T) \
74 T(const T &src) = delete; \
75 T(T &&src) = delete; \
77 T &operator=(const T &src) = delete; \
78 T &operator=(T &&src) = delete;
84 #define TECA_ALGORITHM_PROPERTY(T, NAME) \
87 void set_##NAME(const T &v) \
89 if (this->NAME != v) \
92 this->set_modified(); \
97 const T &get_##NAME() const \
108 #define TECA_ALGORITHM_PROPERTY_V(T, NAME) \
111 void set_##NAME(const T &v) \
113 if (this->validate_ ## NAME (v)) \
116 if (this->NAME != v) \
119 this->set_modified(); \
124 const T &get_##NAME() const \
133 #define TECA_ALGORITHM_VECTOR_PROPERTY(T, NAME) \
136 size_t get_number_of_##NAME##s () \
138 return this->NAME##s.size(); \
142 void append_##NAME(const T &v) \
144 this->NAME##s.push_back(v); \
145 this->set_modified(); \
149 void set_##NAME(size_t i, const T &v) \
151 if (this->NAME##s[i] != v) \
153 this->NAME##s[i] = v; \
154 this->set_modified(); \
159 void set_##NAME##s(const std::vector<T> &v) \
161 if (this->NAME##s != v) \
164 this->set_modified(); \
169 void set_##NAME##s(const std::initializer_list<T> &&l) \
171 std::vector<T> v(l); \
172 if (this->NAME##s != v) \
175 this->set_modified(); \
180 const T &get_##NAME(size_t i) const \
182 return this->NAME##s[i]; \
186 const std::vector<T> &get_##NAME##s() const \
188 return this->NAME##s; \
192 void clear_##NAME##s() \
194 this->NAME##s.clear(); \
199 bool operator!=(
const std::function<T> &lhs,
const std::function<T> &rhs)
208 #define TECA_ALGORITHM_CALLBACK_PROPERTY(T, NAME) \
211 void set_##NAME(const T &v) \
216 this->set_modified(); \
221 const T &get_##NAME() const \
262 #if defined(TECA_HAS_BOOST)
267 virtual void get_properties_description(
const std::string &prefix,
268 options_description &opts);
274 virtual void set_properties(
const std::string &prefix,
275 variables_map &opts);
283 TECA_ALGORITHM_PROPERTY(
int, verbose)
299 const teca_algorithm_output_port &port);
319 void pop_cache(
unsigned int port = 0,
int top = 0);
328 virtual int update(
unsigned int port);
343 virtual void to_stream(std::ostream &s)
const;
386 const std::vector<teca_metadata> &input_md);
395 unsigned int port,
const std::vector<teca_metadata> &input_md,
406 const_p_teca_dataset
execute(
unsigned int port,
407 const std::vector<const_p_teca_dataset> &input_data,
430 teca_algorithm_output_port ¤t);
436 const_p_teca_dataset request_data(
437 teca_algorithm_output_port &port,
488 teca_algorithm_internals *internals;
491 friend class teca_data_request;
virtual teca_metadata update_metadata(unsigned int port=0)
get meta data considering this instance up.
virtual void clear_modified(teca_algorithm_output_port current)
void clear_cache(unsigned int port)
clear the cache on the given output port
virtual std::vector< teca_metadata > get_upstream_request(unsigned int port, const std::vector< teca_metadata > &input_md, const teca_metadata &request)
MPI_Comm get_communicator()
get the active communicator
void clear_input_connections()
remove all input connections
teca_algorithm_output_port & get_input_connection(unsigned int i)
virtual teca_metadata get_output_metadata(unsigned int port, const std::vector< teca_metadata > &input_md)
void set_executive(p_teca_algorithm_executive exe)
set the executive
virtual const char * get_class_name() const =0
return the name of the class.
int cache_output_data(unsigned int port, const teca_metadata &request, const_p_teca_dataset &data)
virtual void to_stream(std::ostream &s) const
virtual void from_stream(std::istream &s)
deserialize from the stream.
virtual teca_algorithm_output_port get_output_port(unsigned int port=0)
void pop_cache(unsigned int port=0, int top=0)
virtual void set_modified()
virtual const_p_teca_dataset execute(unsigned int port, const std::vector< const_p_teca_dataset > &input_data, const teca_metadata &request)
virtual void remove_input_connection(unsigned int id)
remove input connections
void set_communicator(MPI_Comm comm)
p_teca_algorithm_executive get_executive()
get the executive
void set_cache_size(unsigned int n)
set the cache size. the default is 1. (threadsafe)
virtual int update()
execute the pipeline from this instance up.
unsigned int & get_port(teca_algorithm_output_port &op)
get port number from the output port
Definition: teca_algorithm_output_port.h:17
void set_input_connection(const teca_algorithm_output_port &port)
set an input to this algorithm
Definition: teca_algorithm.h:293
p_teca_algorithm & get_algorithm(teca_algorithm_output_port &op)
get the algorithm from the output port
Definition: teca_algorithm_output_port.h:12
int get_modified(unsigned int port) const
return the output port's modified flag value
void set_number_of_input_connections(unsigned int n)
virtual int validate_cache(teca_algorithm_output_port ¤t)
const_p_teca_dataset get_output_data(unsigned int port=0)
unsigned int get_number_of_input_connections()
get the number of input connections
This is the base class defining a threaded algorithm.
Definition: teca_threaded_algorithm.h:46
virtual teca_metadata get_cache_key(unsigned int port, const teca_metadata &request) const
The interface to TECA pipeline architecture.
Definition: teca_algorithm.h:237
void set_number_of_output_ports(unsigned int n)