Public Member Functions | Private Attributes | List of all members
WireCellTbb::DataFlowGraph Class Reference

#include <DataFlowGraph.h>

Inheritance diagram for WireCellTbb::DataFlowGraph:
WireCell::IDataFlowGraph WireCell::IConfigurable WireCell::IComponent< IDataFlowGraph > WireCell::IComponent< IConfigurable > WireCell::Interface WireCell::Interface

Public Member Functions

 DataFlowGraph (int max_threads=0)
 
virtual ~DataFlowGraph ()
 
virtual bool connect (WireCell::INode::pointer tail, WireCell::INode::pointer head, size_t tail_port=0, size_t head_port=0)
 
virtual bool run ()
 Run the graph, return false on error. More...
 
virtual void configure (const WireCell::Configuration &config)
 Accept a configuration. More...
 
virtual WireCell::Configuration default_configuration () const
 Optional, override to return a hard-coded default configuration. More...
 
- Public Member Functions inherited from WireCell::IDataFlowGraph
virtual ~IDataFlowGraph ()
 
- Public Member Functions inherited from WireCell::IComponent< IDataFlowGraph >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 
- Public Member Functions inherited from WireCell::IConfigurable
virtual ~IConfigurable ()
 
- Public Member Functions inherited from WireCell::IComponent< IConfigurable >
virtual ~IComponent ()
 

Private Attributes

tbb::task_scheduler_init m_sched
 
tbb::flow::graph m_graph
 
WrapperFactory m_factory
 

Additional Inherited Members

- Public Types inherited from WireCell::IComponent< IDataFlowGraph >
typedef std::shared_ptr< IDataFlowGraphpointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 
- Public Types inherited from WireCell::IComponent< IConfigurable >
typedef std::shared_ptr< IConfigurablepointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 

Detailed Description

Definition at line 16 of file DataFlowGraph.h.

Constructor & Destructor Documentation

DataFlowGraph::DataFlowGraph ( int  max_threads = 0)

Definition at line 19 of file DataFlowGraph.cxx.

20  : m_sched(max_threads > 0 ? max_threads : tbb::task_scheduler_init::automatic)
21  , m_graph()
23 {
24 }
tbb::flow::graph m_graph
Definition: DataFlowGraph.h:35
tbb::task_scheduler_init m_sched
Definition: DataFlowGraph.h:34
DataFlowGraph::~DataFlowGraph ( )
virtual

Definition at line 26 of file DataFlowGraph.cxx.

27 {
28 }

Member Function Documentation

void DataFlowGraph::configure ( const WireCell::Configuration config)
virtual

Accept a configuration.

Implements WireCell::IConfigurable.

Definition at line 38 of file DataFlowGraph.cxx.

39 {
40  // int maxthreads = get<int>(cfg,"max_threads");
41  // fixme: now what?
42 }
bool DataFlowGraph::connect ( WireCell::INode::pointer  tail,
WireCell::INode::pointer  head,
size_t  tail_port = 0,
size_t  head_port = 0 
)
virtual

Connect two nodes so that data runs from tail to head. Return false on error.

Implements WireCell::IDataFlowGraph.

Definition at line 45 of file DataFlowGraph.cxx.

47 {
48  using namespace WireCellTbb;
49 
50  Node mytail = m_factory(tail);
51  if (!mytail) {
52  cerr << "DFP: failed to get tail node wrapper for "
53  << demangle(tail->signature()) << endl;
54  return false;
55  }
56 
57  Node myhead = m_factory(head);
58  if (!myhead) {
59  cerr << "DFP: failed to get head node wrapper for "
60  << demangle(head->signature()) << endl;
61  return false;
62  }
63 
64  auto sports = mytail->sender_ports();
65  if (sport < 0 || sports.size() <= sport) {
66  cerr << "DFP: bad sender port number: " << sport << endl;
67  return false;
68  }
69 
70  auto rports = myhead->receiver_ports();
71  if (rport < 0 || rports.size() <= rport) {
72  cerr << "DFP: bad receiver port number: " << rport << endl;
73  return false;
74  }
75 
76 
77  sender_type* s = sports[sport];
78  if (!s) {
79  cerr << "DFP: failed to get sender port " << sport << endl;
80  return false;
81  }
82 
83  receiver_type* r = rports[rport];
84  if (!s) {
85  cerr << "DFP: failed to get receiver port " << rport << endl;
86  return false;
87  }
88 
89 
90  //cerr << "Connecting " << s << " and " << r << endl;
91  make_edge(*s, *r);
92  return true;
93 }
std::string demangle(T const *=nullptr)
Outputs a demangled name for type T.
Definition: DebugUtils.h:348
std::shared_ptr< NodeWrapper > Node
Definition: NodeWrapper.h:51
tbb::flow::sender< boost::any > sender_type
Definition: NodeWrapper.h:15
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
tbb::flow::receiver< boost::any > receiver_type
Definition: NodeWrapper.h:16
Configuration DataFlowGraph::default_configuration ( ) const
virtual

Optional, override to return a hard-coded default configuration.

Reimplemented from WireCell::IConfigurable.

Definition at line 30 of file DataFlowGraph.cxx.

31 {
33  cfg["max_threads"] = 1;
34  return cfg;
35 }
cfg
Definition: dbjson.py:29
Json::Value Configuration
Definition: Configuration.h:50
bool DataFlowGraph::run ( )
virtual

Run the graph, return false on error.

Implements WireCell::IDataFlowGraph.

Definition at line 96 of file DataFlowGraph.cxx.

97 {
98  for (auto it : m_factory.seen()) {
99  cerr << "Initialize node of type: " << demangle(it.first->signature()) << endl;
100  it.second->initialize();
101  }
102  m_graph.wait_for_all();
103  return true;
104 }
std::string demangle(T const *=nullptr)
Outputs a demangled name for type T.
Definition: DebugUtils.h:348
tbb::flow::graph m_graph
Definition: DataFlowGraph.h:35
WCNode2Wrapper & seen()
QTextStream & endl(QTextStream &s)

Member Data Documentation

WrapperFactory WireCellTbb::DataFlowGraph::m_factory
private

Definition at line 36 of file DataFlowGraph.h.

tbb::flow::graph WireCellTbb::DataFlowGraph::m_graph
private

Definition at line 35 of file DataFlowGraph.h.

tbb::task_scheduler_init WireCellTbb::DataFlowGraph::m_sched
private

Definition at line 34 of file DataFlowGraph.h.


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