File indexing completed on 2025-12-16 09:20:31
0001
0002 #include "CommonOptions.h"
0003
0004 #include <Acts/Utilities/Helpers.hpp>
0005 #include <ActsExamples/Utilities/Options.hpp>
0006
0007 #include <exception>
0008 #include <fstream>
0009 #include <regex>
0010 #include <system_error>
0011
0012 using namespace boost::program_options;
0013
0014 boost::program_options::options_description
0015 ActsExamples::Options::makeDefaultOptions(const std::string& caption) {
0016
0017 options_description opt(caption);
0018
0019 opt.add_options()("help,h", "Produce help message");
0020 opt.add_options()(
0021 "loglevel,l", value<size_t>()->default_value(2),
0022 "The output log level. Please set the wished number (0 = VERBOSE, 1 = "
0023 "DEBUG, 2 = INFO, 3 = WARNING, 4 = ERROR, 5 = FATAL).");
0024 opt.add_options()(
0025 "response-file", value<std::string>()->default_value(""),
0026 "Configuration file (response file) replacing command line options.");
0027
0028 return opt;
0029 }
0030
0031
0032 void ActsExamples::Options::addGeometryOptions(
0033 boost::program_options::options_description& opt) {
0034 opt.add_options()("geo-surface-loglevel", value<size_t>()->default_value(3),
0035 "The outoput log level for the surface building.")(
0036 "geo-layer-loglevel", value<size_t>()->default_value(3),
0037 "The output log level for the layer building.")(
0038 "geo-volume-loglevel", value<size_t>()->default_value(3),
0039 "The output log level "
0040 "for the volume "
0041 "building.");
0042 }
0043
0044 void ActsExamples::Options::addMaterialOptions(
0045 boost::program_options::options_description& opt) {
0046 opt.add_options()(
0047 "mat-input-type", value<std::string>()->default_value("build"),
0048 "The way material is loaded: 'none', 'build', 'proto', 'file'.")(
0049 "mat-input-file", value<std::string>()->default_value(""),
0050 "Name of the material map input file, supported: '.json', '.cbor' or "
0051 "'.root'.")("mat-output-file", value<std::string>()->default_value(""),
0052 "Name of the material map output file (without extension).")(
0053 "mat-output-sensitives", value<bool>()->default_value(true),
0054 "Write material information of sensitive surfaces.")(
0055 "mat-output-approaches", value<bool>()->default_value(true),
0056 "Write material information of approach surfaces.")(
0057 "mat-output-representing", value<bool>()->default_value(true),
0058 "Write material information of representing surfaces.")(
0059 "mat-output-boundaries", value<bool>()->default_value(true),
0060 "Write material information of boundary surfaces.")(
0061 "mat-output-volumes", value<bool>()->default_value(true),
0062 "Write material information of volumes.")(
0063 "mat-output-dense-volumes", value<bool>()->default_value(false),
0064 "Write material information of dense volumes.")(
0065 "mat-output-allmaterial", value<bool>()->default_value(false),
0066 "Add protoMaterial to all surfaces and volume for the mapping.");
0067 }
0068
0069
0070 boost::program_options::variables_map ActsExamples::Options::parse(
0071 const boost::program_options::options_description& opt, int argc,
0072 char* argv[]) noexcept(false) {
0073 variables_map vm;
0074 store(command_line_parser(argc, argv).options(opt).run(), vm);
0075 notify(vm);
0076
0077 if (vm.count("response-file") != 0u &&
0078 ! vm["response-file"].template as<std::string>().empty()) {
0079
0080 std::ifstream ifs(vm["response-file"].as<std::string>().c_str());
0081 if (!ifs) {
0082 throw(std::system_error(std::error_code(),
0083 "Could not open response file."));
0084 }
0085
0086 std::stringstream ss;
0087 ss << ifs.rdbuf();
0088 std::string rString = ss.str();
0089 std::vector<std::string> args;
0090 const std::regex rgx("[ \t\r\n\f]");
0091 std::sregex_token_iterator iter(rString.begin(), rString.end(), rgx, -1);
0092 std::sregex_token_iterator end;
0093 for (; iter != end; ++iter) {
0094 if (std::string(*iter).empty()) {
0095 continue;
0096 }
0097 args.push_back(*iter);
0098 }
0099
0100 store(command_line_parser(args).options(opt).run(), vm);
0101 }
0102
0103
0104 if (vm.count("help") != 0u) {
0105 std::cout << opt << std::endl;
0106 vm.clear();
0107 }
0108 return vm;
0109 }