DfpGraph.cxx
Go to the documentation of this file.
2 
3 using namespace WireCell;
4 
6 {
7  auto it = vertex_property_map.find(tn);
8  if (it != vertex_property_map.end()) {
9  return it->second;
10  }
11  auto v = add_vertex(tn, graph);
12  vertex_property_map[tn] = v;
13  return v;
14 }
15 
16 DfpGraph::Edge DfpGraph::connect(const std::string& tail_type, const std::string& tail_name, int tail_port,
17  const std::string& head_type, const std::string& head_name, int head_port)
18 {
19 
20  VertexProperty tvp(tail_type, tail_name);
21  VertexProperty hvp(head_type, head_name);
22 
23  auto tv = get_add_vertex(tvp);
24  auto hv = get_add_vertex(hvp);
25 
26  EdgeProperty ep(tail_port, head_port);
27  Edge e; bool b;
28  std::tie(e, b) = boost::add_edge(tv, hv, ep, graph);
29  return e;
30 }
31 
32 std::vector<DfpGraph::Connection> DfpGraph::connections()
33 {
34 
35  std::vector<Connection> ret;
36  auto vits = boost::vertices(graph);
37  for (auto v = vits.first; v != vits.second; ++v) {
38  auto vp = graph[*v];
39  auto eits = out_edges(*v, graph);
40 
41  if (eits.first == eits.second) continue;
42 
43  for (auto e = eits.first; e != eits.second; ++e) {
44  auto ep = graph[*e];
45 
46  auto other = target(*e, graph);
47  auto hp = graph[other];
48 
49  ret.push_back(std::make_tuple(vp,hp,ep));
50  }
51  }
52  return ret;
53 }
54 
56 {
57  for (auto conn : cfg) {
58  auto tail = conn["tail"];
59  auto head = conn["head"];
60 
61  connect(get<std::string>(tail, "type"), get<std::string>(tail, "name"), get<int>(tail, "port"),
62  get<std::string>(head, "type"), get<std::string>(head, "name"), get<int>(head, "port"));
63  }
64 }
65 
std::vector< Connection > connections()
Definition: DfpGraph.cxx:32
std::string string
Definition: nybbler.cc:12
void configure(const Configuration &cfg)
Definition: DfpGraph.cxx:55
VertexPropertyMap vertex_property_map
Definition: DfpGraph.h:54
cfg
Definition: dbjson.py:29
const double e
boost::graph_traits< Graph >::edge_descriptor Edge
Definition: DfpGraph.h:46
boost::graph_traits< Graph >::vertex_descriptor Vertex
Definition: DfpGraph.h:45
Vertex get_add_vertex(const VertexProperty &tn)
Definition: DfpGraph.cxx:5
Edge connect(const std::string &tail_type, const std::string &tail_name, int tail_port, const std::string &head_type, const std::string &head_name, int head_port)
Explicitly connect one edge.
Definition: DfpGraph.cxx:16
Definition: Main.h:22
conn
Definition: dbjson.py:16
Json::Value Configuration
Definition: Configuration.h:50
static bool * b
Definition: config.cpp:1043