test_tbb_dfp_mce.cxx
Go to the documentation of this file.
1 // A minimally complete example of a tbb dfp
2 
3 #include "tbb_mock.h"
4 
6 #include "WireCellTbb/SinkCat.h"
9 
10 #include "WireCellUtil/Testing.h"
11 
12 #include <tbb/flow_graph.h>
13 
14 #include <string>
15 #include <deque>
16 #include <iostream>
17 
18 using namespace std;
19 
20 // fixme: this fakes the factory until we clean up nodes to allow
21 // empty c'tor and use configuration.
23 {
24  using namespace WireCell;
25 
26  if (node_desc == "source") { // note actual desc should be class or class:inst
28  }
29  if (node_desc == "drift") { // note actual desc should be class or class:inst
31  }
32  if (node_desc == "sink") { // note actual desc should be class or class:inst
34  }
35  return nullptr;
36 }
37 
38 
39 
41 {
42  using namespace WireCell;
43  using namespace WireCellTbb;
44 
45  INode::pointer wcnode = get_node(node_desc);
46  if (! wcnode) {
47  cerr << "Failed to get node for " << node_desc << endl;
48  return nullptr;
49  }
50 
51  cerr << "Getting node from category: " << wcnode->category() << endl;
52  switch (wcnode->category()) {
53  case INode::sourceNode:
54  return Node(new SourceNodeWrapper(graph, wcnode));
55  case INode::sinkNode:
56  return Node(new SinkNodeWrapper(graph, wcnode));
57  // case INode::functionNode:
58  // return Node(new FunctionWrapper(graph, wcnode));
59  case INode::queuedoutNode:
60  return Node(new QueuedoutWrapper(graph, wcnode));
61  default:
62  return nullptr;
63  }
64  return nullptr;
65 }
66 
67 bool connect(WireCellTbb::Node sender, WireCellTbb::Node receiver, size_t sport=0, size_t rport=0);
68 bool connect(WireCellTbb::Node sender, WireCellTbb::Node receiver, size_t sport, size_t rport)
69 {
70  using namespace WireCellTbb;
71 
72  Assert(sender);
73  Assert(receiver);
74  auto sports = sender->sender_ports();
75  auto rports = receiver->receiver_ports();
76 
77  Assert(sports.size() > sport);
78  Assert(rports.size() > rport);
79 
80  sender_type* s = sports[sport];
81  receiver_type* r = rports[rport];
82  Assert(s);
83  Assert(r);
84 
85  cerr << "Connecting " << s << " and " << r << endl;
86  make_edge(*s, *r);
87  return true;
88 }
89 
90 int main()
91 {
92  using namespace WireCellTbb;
93 
95  Node source = make_node(graph, "source");
96  Assert(source);
97  Node drift = make_node(graph, "drift");
98  Assert(drift);
99  Node sink = make_node(graph, "sink");
100  Assert(sink);
101 
102  Assert (connect(source, drift));
103  Assert (connect(drift, sink));
104 
105  // fixme: in general all nodes should be initialize()'d but so far only source nodes need it.
106  source->initialize();
107 
108  graph.wait_for_all();
109 
110  return 0;
111 }
const CharType(& source)[N]
Definition: pointer.h:1147
int main()
std::shared_ptr< INode > pointer
Access subclass facet by pointer.
Definition: IComponent.h:33
QMapNodeBase Node
Definition: qmap.cpp:41
std::string string
Definition: nybbler.cc:12
def graph(desc, maker=maker)
Definition: apa.py:294
STL namespace.
std::shared_ptr< NodeWrapper > Node
Definition: NodeWrapper.h:51
#define Assert
Definition: Testing.h:7
WireCell::INode::pointer get_node(const std::string &node_desc)
std::shared_ptr< Interface > pointer
Definition: Interface.h:16
tbb::flow::sender< boost::any > sender_type
Definition: NodeWrapper.h:15
Definition: Main.h:22
WireCellTbb::Node make_node(tbb::flow::graph &graph, const std::string &node_desc)
bool connect(WireCellTbb::Node sender, WireCellTbb::Node receiver, size_t sport=0, size_t rport=0)
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
tbb::flow::receiver< boost::any > receiver_type
Definition: NodeWrapper.h:16