Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
tbb
test
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
5
#include "
WireCellTbb/NodeWrapper.h
"
6
#include "
WireCellTbb/SinkCat.h
"
7
#include "
WireCellTbb/SourceCat.h
"
8
#include "
WireCellTbb/QueuedoutCat.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.
22
WireCell::INode::pointer
get_node
(
const
std::string
& node_desc)
23
{
24
using namespace
WireCell
;
25
26
if
(node_desc ==
"source"
) {
// note actual desc should be class or class:inst
27
return
INode::pointer
(
new
WireCellTbb::MockDepoSource
);
28
}
29
if
(node_desc ==
"drift"
) {
// note actual desc should be class or class:inst
30
return
INode::pointer
(
new
WireCellTbb::MockDrifter
);
31
}
32
if
(node_desc ==
"sink"
) {
// note actual desc should be class or class:inst
33
return
INode::pointer
(
new
WireCellTbb::MockDepoSink
);
34
}
35
return
nullptr
;
36
}
37
38
39
40
WireCellTbb::Node
make_node
(
tbb::flow::graph
&
graph
,
const
std::string
& node_desc)
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
94
tbb::flow::graph
graph
;
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
}
source
const CharType(& source)[N]
Definition:
pointer.h:1147
main
int main()
Definition:
test_tbb_dfp_mce.cxx:90
WireCell::IComponent< INode >::pointer
std::shared_ptr< INode > pointer
Access subclass facet by pointer.
Definition:
IComponent.h:33
WireCellTbb::SourceNodeWrapper
Definition:
SourceCat.h:27
Node
QMapNodeBase Node
Definition:
qmap.cpp:41
string
std::string string
Definition:
nybbler.cc:12
QueuedoutCat.h
wirecell.util.wires.apa.graph
def graph(desc, maker=maker)
Definition:
apa.py:294
std
STL namespace.
WireCellTbb::Node
std::shared_ptr< NodeWrapper > Node
Definition:
NodeWrapper.h:51
tbb_mock.h
Assert
#define Assert
Definition:
Testing.h:7
WireCellTbb::MockDrifter
Definition:
tbb_mock.h:36
get_node
WireCell::INode::pointer get_node(const std::string &node_desc)
Definition:
test_tbb_dfp_mce.cxx:22
SourceCat.h
Testing.h
WireCell::Interface::pointer
std::shared_ptr< Interface > pointer
Definition:
Interface.h:16
SinkCat.h
WireCellTbb::sender_type
tbb::flow::sender< boost::any > sender_type
Definition:
NodeWrapper.h:15
WireCellTbb::SinkNodeWrapper
Definition:
SinkCat.h:26
WireCell
Definition:
Main.h:22
make_node
WireCellTbb::Node make_node(tbb::flow::graph &graph, const std::string &node_desc)
Definition:
test_tbb_dfp_mce.cxx:40
WireCellTbb
Definition:
DataFlowGraph.h:14
WireCellTbb::MockDepoSource
Definition:
tbb_mock.h:15
NodeWrapper.h
connect
bool connect(WireCellTbb::Node sender, WireCellTbb::Node receiver, size_t sport=0, size_t rport=0)
Definition:
test_tbb_dfp_mce.cxx:68
WireCellTbb::MockDepoSink
Definition:
tbb_mock.h:59
WireCellTbb::QueuedoutWrapper
Definition:
QueuedoutCat.h:29
s
static QCString * s
Definition:
config.cpp:1042
plot_model.r
r
Definition:
plot_model.py:57
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
WireCellTbb::receiver_type
tbb::flow::receiver< boost::any > receiver_type
Definition:
NodeWrapper.h:16
Generated by
1.8.11