22#include "marley/CommandHandler.hh"
23#include "marley/Logger.hh"
24#include "marley/marley_utils.hh"
28 bool print_version(
const std::deque< std::string >& ) {
29 std::cout <<
"MARLEY (Model of Argon Reaction Low Energy Yields) "
30 << MARLEY_VERSION <<
'\n';
31 std::cout <<
"Copyright (C) 2016-2026 Steven Gardiner\n";
32 std::cout <<
"License: GNU GPL version 3 "
33 <<
"<http://opensource.org/licenses/GPL-3.0>\n";
34 std::cout <<
"This is free software: you are free to change and"
35 <<
" redistribute it.\n";
39 void print_generate_help() {
40 std::cout <<
"Usage: marley generate CONFIG_FILE\n\n"
41 <<
"Simulate neutrino interaction events according to the\n"
42 <<
"settings in CONFIG_FILE.\n\n"
43 <<
"This is the default command: 'marley CONFIG_FILE' is equivalent to\n"
44 <<
"'marley generate CONFIG_FILE'.\n\n"
46 <<
" -h, --help Print this help message\n";
49 void print_print_help() {
50 std::cout <<
"Usage: marley print [FORMAT] INPUT_FILES...\n\n"
51 <<
"Print events from one or more MARLEY output files.\n\n"
52 <<
" FORMAT Optional output format selector:\n"
53 <<
" pretty (default): human-readable event history\n"
54 <<
" hepmc3: text representation of HepMC3\n"
55 <<
" legacy: MARLEY v1 legacy event summary\n\n"
57 <<
" -h, --help Print this help message\n";
60 void print_reweight_help() {
61 std::cout <<
"Usage: marley reweight CONFIG_FILE INPUT_FILE...\n\n"
62 <<
"Reweight previously generated MARLEY events in one or more INPUT_FILEs"
64 <<
"weight-calculation settings in CONFIG_FILE.\n\n"
66 <<
" -h, --help Print this help message\n";
69 void print_xsec_help() {
70 std::cout <<
"Usage: marley xsec -o OUTPUT_FILE CONFIG_FILE\n\n"
71 <<
"Tabulate the total cross section versus projectile kinetic energy\n"
72 <<
"using the settings in CONFIG_FILE. Write the results to"
73 <<
" OUTPUT_FILE.\n\n"
74 <<
" -o OUTPUT_FILE Required: path to the output file\n"
75 <<
" -f, --force Overwrite the output file without prompting\n\n"
77 <<
" -h, --help Print this help message\n";
80 void print_decay_help() {
81 std::cout <<
"Usage: marley decay CONFIG_FILE\n\n"
82 <<
"Simulate stand-alone nuclear de-excitations according to the\n"
83 <<
"settings in CONFIG_FILE.\n\n"
85 <<
" -h, --help Print this help message\n";
88 void print_summarize_help() {
89 std::cout <<
"Usage: marley summarize -o OUTPUT_FILE INPUT_FILE...\n\n"
90 <<
"Convert one or more MARLEY event files into a"
91 <<
" summary file containing\n"
92 <<
"a flat TTree suitable for analysis with ROOT.\n\n"
93 <<
" -o OUTPUT_FILE Required: path to the output ROOT file\n"
94 <<
" -f, --force Overwrite the output file without prompting\n\n"
96 <<
" -h, --help Print this help message\n\n"
97 <<
"Note: this command requires a ROOT-enabled build of MARLEY.\n";
100 void print_help_command_help() {
101 std::cout <<
"Usage: marley help [COMMAND]\n\n"
102 <<
"Show the top-level help message or detailed help for COMMAND.\n\n"
104 <<
" -h, --help Print this help message\n";
107 void print_version_command_help() {
108 std::cout <<
"Usage: marley version\n\n"
109 <<
"Print version information.\n";
112 void print_convert_help() {
113 std::cout <<
"Usage: marley convert [--output-format FORMAT]"
114 <<
" -o OUTPUT_FILE INPUT_FILES...\n\n"
115 <<
"Convert MARLEY event files between supported formats.\n\n"
116 <<
" -o OUTPUT_FILE Required: path to the output file\n"
117 <<
" --output-format FORMAT Output format. Supported values:\n"
118 <<
" \"ascii\" (default), \"root\",\n"
119 <<
" \"legacy\", \"hepevt\"\n"
120 <<
" -f, --force Overwrite the output file without"
123 <<
" -h, --help Print this help message\n\n"
124 <<
"Note: ROOT format conversions require a ROOT-enabled build"
126 <<
"The \"legacy\" and \"hepevt\" formats are one-way conversions"
128 <<
"current HepMC3-based format to the deprecated output formats"
130 <<
"MARLEY v1.2.1 and earlier.\n";
135const marley::CommandHandler::CommandMap
138 {
"generate", {
"Generate Monte Carlo events",
139 print_generate_help, cmd_generate } },
141 {
"print", {
"Print existing events in a human-readable format",
142 print_print_help, cmd_print } },
144 {
"reweight", {
"Reweight previously generated events",
145 print_reweight_help, cmd_reweight } },
147 {
"xsec", {
"Tabulate total cross section vs. projectile kinetic energy",
148 print_xsec_help, cmd_xsec } },
150 {
"decay", {
"Simulate nuclear de-excitations",
151 print_decay_help, cmd_decay } },
153 {
"summarize", {
"Create a ROOT TTree summary of event files",
154 print_summarize_help, cmd_summarize,
true } },
158 {
"convert", {
"Convert event files between supported formats",
159 print_convert_help, cmd_convert,
false } },
161 {
"help", {
"Show this help message or help for a specific command",
162 print_help_command_help, cmd_help } },
164 {
"version", {
"Print version information",
165 print_version_command_help, print_version } },
169 std::cout <<
"Usage: marley <command> [options]\n\n"
173 std::cout <<
" " << std::left << std::setw(12) << name
175 if ( info.requires_root_ ) std::cout <<
" [requires ROOT]";
179 std::cout <<
"\nOptions:\n"
180 <<
" -h, --help Show top-level help\n"
181 <<
" -v, --version Print version information\n";
182 std::cout <<
"\nRun 'marley help <command>' or 'marley <command> --help' for"
184 <<
"MARLEY home page: <https://www.marleygen.org>\n";
192 if (
cmds_.empty() ) {
198 std::string subcmd =
cmds_.front();
202 if ( subcmd ==
"--version" || subcmd ==
"-v" ) {
205 else if ( subcmd ==
"--help" || subcmd ==
"-h" ) {
217 return cmd_iter->second.cmd_(
cmds_ );
218 }
catch (
const std::exception& e ) {
220 MARLEY_LOG( ERROR,
"app" ) << std::flush << e.what();
227 if ( subcmd ==
"marley" ) {
228 std::cout << marley_utils::marley_pic;
235 if ( !subcmd.empty() && subcmd[0] !=
'-' ) {
239 std::cerr <<
"marley: unknown option '" << subcmd <<
"'\n";
240 std::cerr <<
"Run 'marley help' for a list of available commands.\n";
244marley::CommandHandler::CommandHandler(
int argc,
char* argv[] )
246 : cmds_( argv, argv + argc )
static bool print_top_level_help()
static const CommandMap command_map_
std::deque< std::string > cmds_
static bool cmd_generate(std::deque< std::string > &args)
Generate Monte Carlo events.