11std::string lower(std::string s) {
12 std::transform(
s.begin(),
s.end(),
s.begin(), [](
unsigned char c) { return static_cast<char>(std::tolower(c)); });
16std::vector<std::string> split_csv(
const std::string& s) {
17 std::vector<std::string> out;
18 std::stringstream ss(s);
20 while (std::getline(ss, item,
',')) {
21 if (!item.empty()) out.push_back(item);
26bool is_option(
const std::string& s) {
27 return s.rfind(
"--", 0) == 0;
34 for (
int i = first; i < argc; ++i) {
35 std::string token = argv[i];
36 if (!is_option(token)) {
41 token = token.substr(2);
45 const auto eq = token.find(
'=');
46 if (eq != std::string::npos) {
47 key = token.substr(0, eq);
48 value = token.substr(eq + 1);
51 if (i + 1 < argc && !is_option(argv[i + 1])) {
57 out.
options[key].push_back(value);
63 return options.contains(key);
66std::string
CliOptions::get(
const std::string& key,
const std::string& fallback)
const {
67 auto it = options.find(key);
68 if (it == options.end() || it->second.empty())
return fallback;
69 return it->second.back();
73 if (!has(key))
return fallback;
74 return std::stoi(get(key));
78 if (!has(key))
return fallback;
79 return std::stod(get(key));
83 if (!has(key))
return fallback;
84 const std::string v = lower(get(key,
"true"));
85 return v ==
"true" || v ==
"1" || v ==
"yes" || v ==
"on";
88std::vector<std::string>
CliOptions::list(
const std::string& key,
const std::vector<std::string>& fallback)
const {
89 auto it = options.find(key);
90 if (it == options.end() || it->second.empty())
return fallback;
92 std::vector<std::string> out;
93 for (
const auto& raw : it->second) {
94 auto parts = split_csv(raw);
95 out.insert(out.end(), parts.begin(), parts.end());
97 return out.empty() ? fallback : out;
101 std::cout <<
"\n== " << title <<
" ==\n";
105 const std::string m = lower(model);
107 if (m ==
"thdm" || m ==
"2hdm")
return Model::THDM;
108 if (m ==
"mssm" || m ==
"susy" || m ==
"nmssm")
return Model::SUSY;
110 throw std::invalid_argument(
"Unknown model: " + model);
114 const std::string o = lower(order);
118 throw std::invalid_argument(
"Unknown QCD order: " + order);
123 const std::string value = lower(contribution);
127 throw std::invalid_argument(
"Unknown contribution type: " + contribution);
137 hyp.
init(opts.get(
"lha",
"lha/si_input.flha"), cfg);
void print_section(const std::string &title)
ContributionType parse_contribution(const std::string &contribution)
HyperisoMaster init_hyperiso_from_cli(const CliOptions &opts)
Model parse_model(const std::string &model)
QCDOrder parse_qcd_order(const std::string &order)
@ IS_LHA_SPECTRUM
Input LHA file already contains a spectrum.
@ HYP_AS_SM_MARTY
If true, use Hyperiso as SM values for Wilson coefficients (up to NNLO).
High-level interface to initialize and monitor the main framework configuration.
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes Hyperiso using a LHA file and a full Config object.
Small command-line parser for the Hyperiso terminal interface.
double get_double(const std::string &key, double fallback) const
std::vector< std::string > list(const std::string &key, const std::vector< std::string > &fallback={}) const
bool has(const std::string &key) const
bool flag(const std::string &key, bool fallback=false) const
std::vector< std::string > positionals
std::map< std::string, std::vector< std::string > > options
int get_int(const std::string &key, int fallback) const
static CliOptions parse(int argc, char *argv[], int first=1)
std::string get(const std::string &key, const std::string &fallback="") const
Configuration object controlling model, input flags and optional MARTY resources.
std::map< ExternalFlag, bool > flags
External flags describing the nature of the inputs.
Model model
Current model.