Skip to content

Commit

Permalink
cli: add option to set output file, type converter for log level (#64)
Browse files Browse the repository at this point in the history
* cli: add option to set output file

* cli: add lexical_cast for RMGLog::LogLevel

* Update cli docs

* docs: do not show CLI-related stuff in API docs

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ManuelHu and pre-commit-ci[bot] authored Apr 3, 2024
1 parent 6672c99 commit 9b9aec8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
5 changes: 5 additions & 0 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ XML_PROGRAMLISTING = NO
WARN_IF_UNDOCUMENTED = NO
HAVE_DOT = YES
DOT_PATH = $(DOXYGEN_DOT_PATH)

# Exclude symbols commonly used by libraries.
EXCLUDE_SYMBOLS = "CLI::*" "CLI" "FMT_*" "_g4rand" "bxdecay0_g4"
# Exclude CLI utility.
EXCLUDE = "@DOXYGEN_INPUT_DIR@/src/remage.cc"
13 changes: 8 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,22 @@ through the ``remage`` executable:
$ remage --help
remage: simulation framework for germanium experiments
Usage: src/remage [OPTIONS] [macros...]
Usage: ./src/remage [OPTIONS] [macros...]
Positionals:
macros TEXT ... Macro files
macros FILE ... Macro files
Options:
-h,--help Print this help message and exit
-q Print only warnings and errors
-v [0] Verbosity
-l,--log-level ENUM Logging level
-v [0] Increase verbosity
-l,--log-level LEVEL [summary]
Logging level debug|detail|summary|warning|error|fatal|nothing
-i,--interactive Run in interactive mode
-t,--threads INT Number of threads
-g,--gdml-files TEXT ... GDML files
-g,--gdml-files FILE ... GDML files
-o,--output-file FILE Output file for detector hits
Advanced applications can extend |remage| and link against ``libremage`` with the
usual CMake syntax:
Expand Down
41 changes: 35 additions & 6 deletions src/remage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@
#include <string>
#include <vector>

#include "CLI11/CLI11.hpp"

#include "RMGHardware.hh"
#include "RMGLog.hh"
#include "RMGManager.hh"

#ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY
#endif
#include "fmt/core.h"
#include "magic_enum/magic_enum.hpp"

namespace CLI {
namespace detail {
bool lexical_cast(std::string input, RMGLog::LogLevel& output) {
try {
output = static_cast<RMGLog::LogLevel>(std::stoll(input));
return true;
} catch (...) {
auto r = magic_enum::enum_cast<RMGLog::LogLevel>(input);
if (r.has_value()) output = r.value();
return r.has_value();
}
}
} // namespace detail
} // namespace CLI

#include "CLI11/CLI11.hpp"

int main(int argc, char** argv) {

CLI::App app{"remage: simulation framework for germanium experiments"};
Expand All @@ -32,16 +53,23 @@ int main(int argc, char** argv) {
bool interactive = false;
std::vector<std::string> gdmls;
std::vector<std::string> macros;
std::string output;
RMGLog::LogLevel loglevel = RMGLog::summary;

auto log_level_strings = magic_enum::enum_names<RMGLog::LogLevel>();
auto log_level_desc = fmt::format("Logging level {}", fmt::join(log_level_strings, "|"));

app.add_flag("-q", quiet, "Print only warnings and errors");
app.add_flag("-v", verbosity, "Verbosity");
app.add_option("-l,--log-level", loglevel, "Logging level");
app.add_flag("-v", verbosity, "Increase verbosity");
app.add_option("-l,--log-level", loglevel, log_level_desc.c_str())
->type_name("LEVEL")
->default_val("summary");

app.add_flag("-i,--interactive", interactive, "Run in interactive mode");
app.add_option("-t,--threads", nthreads, "Number of threads");
app.add_option("-g,--gdml-files", gdmls, "GDML files");
app.add_option("macros", macros, "Macro files");
app.add_option("-g,--gdml-files", gdmls, "GDML files")->type_name("FILE");
app.add_option("-o,--output-file", output, "Output file for detector hits")->type_name("FILE");
app.add_option("macros", macros, "Macro files")->type_name("FILE");

CLI11_PARSE(app, argc, argv);

Expand All @@ -61,6 +89,7 @@ int main(int argc, char** argv) {

for (const auto& g : gdmls) manager.GetDetectorConstruction()->IncludeGDMLFile(g);
for (const auto& m : macros) manager.IncludeMacroFile(m);
if (!output.empty()) manager.SetOutputFileName(output);

manager.Initialize();
manager.Run();
Expand Down

0 comments on commit 9b9aec8

Please sign in to comment.