Pgrapher.cxx
Go to the documentation of this file.
3 #include "WireCellIface/INode.h"
5 
8 
9 using WireCell::get;
10 using namespace WireCell::Pgraph;
11 
12 WireCell::Configuration Pgrapher::default_configuration() const
13 {
15 
16  cfg["edges"] = Json::arrayValue;
17  return cfg;
18 }
19 
20 static
21 std::pair<WireCell::INode::pointer, int> get_node(WireCell::Configuration jone)
22 {
23  using namespace WireCell;
24  std::string node = jone["node"].asString();
25 
26  // We should NOT be the one creating this component.
27  auto nptr = WireCell::Factory::find_maybe_tn<INode>(node);
28  if (!nptr) {
29  THROW(ValueError() << errmsg{"failed to get node"});
30  }
31 
32  int port = get(jone,"port",0);
33  return std::make_pair(nptr, port);
34 }
35 
37 
38 {
39  Pgraph::Factory fac;
40  l->debug("connecting: {} edges", cfg["edges"].size());
41  for (auto jedge : cfg["edges"]) {
42  auto tail = get_node(jedge["tail"]);
43  auto head = get_node(jedge["head"]);
44 
45  SPDLOG_LOGGER_TRACE(l,"connecting: {}", jedge);
46 
47  bool ok = m_graph.connect(fac(tail.first), fac(head.first),
48  tail.second, head.second);
49  if (!ok) {
50  l->critical("failed to connect edge: {}", jedge);
51  THROW(ValueError() << errmsg{"failed to connect edge"});
52  }
53  }
54  if (!m_graph.connected()) {
55  l->critical("graph not fully connected");
56  THROW(ValueError() << errmsg{"graph not fully connected"});
57  }
58 }
59 
60 
61 
62 void Pgrapher::execute()
63 {
64  m_graph.execute();
65 }
66 
67 
68 
69 Pgrapher::Pgrapher()
70  : l(Log::logger("pgraph"))
71 {
72 }
74 {
75 }
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
cfg
Definition: dbjson.py:29
static QStrList * l
Definition: config.cpp:1044
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:87
def configure(cfg)
Definition: cuda.py:34
#define THROW(e)
Definition: Exceptions.h:25
logptr_t logger(std::string name)
Definition: Logging.cxx:71
Thrown when a wrong value has been encountered.
Definition: Exceptions.h:37
Definition: Main.h:22
#define SPDLOG_LOGGER_TRACE(logger,...)
Definition: spdlog.h:319
Json::Value Configuration
Definition: Configuration.h:50
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
static std::pair< WireCell::INode::pointer, int > get_node(WireCell::Configuration jone)
Definition: Pgrapher.cxx:21
#define WIRECELL_FACTORY(NAME, CONCRETE,...)
Definition: NamedFactory.h:332