TECA
The Toolkit for Extreme Climate Analysis
teca_programmable_algorithm Class Reference

An algorithm implemented with user provided callbacks. More...

#include <teca_programmable_algorithm.h>

Inheritance diagram for teca_programmable_algorithm:
[legend]
Collaboration diagram for teca_programmable_algorithm:
[legend]

Public Member Functions

std::shared_ptr< teca_programmable_algorithmshared_from_this ()
 
std::shared_ptr< teca_programmable_algorithm const > shared_from_this () const
 
 teca_programmable_algorithm (const teca_programmable_algorithm &src)=delete
 
 teca_programmable_algorithm (teca_programmable_algorithm &&src)=delete
 
teca_programmable_algorithmoperator= (const teca_programmable_algorithm &src)=delete
 
teca_programmable_algorithmoperator= (teca_programmable_algorithm &&src)=delete
 
void set_number_of_input_connections (unsigned int n)
 set the number of input and outputs More...
 
void set_number_of_output_ports (unsigned int n)
 
virtual int set_name (const std::string &name)
 
const char * get_class_name () const override
 get the name differntiating this instance in the pipeline. More...
 
default actions
void use_default_report_action ()
 
void use_default_request_action ()
 
void use_default_execute_action ()
 
report_callback
void set_report_callback (const report_callback_t &v)
 
const report_callback_t & get_report_callback () const
 
report_callback_t & get_report_callback ()
 
request_callback
void set_request_callback (const request_callback_t &v)
 
const request_callback_t & get_request_callback () const
 
request_callback_t & get_request_callback ()
 
- Public Member Functions inherited from teca_algorithm
 teca_algorithm (const teca_algorithm &src)=delete
 
 teca_algorithm (teca_algorithm &&src)=delete
 
teca_algorithmoperator= (const teca_algorithm &src)=delete
 
teca_algorithmoperator= (teca_algorithm &&src)=delete
 
void set_communicator (MPI_Comm comm)
 
MPI_Comm get_communicator ()
 get the active communicator More...
 
virtual teca_algorithm_output_port get_output_port (unsigned int port=0)
 
void set_input_connection (const teca_algorithm_output_port &port)
 set an input to this algorithm More...
 
virtual void set_input_connection (unsigned int id, const teca_algorithm_output_port &port)
 set an input to this algorithm More...
 
virtual void remove_input_connection (unsigned int id)
 remove input connections More...
 
void clear_input_connections ()
 remove all input connections More...
 
const_p_teca_dataset get_output_data (unsigned int port=0)
 
void pop_cache (unsigned int port=0, int top=0)
 
void set_cache_size (unsigned int n)
 set the cache size. the default is 1. (threadsafe) More...
 
virtual int update ()
 execute the pipeline from this instance up. More...
 
virtual int update (unsigned int port)
 execute the pipeline from this instance up. More...
 
virtual teca_metadata update_metadata (unsigned int port=0)
 get meta data considering this instance up. More...
 
void set_executive (p_teca_algorithm_executive exe)
 set the executive More...
 
p_teca_algorithm_executive get_executive ()
 get the executive More...
 
virtual void to_stream (std::ostream &s) const
 
virtual void from_stream (std::istream &s)
 deserialize from the stream. More...
 
void set_verbose (const int &v)
 
const int & get_verbose () const
 

Static Public Member Functions

static p_teca_programmable_algorithm New ()
 

execute_callback

report_callback_t report_callback
 
request_callback_t request_callback
 
execute_callback_t execute_callback
 
char class_name [128]
 
void set_execute_callback (const execute_callback_t &v)
 
const execute_callback_t & get_execute_callback () const
 
execute_callback_t & get_execute_callback ()
 
 teca_programmable_algorithm ()
 
teca_metadata get_output_metadata (unsigned int port, const std::vector< teca_metadata > &input_md) override
 
std::vector< teca_metadataget_upstream_request (unsigned int port, const std::vector< teca_metadata > &input_md, const teca_metadata &request) override
 
const_p_teca_dataset execute (unsigned int port, const std::vector< const_p_teca_dataset > &input_data, const teca_metadata &request) override
 
virtual teca_metadata get_output_metadata (unsigned int port, const std::vector< teca_metadata > &input_md)
 
