JoinCat.h
Go to the documentation of this file.
1 #ifndef WIRECELLTBB_JOINCAT
2 #define WIRECELLTBB_JOINCAT
3 
5 #include "WireCellUtil/Testing.h"
7 
8 namespace WireCellTbb {
9 
10 
11  // Body for a TBB join node.
12  template<typename TupleType>
13  class JoinBody {
15  public:
18 
20  m_wcnode = std::dynamic_pointer_cast<WireCell::IJoinNodeBase>(wcnode);
21  Assert(m_wcnode);
22  }
23 
24  boost::any operator() (const TupleType &tup) const {
25  helper_type ih;
26  any_vector in = ih.as_any(tup);
27  boost::any ret;
28  //bool ok = (*m_wcnode)(in, ret);
29  (*m_wcnode)(in, ret); // fixme: don't ignore the return code
30  return ret;
31  }
32 
33  };
34 
35  template<std::size_t N>
37  tbb::flow::graph_node*& joiner, tbb::flow::graph_node*& caller)
38  {
39  typedef typename WireCell::type_repeater<N, boost::any>::type TupleType;
40 
41  // this node is fully TBB and joins N receiver ports into a tuple
42  typedef tbb::flow::join_node< TupleType > tbb_join_node_type;
43  tbb_join_node_type* jn = new tbb_join_node_type(graph);
44  joiner = jn;
45 
46  // this node takes user WC body and runs it after converting input tuple to vector
47  typedef tbb::flow::function_node<TupleType,boost::any> joining_node;
48  joining_node* fn = new joining_node(graph, wcnode->concurrency(), JoinBody<TupleType>(wcnode));
49  caller = fn;
50 
51  tbb::flow::make_edge(*jn, *fn);
52 
53  //JoinNodeInputPorts<TupleType,N> ports;
54  //return ports(*jn);
55  return receiver_ports(*jn);
56  }
57 
58  // Wrap the TBB (compound) node
59  class JoinWrapper : public NodeWrapper {
60  tbb::flow::graph_node *m_joiner, *m_caller;
62 
63  public:
64 
66  : m_joiner(0), m_caller(0)
67  {
68  int nin = wcnode->input_types().size();
69  // an exhaustive switch to convert from run-time to compile-time types and enumerations.
70  Assert (nin > 0 && nin <= 3); // fixme: exception instead?
71  if (1 == nin) m_receiver_ports = build_joiner<1>(graph, wcnode, m_joiner, m_caller);
72  if (2 == nin) m_receiver_ports = build_joiner<2>(graph, wcnode, m_joiner, m_caller);
73  if (3 == nin) m_receiver_ports = build_joiner<3>(graph, wcnode, m_joiner, m_caller);
74  }
75 
77  return m_receiver_ports;
78  }
79 
81  auto ptr = dynamic_cast< sender_type* >(m_caller);
82  return sender_port_vector{ptr};
83  }
84 
85  };
86 
87 
88 }
89 
90 #endif
tbb::flow::graph_node * m_joiner
Definition: JoinCat.h:60
receiver_port_vector receiver_ports(tbb::flow::join_node< Tuple > &jn, std::index_sequence< Is... >)
Definition: NodeWrapper.h:56
def graph(desc, maker=maker)
Definition: apa.py:294
std::vector< boost::any > any_vector
Definition: IJoinNode.h:25
virtual sender_port_vector sender_ports()
Definition: JoinCat.h:80
receiver_port_vector build_joiner(tbb::flow::graph &graph, WireCell::INode::pointer wcnode, tbb::flow::graph_node *&joiner, tbb::flow::graph_node *&caller)
Definition: JoinCat.h:36
receiver_port_vector m_receiver_ports
Definition: JoinCat.h:61
#define Assert
Definition: Testing.h:7
QAsciiDict< Entry > fn
WireCell::IJoinNodeBase::any_vector any_vector
Definition: JoinCat.h:16
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
JoinBody(WireCell::INode::pointer wcnode)
Definition: JoinCat.h:19
JoinWrapper(tbb::flow::graph &graph, WireCell::INode::pointer wcnode)
Definition: JoinCat.h:65
WireCell::tuple_helper< TupleType > helper_type
Definition: JoinCat.h:17
WireCell::IJoinNodeBase::pointer m_wcnode
Definition: JoinCat.h:14
std::vector< receiver_type * > receiver_port_vector
Definition: NodeWrapper.h:19
tbb::flow::sender< boost::any > sender_type
Definition: NodeWrapper.h:15
virtual receiver_port_vector receiver_ports()
Definition: JoinCat.h:76
const void * ptr(const T *p)
Definition: format.h:3138
std::vector< sender_type * > sender_port_vector
Definition: NodeWrapper.h:18
std::shared_ptr< IJoinNodeBase > pointer
Definition: IJoinNode.h:21
boost::any operator()(const TupleType &tup) const
Definition: JoinCat.h:24