Main.h
Go to the documentation of this file.
1 /** This is the main entry point to the WCT. It provides a single
2  * command line method or optionally a family of fine-grained methods
3  * for setup and running.
4  *
5  * One use of this is in the `wire-cell` command line program. It may
6  * also be use to embed WCT into a larger application or framework. */
7 
8 #ifndef WIRECELL_MAIN
9 #define WIRECELL_MAIN
10 
13 #include "WireCellUtil/Persist.h"
14 
15 #include "WireCellUtil/Logging.h"
16 
17 #include <string>
18 #include <vector>
19 
20 
21 
22 namespace WireCell {
23  class Main {
24 
25  public:
26 
27  Main();
28  ~Main();
29 
30  /// Single-point entry to Wire Cell.
31  ///
32  /// Pass in literal command line arguments and return a return
33  /// code. See `wire-cell --help` for args.
34  ///
35  /// Or, one can use subsequent methods for more fine-grained
36  /// setup and execution.
37  int cmdline(int argc, char* argv[]);
38 
39 
40  /// Individual setup methods called by cmdline() or called
41  /// explicitly by external application/frameork:
42 
43  /// Add an IApplication component to execute as a `type:name`
44  /// string.
45  void add_app(const std::string& tn);
46 
47  /// Append a top-level JSON/Jsonnet configuration file to the
48  /// configuration sequence.
49  void add_config(const std::string& filename);
50 
51  /// Bind an external scalar value to a variable so that it may
52  /// be referenced in the configuration files (via
53  /// std.extVar()).
54  void add_var(const std::string& name, const std::string& value);
55 
56  /// Bind external configuration code (in Jsonnet language) to
57  /// a variable so that its may be referenced the configuration
58  /// files (via std.extVar())
59  void add_code(const std::string& name, const std::string& value);
60 
61  /// Add an element to the configuration path in which
62  /// configuration files may be found.
63  void add_path(const std::string& dirname);
64 
65  /// Add a plugin library in which components may be found.
66  /// The libname may lack the initial "lib" prefix and file
67  /// extension.
68  void add_plugin(const std::string& libname);
69 
70 
71  /// Add a log sink, reserved names 'stdout' and 'stderr' or a filename.
72  void add_logsink(const std::string& log, const std::string& level="");
73 
74  /// Set a minimum level to emit a message for a given
75  /// log. (levels: critical, error, warn, info, debug, trace).
76  void set_loglevel(const std::string& log, const std::string& level="");
77 
78  /// Call once after all setup has been done and before
79  /// running.
80  void initialize();
81 
82  /// Run any and all application components once.
83  void operator()();
84 
85 
86  private:
88  std::vector<std::string> m_plugins, m_apps, m_cfgfiles, m_load_path;
91 
92  };
93 
94 
95 
96 }
97 #endif
static QCString name
Definition: declinfo.cpp:673
std::vector< std::string > m_cfgfiles
Definition: Main.h:88
void add_code(const std::string &name, const std::string &value)
Definition: Main.cxx:173
int cmdline(int argc, char *argv[])
Definition: Main.cxx:38
std::string string
Definition: nybbler.cc:12
void add_logsink(const std::string &log, const std::string &level="")
Add a log sink, reserved names &#39;stdout&#39; and &#39;stderr&#39; or a filename.
Definition: Main.cxx:147
std::vector< std::string > m_plugins
Definition: Main.h:88
std::map< std::string, std::string > externalvars_t
Definition: Persist.h:69
Persist::externalvars_t m_extcode
Definition: Main.h:89
string filename
Definition: train.py:213
void add_config(const std::string &filename)
Definition: Main.cxx:163
std::vector< std::string > m_apps
Definition: Main.h:88
void add_path(const std::string &dirname)
Definition: Main.cxx:178
void add_var(const std::string &name, const std::string &value)
Definition: Main.cxx:168
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
std::vector< std::string > m_load_path
Definition: Main.h:88
void add_app(const std::string &tn)
Definition: Main.cxx:142
void operator()()
Run any and all application components once.
Definition: Main.cxx:265
Definition: Main.h:22
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
ConfigManager m_cfgmgr
Definition: Main.h:87
void initialize()
Definition: Main.cxx:184
void add_plugin(const std::string &libname)
Definition: Main.cxx:137
Persist::externalvars_t m_extvars
Definition: Main.h:89
Log::logptr_t l
Definition: Main.h:90
void set_loglevel(const std::string &log, const std::string &level="")
Definition: Main.cxx:159