virtual teca_metadata get_output_metadata (teca_algorithm_output_port &current)
 

Additional Inherited Members

- Protected Member Functions inherited from teca_algorithm
void set_number_of_input_connections (unsigned int n)
 
void set_number_of_output_ports (unsigned int n)
 
virtual void set_modified ()
 
void set_modified (unsigned int port)
 an overload to set_modified by port More...
 
virtual teca_metadata get_cache_key (unsigned int port, const teca_metadata &request) const
 
virtual teca_metadata get_output_metadata (teca_algorithm_output_port &current)
 
virtual const_p_teca_dataset request_data (teca_algorithm_output_port &port, const teca_metadata &request)
 
virtual int validate_cache (teca_algorithm_output_port &current)
 
virtual void clear_modified (teca_algorithm_output_port current)
 
const_p_teca_dataset get_output_data (unsigned int port, const teca_metadata &request)
 
int cache_output_data (unsigned int port, const teca_metadata &request, const_p_teca_dataset &data)
 
void clear_cache (unsigned int port)
 clear the cache on the given output port More...
 
unsigned int get_number_of_input_connections ()
 get the number of input connections More...
 
teca_algorithm_output_portget_input_connection (unsigned int i)
 
void clear_modified (unsigned int port)
 clear the modified flag on the i'th output More...
 
int get_modified (unsigned int port) const
 return the output port's modified flag value More...
 
- Protected Attributes inherited from teca_algorithm
int verbose
 

Detailed Description

An algorithm implemented with user provided callbacks.

The user can provide a callback for each of the three phases of pipeline execution. The number of input and output ports can also be set for filters (1 or more inputs, 1 or more outputs) sources, (no inputs, 1 or more outputs), or sinks (1 or more inputs, no outputs).

  1. report phase. the report callback returns metadata describing data that can be produced. The report callback is optional. It's only needed if the algorithm will produce new data or transform metadata.

    the report callback must be callable with signature: teca_metadata(unsigned int)

  2. request phase. the request callback generates a vector of requests(metadata objects) that inform the upstream of what data to generate. The request callback is optional. It's only needed if the algorithm needs data from the upstream or transform metadata.

    the request callback must be callable with the signature: std::vector<teca_metadata>( unsigned int, const std::vector<teca_metadata> &, const teca_metadata &)

  3. execute phase. the execute callback is used to do useful work on incoming or outgoing data. Examples include generating new datasets, processing datasets, reading and writing data to/from disk, and so on. The execute callback is optional.

    the execute callback must be callable with the signature: const_p_teca_dataset( unsigned int, const std::vector<const_p_teca_dataset> &, const teca_metadata &)

see also:

set_number_of_input_connections set_number_of_output_ports set_report_callback set_request_callback set_execute_callback

Member Function Documentation

◆ execute()

const_p_teca_dataset teca_programmable_algorithm::execute ( unsigned int  port,
const std::vector< const_p_teca_dataset > &  input_data,
const teca_metadata request 
)
overrideprotectedvirtual

implementations must override this method and produce the output dataset for the port named in the first argument. The second argument is a list of all of the input datasets. See also get_request. The third argument contains a request from the consumer which can specify information such as arrays, subset region, timestep etc. The implementation is free to handle the request as it sees fit.

Reimplemented from teca_algorithm.

◆ get_class_name()

const char* teca_programmable_algorithm::get_class_name ( ) const
inlineoverridevirtual

get the name differntiating this instance in the pipeline.

Implements teca_algorithm.

◆ get_execute_callback() [1/2]

execute_callback_t& teca_programmable_algorithm::get_execute_callback ( )
inline

Get the execute_callback algorithm property

◆ get_execute_callback() [2/2]

const execute_callback_t& teca_programmable_algorithm::get_execute_callback ( ) const
inline

Get the execute_callback algorithm property

◆ get_output_metadata() [1/3]

virtual teca_metadata teca_algorithm::get_output_metadata
protected

driver function that manage meta data reporting phase of pipeline execution.

◆ get_output_metadata() [2/3]

virtual teca_metadata teca_algorithm::get_output_metadata
protected

implementations must override this method to provide information to downstream consumers about what data will be produced on each output port. The port to provide information about is named in the first argument the second argument contains a list of the metadata describing data on all of the inputs.

