DfpGraph.h
Go to the documentation of this file.
1 #ifndef WIRECELLUTIL_DFPGRAPH
2 #define WIRECELLUTIL_DFPGRAPH
3 
5 #include "WireCellUtil/String.h"
6 #include <boost/graph/adjacency_list.hpp>
7 
8 #include <tuple>
9 #include <vector>
10 
11 namespace WireCell {
12 
13  struct DfpGraph {
14 
15  struct VertexProperty {
18 
19  VertexProperty(const std::string& t, const std::string& n) : type(t), name(n) {}
21  std::tie(type,name) = WireCell::String::parse_pair(tn);
22  }
23  VertexProperty() : type(""), name("") {}
24 
25  bool operator==(const VertexProperty& rhs) const {
26  return type == rhs.type && name == rhs.name;
27  }
28  bool operator<(const VertexProperty& rhs) const {
29  if (type == rhs.type) {
30  return name < rhs.name;
31  }
32  return type < rhs.type;
33  }
34  };
35 
36  struct EdgeProperty {
37  int tail;
38  int head;
39  EdgeProperty(int t, int h) : tail(t), head(h) {}
40  EdgeProperty() : tail(-1), head(-1) {}
41  };
42  typedef boost::adjacency_list<boost::vecS, boost::setS, boost::directedS,
44 
45  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
46  typedef boost::graph_traits<Graph>::edge_descriptor Edge;
47 
48  typedef std::map<VertexProperty, Vertex> VertexPropertyMap;
49 
50  typedef std::tuple<VertexProperty, VertexProperty, EdgeProperty> Connection;
51 
52 
53  Graph graph;
54  VertexPropertyMap vertex_property_map;
55 
56 
57  Vertex get_add_vertex(const VertexProperty& tn);
58 
59  /// Configure with list of connection dictionaries like:
60  ///
61  /// {
62  /// "tail": {"type":"TailType","name":"tailname", "port":0},
63  /// "head": {"type":"HeadType","name":"headname", "port":42}
64  /// },
65  ///
66  /// Only "type" key is required.
67  void configure(const Configuration& cfg);
68 
69  /// Explicitly connect one edge
70  Edge connect(const std::string& tail_type, const std::string& tail_name, int tail_port,
71  const std::string& head_type, const std::string& head_name, int head_port);
72 
73  std::vector<Connection> connections();
74  };
75 }
76 
77 
78 inline
79 std::ostream& operator<<(std::ostream& os, const WireCell::DfpGraph::VertexProperty& vp)
80 {
81  os << vp.type << ":" << vp.name;
82  return os;
83 }
84 
85 inline
86 std::ostream& operator<<(std::ostream& os, const WireCell::DfpGraph::EdgeProperty& ep)
87 {
88  os << "( " << ep.tail << " --> " << ep.head << " )";
89  return os;
90 }
91 
92 
93 
94 #endif
std::vector< Connection > connections()
Definition: DfpGraph.cxx:32
std::string string
Definition: nybbler.cc:12
VertexProperty(const std::string &t, const std::string &n)
Definition: DfpGraph.h:19
boost::adjacency_list< boost::vecS, boost::setS, boost::directedS, VertexProperty, EdgeProperty > Graph
Definition: DfpGraph.h:43
void configure(const Configuration &cfg)
Definition: DfpGraph.cxx:55
VertexPropertyMap vertex_property_map
Definition: DfpGraph.h:54
std::pair< std::string, std::string > parse_pair(const std::string &in, const std::string &delim=":")
Definition: String.cxx:15
cfg
Definition: dbjson.py:29
bool operator==(const VertexProperty &rhs) const
Definition: DfpGraph.h:25
std::map< VertexProperty, Vertex > VertexPropertyMap
Definition: DfpGraph.h:48
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
std::tuple< VertexProperty, VertexProperty, EdgeProperty > Connection
Definition: DfpGraph.h:50
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
std::ostream & operator<<(std::ostream &os, const WireCell::WirePlaneId &wpid)
Definition: WirePlaneId.cxx:83
Json::Value Configuration
Definition: Configuration.h:50
VertexProperty(const std::string &tn)
Definition: DfpGraph.h:20
std::size_t n
Definition: format.h:3399
bool operator<(const VertexProperty &rhs) const
Definition: DfpGraph.h:28
h
training ###############################
Definition: train_cnn.py:186