NodeWrapper.h
Go to the documentation of this file.
1 #ifndef WIRECELLTBB_NODEWRAPPER
2 #define WIRECELLTBB_NODEWRAPPER
3 
4 #include "WireCellIface/INode.h"
6 
7 #include <tbb/flow_graph.h>
8 #include <boost/any.hpp>
9 #include <memory>
10 #include <map>
11 
12 namespace WireCellTbb {
13 
14  // Broken out sender/receiver types, vectors of their pointers
15  typedef tbb::flow::sender<boost::any> sender_type;
16  typedef tbb::flow::receiver<boost::any> receiver_type;
17 
18  typedef std::vector<sender_type*> sender_port_vector;
19  typedef std::vector<receiver_type*> receiver_port_vector;
20 
21  typedef std::vector<boost::any> any_vector;
22 
23  typedef std::tuple<boost::any> any_single;
24  typedef std::tuple<boost::any,boost::any> any_double;
25  typedef std::tuple<boost::any,boost::any,boost::any> any_triple;
26 
27  /// Types for TBB nodes
28  typedef tbb::flow::source_node<boost::any> source_node;
29  typedef tbb::flow::function_node<boost::any> sink_node;
30  typedef tbb::flow::function_node<boost::any,boost::any> function_node;
31  typedef tbb::flow::multifunction_node<boost::any,any_single> queuedout_node;
32  typedef queuedout_node::output_ports_type queuedout_port;
33 
34 
35  // A base facade which expose sender/receiver ports and provide
36  // initialize hook. There is one NodeWrapper for each node
37  // category.
38  class NodeWrapper {
39  public:
40  virtual ~NodeWrapper() {}
41 
42  virtual sender_port_vector sender_ports() { return sender_port_vector(); }
43  virtual receiver_port_vector receiver_ports() { return receiver_port_vector(); }
44 
45  // call before running graph
46  virtual void initialize() { }
47 
48  };
49 
50  // expose the wrappers only as a shared pointer
51  typedef std::shared_ptr<NodeWrapper> Node;
52 
53 
54  // internal
55  template<typename Tuple, std::size_t... Is>
56  receiver_port_vector receiver_ports(tbb::flow::join_node<Tuple>& jn, std::index_sequence<Is...>) {
57  return { dynamic_cast<receiver_type*>(&tbb::flow::input_port<Is>(jn))... };
58  }
59  /// Return receiver ports of a join node as a vector.
60  template<typename Tuple>
61  receiver_port_vector receiver_ports(tbb::flow::join_node<Tuple>& jn) {
63  }
64 
65 }
66 
67 #endif
virtual receiver_port_vector receiver_ports()
Definition: NodeWrapper.h:43
void * Tuple
Definition: DBFolder.h:12
std::shared_ptr< NodeWrapper > Node
Definition: NodeWrapper.h:51
std::tuple< boost::any, boost::any > any_double
Definition: NodeWrapper.h:24
tbb::flow::function_node< boost::any > sink_node
Definition: NodeWrapper.h:29
tbb::flow::source_node< boost::any > source_node
Types for TBB nodes.
Definition: NodeWrapper.h:28
tbb::flow::multifunction_node< boost::any, any_single > queuedout_node
Definition: NodeWrapper.h:31
std::vector< receiver_type * > receiver_port_vector
Definition: NodeWrapper.h:19
std::vector< boost::any > any_vector
Definition: NodeWrapper.h:21
tbb::flow::sender< boost::any > sender_type
Definition: NodeWrapper.h:15
virtual sender_port_vector sender_ports()
Definition: NodeWrapper.h:42
std::tuple< boost::any, boost::any, boost::any > any_triple
Definition: NodeWrapper.h:25
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
std::vector< sender_type * > sender_port_vector
Definition: NodeWrapper.h:18
virtual void initialize()
Definition: NodeWrapper.h:46
tbb::flow::function_node< boost::any, boost::any > function_node
Definition: NodeWrapper.h:30
queuedout_node::output_ports_type queuedout_port
Definition: NodeWrapper.h:32
std::tuple< boost::any > any_single
Definition: NodeWrapper.h:23
tbb::flow::receiver< boost::any > receiver_type
Definition: NodeWrapper.h:16