383 using namespace smash;
385 const auto &log = logger<LogArea::Main>();
387 constexpr option longopts[] = {
388 {
"config", required_argument, 0,
'c'},
389 {
"decaymodes", required_argument, 0,
'd'},
390 {
"endtime", required_argument, 0,
'e'},
391 {
"force", no_argument, 0,
'f'},
392 {
"help", no_argument, 0,
'h'},
393 {
"inputfile", required_argument, 0,
'i'},
394 {
"modus", required_argument, 0,
'm'},
395 {
"particles", required_argument, 0,
'p'},
396 {
"output", required_argument, 0,
'o'},
397 {
"list-2-to-n", no_argument, 0,
'l'},
398 {
"resonance", required_argument, 0,
'r'},
399 {
"cross-sections", required_argument, 0,
's'},
400 {
"cross-sections-fs", required_argument, 0,
'S'},
401 {
"version", no_argument, 0,
'v'},
405 const std::string progname = bf::path(argv[0]).filename().native();
408 bool force_overwrite =
false;
410 std::vector<std::string> extra_config;
411 char *particles =
nullptr, *decaymodes =
nullptr, *modus =
nullptr,
412 *end_time =
nullptr, *pdg_string =
nullptr, *cs_string =
nullptr;
413 bool list2n_activated =
false;
414 bool resonance_dump_activated =
false;
415 bool cross_section_dump_activated =
false;
416 bool final_state_cross_sections =
false;
420 bool suppress_disclaimer =
false;
421 while ((opt = getopt_long(argc, argv,
"c:d:e:fhi:m:p:o:lr:s:S:v", longopts,
425 extra_config.emplace_back(optarg);
431 force_overwrite =
true;
437 usage(EXIT_SUCCESS, progname);
449 output_path = optarg;
452 list2n_activated =
true;
453 suppress_disclaimer =
true;
456 resonance_dump_activated =
true;
458 suppress_disclaimer =
true;
461 final_state_cross_sections =
true;
464 cross_section_dump_activated =
true;
466 suppress_disclaimer =
true;
471 "Branch : %s\nSystem : %s\nCompiler : %s %s\n" 472 "Build : %s\nDate : %s\n",
473 VERSION_MAJOR, GIT_BRANCH, CMAKE_SYSTEM, CMAKE_CXX_COMPILER_ID,
474 CMAKE_CXX_COMPILER_VERSION, CMAKE_BUILD_TYPE, BUILD_DATE);
475 std::exit(EXIT_SUCCESS);
477 usage(EXIT_FAILURE, progname);
483 std::cout << argv[0] <<
": invalid argument -- '" << argv[optind]
485 usage(EXIT_FAILURE, progname);
488 if (!suppress_disclaimer) {
496 input_path.filename());
498 for (
const auto &config : extra_config) {
512 auto particles_and_decays =
518 log.warn(
"Ambiguity: particles from external file ", particles,
519 " requested, but there is also particle list in the config." 520 " Using particles from ",
528 log.warn(
"Ambiguity: decaymodes from external file ", decaymodes,
529 " requested, but there is also decaymodes list in the config." 530 " Using decaymodes from",
540 if (list2n_activated) {
549 scat_finder.dump_reactions();
550 std::exit(EXIT_SUCCESS);
552 if (resonance_dump_activated) {
561 std::exit(EXIT_SUCCESS);
563 if (cross_section_dump_activated) {
564 std::string arg_string(cs_string);
565 std::vector<std::string> args =
split(arg_string,
',');
566 const unsigned int n_arg = args.size();
567 if (n_arg != 2 && n_arg != 4 && n_arg < 5) {
568 throw std::invalid_argument(
"-s usage: pdg1,pdg2[,m1,m2[,sqrts1,...]]");
570 PdgCode pdg_a(args[0]), pdg_b(args[1]);
574 for (
unsigned int i = 0; i < 4 - n_arg; i++) {
578 double ma = (args[2] ==
"") ? a.
mass() : std::stod(args[2]);
579 double mb = (args[3] ==
"") ? b.
mass() : std::stod(args[3]);
580 if (a.
is_stable() && args[2] !=
"" && std::stod(args[2]) != a.
mass()) {
582 std::cerr <<
"Warning: pole mass is used for stable particle " 583 << a.
name() <<
" instead of " << args[2] << std::endl;
585 if (b.
is_stable() && args[3] !=
"" && std::stod(args[3]) != b.
mass()) {
587 std::cerr <<
"Warning: pole mass is used for stable particle " 588 << b.
name() <<
" instead of " << args[3] << std::endl;
590 const size_t plab_size = n_arg <= 4 ? 0 : n_arg - 4;
591 std::vector<double> plab;
592 plab.reserve(plab_size);
593 for (
size_t i = 4; i < n_arg; i++) {
594 plab.push_back(std::stod(args.at(i)));
601 scat_finder.dump_cross_sections(a, b, ma, mb, final_state_cross_sections,
603 std::exit(EXIT_SUCCESS);
609 configuration[
"General"][
"End_Time"] = std::abs(std::atof(end_time));
619 const bf::path lock_path = output_path /
"smash.lock";
621 if (!lock.acquire()) {
622 throw std::runtime_error(
623 "Another instance of SMASH is already writing to the specified " 624 "output directory. If you are sure this is not the case, remove \"" +
625 lock_path.native() +
"\".");
627 log.debug(
"output path: ", output_path);
628 if (!force_overwrite && bf::exists(output_path /
"config.yaml")) {
629 throw std::runtime_error(
630 "Output directory would get overwritten. Select a different output " 631 "directory, clean up, or tell SMASH to ignore existing files.");
636 bf::ofstream(output_path /
"config.yaml")
637 <<
"# " << VERSION_MAJOR <<
'\n' 638 <<
"# Branch : " << GIT_BRANCH <<
'\n' 639 <<
"# System : " << CMAKE_SYSTEM <<
'\n' 640 <<
"# Compiler : " << CMAKE_CXX_COMPILER_ID <<
' ' 641 << CMAKE_CXX_COMPILER_VERSION <<
'\n' 642 <<
"# Build : " << CMAKE_BUILD_TYPE <<
'\n' 643 <<
"# Date : " << BUILD_DATE <<
'\n' 660 }
catch (std::exception &e) {
661 log.fatal() <<
"SMASH failed with the following error:\n" << e.what();
std::string to_string() const
Returns a YAML string of the current tree.
Configuration configuration(std::string overrides={})
Return a configuration object filled with data from src/config.yaml.
static std::unique_ptr< ExperimentBase > create(Configuration config, const bf::path &output_path)
Factory method that creates and initializes a new Experiment<Modus>.
ScatterActionsFinder actions_finder_for_dump(Configuration configuration)
Prepares ActionsFinder for cross-section and reaction dumps.
static void check_consistency()
void check_config_version_is_compatible(Configuration configuration)
Checks if the SMASH version is compatible with the version of the configuration file.
static void load_decaymodes(const std::string &input)
Loads the DecayModes map as described in the input string.
std::pair< std::string, std::string > load_particles_and_decaymodes(const char *particles_file, const char *decaymodes_file)
Loads particles and decaymodes from provided files particles_file and decaymodes_file.
void ensure_path_is_valid(const bf::path &path)
Ensures the output path is valid.
Value read(std::initializer_list< const char * > keys) const
Additional interface for SMASH to read configuration values without removing them.
std::vector< std::string > split(const std::string &s, char delim)
Split string by delimiter.
Interface to the SMASH configuration files.
bool has_value(std::initializer_list< const char * > keys) const
Returns whether there is a non-empty value behind the requested keys.
void setup_default_float_traps()
Setup the floating-point traps used throughout SMASH.
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
bf::path default_output_path()
void merge_yaml(const std::string &yaml)
Merge the configuration in yaml into the existing tree.
void create_all_loggers(Configuration config)
Called from main() right after the Configuration object is fully set up to create all logger objects ...
const std::string & name() const
#define source_location
Hackery that is required to output the location in the source code where the log statement occurs...
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Guard to create a file lock.
Particle type contains the static properties of a particle species.
void print_disclaimer()
Print the disclaimer.
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
static void create_type_list(const std::string &particles)
Initialize the global ParticleType list (list_all) from the given input data.
void set_default_loglevel(einhard::LogLevel level)
Set the default log level (what will be returned from subsequent default_loglevel calls)...
int64_t generate_63bit_seed()
Generates a seed with a truly random 63-bit value, if possible.
void dump_width_and_spectral_function() const
Prints out width and spectral function versus mass to the standard output.
std::unique_ptr< ExperimentBase > experiment(const Configuration &c=configuration())
Create an experiment.
void check_for_unused_config_values(const Configuration &configuration)
Checks if there are unused config values.
void ignore_simulation_config_values(Configuration &configuration)
Remove all config values that are only needed for simulations.