15 #include <boost/filesystem/fstream.hpp> 26 #include "smash/config.h" 42 void usage(
const int rc,
const std::string &progname) {
123 std::printf(
"\nUsage: %s [option]\n\n", progname.c_str());
125 " -h, --help usage information\n" 127 " -i, --inputfile <file> path to input configuration file\n" 128 " (default: ./config.yaml)\n" 129 " -d, --decaymodes <file> override default decay modes from file\n" 130 " -p, --particles <file> override default particles from file\n" 132 " -c, --config <YAML> specify config value overrides\n" 133 " (multiple -c arguments are supported)\n" 134 " -m, --modus <modus> shortcut for -c 'General: { Modus: <modus> " 136 " -e, --endtime <time> shortcut for -c 'General: { End_Time: <time> " 140 " -o, --output <dir> output directory (default: ./data/<runid>)\n" 141 " -l, --list-2-to-n list all possible 2->n reactions (with n>1)\n" 142 " -r, --resonance <pdg> dump width(m) and m*spectral function(m^2)" 143 " for resonance pdg\n" 144 " -s, --cross-sections <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n" 145 " dump all partial cross-sections of " 146 "pdg1 + pdg2 reactions versus sqrt(s).\n" 147 " -S, --cross-sections-fs <pdg1>,<pdg2>[,mass1,mass2[,plab1,...]] \n" 148 " dump all partial final-state cross-sections " 149 "of pdg1 + pdg2 reactions versus sqrt(s). Non-deterministic if strings " 151 " Masses are optional, by default pole masses" 153 " Note the required comma and no spaces.\n" 154 " -f, --force force overwriting files in the output " 157 " -v, --version\n\n");
164 <<
"###################################################################" 173 <<
" mss'.. ...s'm. sSA##As mAhh##hsh##s. .hA##ASa sS###As " 175 <<
" :a':'. .'':as sM#' .HHm''HMS''AMs mMA' .AMs aMA. " 177 <<
" .a:s'. ..''ss 'h#H#S. mMm 'M#' .HH. 'MH. :MA 'h#H#S. " 179 <<
" .::ss'. .... 'SMm .HH. SMa hMm sM#..mHMs 'AMa " 181 <<
" .s::' #SMASHh aMS .MH: HM: #MMMmMM. #SMASHh " 184 <<
"###################################################################" 187 <<
" This is SMASH version: " << VERSION_MAJOR <<
"\n" 188 <<
" Simulating Many Accelerated Strongly-interacting Hadrons" 191 <<
" Distributed under the GNU General Public License 3.0" 192 <<
" (GPLv3 or later)." 194 <<
" See LICENSE for details." 196 <<
" For the full list of contributors see AUTHORS." 199 <<
" When using SMASH, please cite" 201 <<
" J. Weil et al., Phys.Rev. C94 (2016) no.5, 054905" 203 <<
" and in addition, if Pythia is used please cite" 205 <<
" T. Sjöstrand, S. Mrenna and P. Skands, JHEP05 (2006) 026," 207 <<
" Comput. Phys. Comm. 178 (2008) 852." 210 <<
" Webpage: https://smash-transport.github.io" 213 <<
" Report issues at https://github.com/smash-transport/smash" 215 <<
" or contact us by email at elfner@th.physik.uni-frankfurt.de" 218 <<
"###################################################################" 230 using std::runtime_error::runtime_error;
239 using std::runtime_error::runtime_error;
244 const bf::path
p = bf::absolute(
"data");
245 if (!bf::exists(p)) {
249 for (
int id = 0; id < std::numeric_limits<int>::max(); ++id) {
250 p2 = p / std::to_string(
id);
251 if (!bf::exists(p2)) {
268 if (bf::exists(path)) {
269 if (!bf::is_directory(path)) {
271 ") exists, but it is not a directory.");
274 if (!bf::create_directories(path)) {
276 "Race condition detected: The directory " + path.native() +
277 " did not exist a few cycles ago, but was created in the meantime by " 278 "a different process.");
292 const std::vector<bool> nucleon_has_interacted = {};
294 const int N_proj = 0;
310 const std::string smash_version =
"1.5";
311 const std::set<std::string> compatible_config_versions = {
"1.5"};
313 const std::string config_version = configuration.
read({
"Version"});
315 if (compatible_config_versions.find(config_version) ==
316 compatible_config_versions.end()) {
317 std::stringstream err;
318 err <<
"The version of the configuration file (" << config_version
319 <<
") is not compatible with the SMASH version (" << smash_version
320 <<
").\nThe following config versions are supported:\n";
321 for (
auto it : compatible_config_versions) {
324 err <<
"\nPlease consider updating your config or using a compatible SMASH" 326 throw std::runtime_error(err.str());
336 if (report !=
"{}") {
337 throw std::runtime_error(
338 "The following configuration values were not used:\n" + report);
349 configuration.
take({
"Version"});
350 configuration.
take({
"particles"});
351 configuration.
take({
"decaymodes"});
352 configuration.
take({
"Modi"});
353 configuration.
take({
"General"});
354 if (configuration.
has_value({
"Output"})) {
355 configuration.
take({
"Output"});
357 if (configuration.
has_value({
"Lattice"})) {
358 configuration.
take({
"Lattice"});
360 if (configuration.
has_value({
"Potentials"})) {
361 configuration.
take({
"Potentials"});
363 if (configuration.
has_value({
"Forced_Thermalization"})) {
364 configuration.
take({
"Forced_Thermalization"});
382 int main(
int argc,
char *argv[]) {
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";
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();
int main(int argc, char *argv[])
Main program Smashes Many Accelerated Strongly-Interacting Hadrons :-)
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.
Exception class that is thrown, if the requested output directory already exists and -f was not speci...
bool acquire()
Try to acquire the file lock.
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.
std::string unused_values_report() const
Returns a string listing the key/value pairs that have not been taken yet.
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.
ExperimentParameters create_experiment_parameters(Configuration config)
Gathers all general Experiment parameters.
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.
A simple scatter finder: Just loops through all particles and checks each pair for a collision...
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)...
Exception class that is thrown, if no new output path can be generated (there is a directory name for...
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.
Helper structure for Experiment.
void ignore_simulation_config_values(Configuration &configuration)
Remove all config values that are only needed for simulations.