ConfigDumper.cxx
Go to the documentation of this file.
2 #include "WireCellUtil/String.h"
3 #include "WireCellUtil/Persist.h"
6 #include "WireCellUtil/Logging.h"
7 
10 
11 
12 using spdlog::info;
13 using spdlog::warn;
14 
15 using namespace std;
16 using namespace WireCell;
17 using namespace WireCellApps;
18 
19 
21  : m_cfg(default_configuration())
22 {
23 }
24 
25 ConfigDumper::~ConfigDumper()
26 {
27 }
28 
30 {
31  m_cfg = config;
32 }
33 
35 {
36  // yo dawg, I heard you liked dumping so I made a dumper that dumps the dumper.
38  cfg["filename"] = "/dev/stdout";
39  cfg["components"] = Json::arrayValue;
40  return cfg;
41 }
42 
44 {
46  int nfailed = 0;
47 
48  std::vector<std::string> comps;
49  for (auto jone : m_cfg["components"]) {
50  comps.push_back(jone.asString());
51  }
52  if (comps.empty()) {
53  comps = Factory::known_types<IConfigurable>();
54  }
55 
56  for (auto c : comps) {
57 
58  string type, name;
59  tie(type,name) = String::parse_pair(convert<string>(c));
60 
62  try {
63  auto cfgobj = Factory::lookup<IConfigurable>(type,name);
64  cfg = cfgobj->default_configuration();
65  }
66  catch (FactoryException& fe) {
67  warn("failed lookup component: \"{}\":\"{}\"", type, name);
68  ++nfailed;
69  continue;
70  }
71  cm.add(cfg, type, name);
72  }
73 
74  Persist::dump(get<string>(m_cfg, "filename"), cm.all());
75 }
76 
static QCString name
Definition: declinfo.cpp:673
std::pair< std::string, std::string > parse_pair(const std::string &in, const std::string &delim=":")
Definition: String.cxx:15
STL namespace.
cfg
Definition: dbjson.py:29
virtual WireCell::Configuration default_configuration() const
Optional, override to return a hard-coded default configuration.
Configuration all() const
Return top-level, aggregate configuration.
Definition: ConfigManager.h:37
Definition: async.h:27
static Config * config
Definition: config.cpp:1054
virtual void execute()
Implement to run something.
int add(Configuration &cfg)
Definition: Main.h:22
virtual void configure(const WireCell::Configuration &config)
Accept a configuration.
WireCell::Configuration m_cfg
Definition: ConfigDumper.h:11
static QCString type
Definition: declinfo.cpp:672
Json::Value Configuration
Definition: Configuration.h:50
static const double cm
Definition: Units.h:76
void dump(const IFrame::pointer frame)
Definition: Fourdee.cxx:120
#define WIRECELL_FACTORY(NAME, CONCRETE,...)
Definition: NamedFactory.h:332