MaCh3  2.8.0
Reference Guide
Functions
mach3.cpp File Reference

Main entry point for the MaCh3 command-line interface. More...

#include "CLI/Modules/ProcessMCMCModule.hpp"
#include "CLI/Modules/DiagModule.hpp"
#include "CLI/Modules/GetPenaltyTermModule.hpp"
#include "CLI/Modules/RHatModule.hpp"
#include "CLI/Modules/SmearModule.hpp"
#include "CLI/Modules/ReweightModule.hpp"
#include "CLI/Modules/CombineModule.hpp"
#include "CLI/Modules/Plot/PlotModule.hpp"
#include "CLI/Modules/UmbrellaModule.hpp"
#include "CLI/MaCh3Program.hpp"
Include dependency graph for mach3.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Main entry point for the MaCh3 application. More...
 

Detailed Description

Main entry point for the MaCh3 command-line interface.

This file contains the main function that initializes the MaCh3 program, registers core modules, loads dynamic plugins, and processes command-line arguments.

Author
Alexander Richards

Definition in file mach3.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main entry point for the MaCh3 application.

Initializes the MaCh3 program with core modules and dynamic plugins, parses command-line arguments, and executes the selected subcommand.

Parameters
argcNumber of command-line arguments
argvArray of command-line argument strings
Returns
Exit code (0 on success, non-zero on error)

Definition at line 29 of file mach3.cpp.

29  {
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 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
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.
Main program class that manages modules, plugins, and command-line parsing.
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.