MaCh3  2.8.0
Reference Guide
mach3.cpp
Go to the documentation of this file.
1 
16 #include "CLI/Modules/Plot/PlotModule.hpp"
18 #include "CLI/MaCh3Program.hpp"
19 
28 // Fix startup errors: the outer boundary also covers construction, registration and discovery.
29 int main(int argc, char *argv[]) try {
30  M3::MaCh3Program program("mach3");
31 
32  // Hidden completion option — accepts prefix + preceding words as context
33  program.add_argument("--complete")
34  .hidden()
35  .nargs(argparse::nargs_pattern::any);
36 
37  // Hidden installer option
38  program.add_argument("--install-completions")
39  .help("")
40  .flag();
41 
43  M3::DiagModule diag;
45  M3::RHatModule rhat;
46  M3::SmearModule smear;
47  M3::ReweightModule reweight;
48  M3::CombineModule combine;
49  M3::PlotModule plot;
50  M3::UmbrellaModule umbrella;
51 
52  program.add_core_module(proc);
53  program.add_core_module(diag);
54  program.add_core_module(penterm);
55  program.add_core_module(rhat);
56  program.add_core_module(smear);
57  program.add_core_module(reweight);
58  program.add_core_module(combine);
59  program.add_core_module(plot);
60  program.add_core_module(umbrella);
61  program.load_dynamic_plugins();
62 
63  // Pre-scan for --complete before argparse processes the full command line,
64  // so incomplete commands (missing required args) still produce completions.
65  for (int i = 1; i < argc; i++) {
66  if (std::string_view(argv[i]) == "--complete") {
67  std::string prefix = (i + 1 < argc) ? argv[i + 1] : "";
68  std::vector<std::string> context;
69  for (int j = i + 2; j < argc; j++) {
70  context.emplace_back(argv[j]);
71  }
72  program.completions(prefix, context);
73  return 0;
74  }
75  }
76 
77  try {
78  program.parse_args(argc, argv);
79  }
80  catch (const std::exception& err) {
81  std::cerr << err.what() << std::endl;
82  std::cerr << program.get_subcommand_used();
83  // Fix error diagnostics: exception text is data, not a logger format string.
84  MACH3LOG_ERROR("{}", err.what());
85  return 1;
86  }
87  catch(...){
88  MACH3LOG_ERROR("Unknown parsing error.");
89  return 1;
90  }
91 
92  // Fix handling of no-argument commands: allow leaf defaults; bare groups still need a child.
93  const auto& selected_parser = program.get_subcommand_used();
94  if (!selected_parser && !selected_parser.subparsers().empty()){
95  std::cerr << selected_parser;
96  return 2;
97  }
98 
99 
100  if (program.get<bool>("--install-completions")) {
101  // Fix handling of completion installation: do not turn an installer failure into process success.
102  return program.install_completions();
103  }
104 
105  try{
106  return program.Run();
107  }
108  catch(const std::exception& err){
109  MACH3LOG_ERROR("{}", err.what());
110  std::cerr << "An exception occurred during program execution: " << err.what() << std::endl;
111  return 3;
112  }
113  catch(...){
114  MACH3LOG_ERROR("Unknown exception occurred during program execution.");
115  std::cerr << "An unknown exception occurred during program execution." << std::endl;
116  return 3;
117  }
118 }
119 catch (const std::exception& err) {
120  MACH3LOG_ERROR("CLI initialisation failed: {}", err.what());
121  std::cerr << "CLI initialisation failed: " << err.what() << "\n";
122  return 1;
123 }
124 catch (...) {
125  MACH3LOG_ERROR("Unknown exception during CLI initialisation.");
126  std::cerr << "Unknown exception during CLI initialisation.\n";
127  return 1;
128 }
Allows you to combine multiple chains or ROOT files into a single output.
Module for extracting penalty terms from systematic chains.
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Core program class for the MaCh3 command-line interface.
Module for processing MCMC chains and producing diagnostic plots.
Module for computing the R-hat diagnostic for MCMC chains.
Module for MCMC reweighting analysis.
Allows you to smear contour. For example after performing sets of study one finds out that used sets ...
Allows you to combine multiple chains or ROOT files into a single output.
Module for MCMC diagnostics.
Definition: DiagModule.hpp:13
Module for extracting specific penalty terms from MCMC chains.
const MaCh3ArgumentParser & get_subcommand_used() const
Get the subcommand that was used in parsing.
Definition: m3argparse.hpp:46
Main program class that manages modules, plugins, and command-line parsing.
void add_core_module(IModule &module)
Add a core module to the program.
void completions(const std::string &prefix, const std::vector< std::string > &context) const
Generate subcommand or long-option suggestions at the active parser depth.
int install_completions() const
Install shell completion scripts for bash and zsh.
int Run()
Run the selected subcommand.
void load_dynamic_plugins()
Load dynamic plugins from the MACH3_PLUGINS environment variable.
void parse_args(int argc, const char *const argv[])
Parse args after inserting any default subcommands.
Module for processing MCMC chains and producing various diagnostic plots.
Module for computing the R-hat diagnostic for MCMC chains.
Definition: RHatModule.hpp:12
Module for performing reweighting analysis on MCMC chains.
Allows you to smear contour. For example after performing sets of study one finds out that used sets ...
Definition: SmearModule.hpp:10
Module for performing Umbrella sampling.
int main(int argc, char *argv[])
Main entry point for the MaCh3 application.
Definition: mach3.cpp:29