◆ get_output_metadata() [3/3]

teca_metadata teca_programmable_algorithm::get_output_metadata ( unsigned int  port,
const std::vector< teca_metadata > &  input_md 
)
overrideprotectedvirtual

implementations must override this method to provide information to downstream consumers about what data will be produced on each output port. The port to provide information about is named in the first argument the second argument contains a list of the metadata describing data on all of the inputs.

Reimplemented from teca_algorithm.

◆ get_report_callback() [1/2]

report_callback_t& teca_programmable_algorithm::get_report_callback ( )
inline

Get the report_callback algorithm property

◆ get_report_callback() [2/2]

const report_callback_t& teca_programmable_algorithm::get_report_callback ( ) const
inline

Get the report_callback algorithm property

◆ get_request_callback() [1/2]

request_callback_t& teca_programmable_algorithm::get_request_callback ( )
inline

Get the request_callback algorithm property

◆ get_request_callback() [2/2]

const request_callback_t& teca_programmable_algorithm::get_request_callback ( ) const
inline

Get the request_callback algorithm property

◆ get_upstream_request()

std::vector<teca_metadata> teca_programmable_algorithm::get_upstream_request ( unsigned int  port,
const std::vector< teca_metadata > &  input_md,
const teca_metadata request 
)
overrideprotectedvirtual

implementations must override this method and generate a set of requests describing the data required on the inputs to produce data for the named output port, given the upstream meta data and request. If no data is needed on an input then the list should contain a null request.

Reimplemented from teca_algorithm.

◆ New()

static p_teca_programmable_algorithm teca_programmable_algorithm::New ( )
inlinestatic

Returns an instance of teca_programmable_algorithm

◆ set_execute_callback()

void teca_programmable_algorithm::set_execute_callback ( const execute_callback_t &  v)
inline

Set the callback that responds to the execution stage of pipeline execution. the execute callback must be callable with the signature:

{C++}
const_p_teca_dataset (
unsigned int, const std::vector<const_p_teca_dataset> &,
const teca_metadata &)
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22

Set the execute_callback algorithm property

◆ set_name()

virtual int teca_programmable_algorithm::set_name ( const std::string &  name)
virtual

set/get the class name. set the name differntiating this instance in the pipeline.

◆ set_number_of_input_connections()

void teca_algorithm::set_number_of_input_connections

set the number of input and outputs

◆ set_number_of_output_ports()

void teca_algorithm::set_number_of_output_ports

Set the number of output ports. implementations should call this from their constructors to setup the internal caches and data structures required for execution.

◆ set_report_callback()

void teca_programmable_algorithm::set_report_callback ( const report_callback_t &  v)
inline

Set callback that responds to reporting stage of pipeline execution. the report callback must be callable with signature:

{C++}
teca_metadata (unsigned int, const std::vector<teca_metadata> &)

Set the report_callback algorithm property

◆ set_request_callback()

void teca_programmable_algorithm::set_request_callback ( const request_callback_t &  v)
inline

Set the callback that responds to the requesting stage of pipeline execution. the request callback must be callable with the signature:

{C++}
std::vector<teca_metadata> (unsigned int,
const std::vector<teca_metadata> &, const teca_metadata &)

Set the request_callback algorithm property

◆ shared_from_this() [1/2]

std::shared_ptr< teca_programmable_algorithm > teca_programmable_algorithm::shared_from_this ( )
inline

Enables the static constructor

◆ shared_from_this() [2/2]

std::shared_ptr< teca_programmable_algorithm const> teca_programmable_algorithm::shared_from_this ( ) const
inline

Enables the static constructor

◆ use_default_execute_action()

void teca_programmable_algorithm::use_default_execute_action ( )

Install the default implementation for the execute phase which returns a nullptr.

◆ use_default_report_action()

void teca_programmable_algorithm::use_default_report_action ( )

Default implemenations for the phases of pipeline execution. Note that these generally do not do all that is needed but may suffice for simple pipelines. Install the default implementation for the report phase which forwards the incoming report downstream.

◆ use_default_request_action()

void teca_programmable_algorithm::use_default_request_action ( )

Install the default implementation for the request phase which forwards the incoming request upstream.


The documentation for this class was generated from the following file: