2 #include <boost/graph/graphviz.hpp> 11 #include <unordered_set> 25 Img::ClusterSink::~ClusterSink()
31 m_filename =
get(
cfg,
"filename", m_filename);
32 m_node_types =
get(
cfg,
"node_types", m_node_types);
38 cfg[
"filename"] = m_filename;
43 cfg[
"node_types"] = m_node_types;
47 typedef std::vector< std::function< std::string(const cluster_node_t& ptr) > >
stringers_t;
52 size_t sp = std::get<size_t>(n.ptr);
54 ss << n.code() <<
":" << sp;
58 template <
typename Type>
61 typename Type::pointer sp = std::get<typename Type::pointer>(n.ptr);
63 ss << n.code() <<
":" << sp->ident();
66 template <
typename Type>
69 typename Type::shared_vector sv = std::get<typename Type::shared_vector>(n.ptr);
71 ss << n.code() <<
"#" << sv->size();
80 scalar_stringer<IChannel>,
81 scalar_stringer<IWire>,
82 scalar_stringer<IBlob>,
83 scalar_stringer<ISlice>,
84 vector_stringer<IChannel>
86 const size_t ind = n.ptr.index();
92 template<
class vdesc_t>
93 void operator()(std::ostream& out,
const vdesc_t v)
const {
94 out <<
"[label=\"" <<
asstring(g[v]) <<
"\"]";
109 if (m_filename.find(
"%") != std::string::npos) {
112 std::ofstream out(fname.c_str());
115 std::unordered_set<char> keep(m_node_types.begin(), m_node_types.end());
121 for (
const auto& v : boost::make_iterator_range(boost::vertices(gr))) {
122 const auto& vobj = gr[v];
123 if (!keep.count(vobj.code())) {
127 for (
auto edge : boost::make_iterator_range(boost::out_edges(v, gr))) {
129 const auto& vobj2 = gr[v2];
130 if (keep.count(vobj2.code())) {
131 grind.
edge(vobj, vobj2);
std::shared_ptr< const ICluster > pointer
void info(const char *fmt, const Args &...args)
const cluster_graph_t & g
std::string scalar_stringer(const cluster_node_t &n)
const graph_t & graph() const
std::string vector_stringer(const cluster_node_t &n)
Cluster finding and building.
boost::adjacency_list< boost::setS, boost::vecS, boost::undirectedS, cluster_node_t > cluster_graph_t
vdesc_t vertex(vertex_t vobj)
WIRECELL_FACTORY(ClusterSink, WireCell::Img::ClusterSink, WireCell::IClusterSink, WireCell::IConfigurable) using namespace WireCell
Json::Value Configuration
static std::string size_stringer(const cluster_node_t &n)
edesc_t edge(vertex_t vobj1, vertex_t vobj2)
std::vector< std::function< std::string(const cluster_node_t &ptr) > > stringers_t
const GenericPointer< typename T::ValueType > & pointer
static std::string asstring(const cluster_node_t &n)
void operator()(std::ostream &out, const vdesc_t v) const